Rework service, removed redundant code, service invoicing improvements
This commit is contained in:
@@ -68,9 +68,11 @@ class SearchController extends Controller
|
||||
foreach (Service::Search($request->input('term'))
|
||||
->whereIN('account_id',$account_ids)
|
||||
->orderBy('id')
|
||||
->limit(20)->get() as $o)
|
||||
->limit(20)
|
||||
->with(['product'])
|
||||
->get() as $o)
|
||||
{
|
||||
$result->push(['name'=>sprintf('%s (%s) %s',$o->name,$o->lid,$o->active ? '' : '<small>INACT</small>'),'value'=>'/u/service/'.$o->id,'category'=>$o->category_name]);
|
||||
$result->push(['name'=>sprintf('%s (%s) %s',$o->name,$o->lid,$o->active ? '' : '<small>INACT</small>'),'value'=>'/u/service/'.$o->id,'category'=>$o->product->category_name]);
|
||||
}
|
||||
|
||||
// Look for an Invoice
|
||||
@@ -93,7 +95,7 @@ class SearchController extends Controller
|
||||
}
|
||||
|
||||
return $result
|
||||
->sortBy(function($item) { return $item['category'].$item['name']; })
|
||||
->sortBy(fn($item)=>$item['category'].$item['name'])
|
||||
->values();
|
||||
}
|
||||
}
|
@@ -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;
|
||||
|
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\{Account,Invoice};
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the users next invoice
|
||||
*/
|
||||
public function view_invoice_next(Account $o)
|
||||
{
|
||||
$io = new Invoice;
|
||||
$io->account = $o;
|
||||
|
||||
// Get the account services
|
||||
$s = $o->services(TRUE)
|
||||
->with(['invoice_items','charges'])
|
||||
->get()
|
||||
->filter(function($item) {
|
||||
return ! $item->suspend_billing AND ! $item->external_billing;
|
||||
});
|
||||
|
||||
// Get our invoice due date for this invoice
|
||||
$io->due_at = $s->min(function($item) { return $item->invoice_next; });
|
||||
|
||||
// @todo The days in advance is an application parameter
|
||||
$io->created_at = $io->due_at->subDays(30);
|
||||
|
||||
// Work out items to add to this invoice, plus any in the next additional days
|
||||
$days = now()->diffInDays($io->due_at)+1+7;
|
||||
foreach ($s as $so)
|
||||
{
|
||||
if ($so->isInvoiceDueSoon($days))
|
||||
foreach ($so->next_invoice_items() as $o)
|
||||
$io->items->push($o);
|
||||
}
|
||||
|
||||
return view('theme.backend.adminlte.u.invoice.home')
|
||||
->with('o',$io);
|
||||
}
|
||||
}
|
@@ -15,9 +15,4 @@ class ReportController extends Controller
|
||||
{
|
||||
return view('product/report');
|
||||
}
|
||||
|
||||
public function services()
|
||||
{
|
||||
return view('service/report');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user