Account next invoice, and authorisations
This commit is contained in:
43
app/Http/Controllers/User/AccountController.php
Normal file
43
app/Http/Controllers/User/AccountController.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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_date = $s->min(function($item) { return $item->invoice_next; });
|
||||
|
||||
// @todo The days in advance is an application parameter
|
||||
$io->date_orig = $io->due_date->subDays(30);
|
||||
|
||||
// Work out items to add to this invoice, plus any in the next additional days
|
||||
$days = now()->diffInDays($io->due_date)+1+7;
|
||||
foreach ($s as $so)
|
||||
{
|
||||
if ($so->isInvoiceDueSoon($days))
|
||||
foreach ($so->next_invoice_items() as $o)
|
||||
$io->items->push($o);
|
||||
}
|
||||
|
||||
return View('u.invoice',['o'=>$io]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user