Compare commits

...

4 Commits

Author SHA1 Message Date
078dc6ab39 Update framework
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 37s
Create Docker Image / Final Docker Image Manifest (push) Successful in 8s
2024-08-01 10:03:34 +10:00
7e383511ab Update phone service update form to use form components 2024-08-01 10:03:34 +10:00
725b6f317d Provide a link to the account in reseller account list 2024-08-01 10:03:34 +10:00
f43748e20a Add account next invoice 2024-08-01 10:03:34 +10:00
12 changed files with 136 additions and 165 deletions

View File

@ -37,7 +37,8 @@ class ChargeController extends Controller
public function delete(Charge $o): array
{
if (Gate::allows('delete',$o)) {
$o->delete();
$o->active = FALSE;
$o->save();
return ['ok'];

View File

@ -2,6 +2,7 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@ -252,11 +253,59 @@ class Account extends Model implements IDs
/* METHODS */
public function invoice_next(): Collection
{
// Collect all the invoice items for our active services
$nextdate = ($x=$this
->services_active
->filter(fn($item)=>$item->isBilled() && $item->invoice_next)
->sortBy(fn($item)=>(string)$item->invoice_next))
->first()
?->invoice_next
->clone();
// Add any additional items that will be invoiced 30 days
$nextitemsdate = max($nextdate,Carbon::now())
->clone()
->addMonth()
->subDay()
->endOfday();
$items = $x
->filter(fn($item)=>$item->invoice_next->lessThan($nextitemsdate))
->sortBy(fn($item)=>$item->invoice_next.$item->name)
->map(fn($item)=>$item->next_invoice_items($nextitemsdate))
->flatten();
// Add any account charges (charges with no active service)
foreach ($this->charges->filter(function($item) { return $item->unprocessed && ((! $this->service_id) || (! $item->service->isBilled())); }) as $oo) {
$ii = new InvoiceItem;
$ii->active = TRUE;
$ii->service_id = $oo->service_id;
$ii->product_id = $this->product_id;
$ii->quantity = $oo->quantity;
$ii->item_type = $oo->type;
$ii->price_base = $oo->amount;
$ii->start_at = $oo->start_at;
$ii->stop_at = $oo->stop_at;
$ii->module_id = 30; // @todo This shouldnt be hard coded
$ii->module_ref = $oo->id;
$ii->site_id = 1; // @todo
$ii->addTaxes($this->country->taxes);
$items->push($ii);
}
return $items;
}
/**
* List of invoices (summary) for this account
*
* @param Collection|NULL $invoices
* @return Collection
* @param bool $all
* @return Builder
*/
public function invoiceSummary(Collection $invoices=NULL,bool $all=FALSE): Builder
{

View File

@ -2,6 +2,7 @@
namespace App\Models;
use Carbon\Carbon;
use Exception;
use Illuminate\Database\Eloquent\Casts\AsCollection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@ -11,7 +12,6 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Leenooks\Carbon;
use Leenooks\Casts\LeenooksCarbon;
use App\Models\Product\Type;
@ -33,8 +33,6 @@ use App\Traits\{ScopeServiceActive,ScopeServiceUserAuthorised};
* + billing_interval : The period that this service is billed for by default
* + billing_interval_string : The period that this service is billed for by default as a name
* + invoiced_to : When this service has been billed 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)
* + 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
@ -615,10 +613,13 @@ class Service extends Model implements IDs
*
* @return Carbon
*/
public function getInvoiceNextAttribute(): Carbon
public function getInvoiceNextAttribute(): ?Carbon
{
$last = $this->getInvoicedToAttribute();
if ($this->stop_at && $last->greaterThan($this->stop_at))
return NULL;
return $last
? $last->addDay()
: (min($this->start_at,$this->invoice_next_at) ?: Carbon::now());
@ -1074,9 +1075,9 @@ class Service extends Model implements IDs
if (is_null($billdate))
$billdate = $invoiced_to->clone()->addDays(config('osb.invoice_days'));
while ($invoiced_to < ($this->stop_at ?: $billdate)) {
while ($invoiced_to <= ($this->stop_at ?: $billdate)) {
$ii = new InvoiceItem;
$period = Invoice::invoice_period($invoiced_to,$this->getBillingIntervalAttribute(),$this->product->price_recur_strict);
$period = Invoice::invoice_period($invoiced_to,$this->getBillingIntervalAttribute(),(bool)$this->product->price_recur_strict);
$ii->active = TRUE;
$ii->service_id = $this->id;

View File

@ -5,8 +5,6 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Collection as DatabaseCollection;
use Illuminate\Support\Facades\Log;
use Laravel\Passport\HasApiTokens;
use Leenooks\Traits\ScopeActive;
@ -272,41 +270,6 @@ class User extends Authenticatable implements IDs
return in_array($this->role(),['wholesaler']);
}
/**
* Get all the items for the next invoice
*
* @param bool $future
* @return DatabaseCollection
* @deprecated This should be done in accounts
*/
public function next_invoice_items(bool $future=FALSE): Collection
{
return collect();
$result = new DatabaseCollection;
$this->services->load(['invoice_items.taxes']);
foreach ($this->services as $o) {
if ($future) {
if ($o->invoice_next->subDays(config('app.invoice_inadvance'))->isPast())
continue;
} else {
if ($o->invoice_next->subDays(config('app.invoice_inadvance'))->isFuture())
continue;
}
foreach ($o->next_invoice_items($future) as $oo)
$result->push($oo);
}
$result->load([
'product.translate',
'service.type',
]);
return $result;
}
/**
* Determine what the logged in user's role is
* + Wholesaler - aka Super User

40
composer.lock generated
View File

@ -1386,16 +1386,16 @@
},
{
"name": "jenssegers/model",
"version": "v1.5.2",
"version": "v1.5.3",
"source": {
"type": "git",
"url": "https://github.com/jenssegers/model.git",
"reference": "2f91457d2efa7f0440ed8703a0d85ba65ee31b94"
"reference": "8a81b2e6fdd49fa0372fb56c62e23de13bf0d623"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jenssegers/model/zipball/2f91457d2efa7f0440ed8703a0d85ba65ee31b94",
"reference": "2f91457d2efa7f0440ed8703a0d85ba65ee31b94",
"url": "https://api.github.com/repos/jenssegers/model/zipball/8a81b2e6fdd49fa0372fb56c62e23de13bf0d623",
"reference": "8a81b2e6fdd49fa0372fb56c62e23de13bf0d623",
"shasum": ""
},
"require": {
@ -1431,9 +1431,9 @@
],
"support": {
"issues": "https://github.com/jenssegers/model/issues",
"source": "https://github.com/jenssegers/model/tree/v1.5.2"
"source": "https://github.com/jenssegers/model/tree/v1.5.3"
},
"time": "2024-04-03T13:39:07+00:00"
"time": "2024-07-25T12:44:26+00:00"
},
{
"name": "knplabs/knp-snappy",
@ -1534,16 +1534,16 @@
},
{
"name": "laravel/framework",
"version": "v11.18.1",
"version": "v11.19.0",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
"reference": "b19ba518c56852567e99fbae9321bc436c2cc5a8"
"reference": "5e103d499e9ee5bcfc184412d034c4e516b87085"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/b19ba518c56852567e99fbae9321bc436c2cc5a8",
"reference": "b19ba518c56852567e99fbae9321bc436c2cc5a8",
"url": "https://api.github.com/repos/laravel/framework/zipball/5e103d499e9ee5bcfc184412d034c4e516b87085",
"reference": "5e103d499e9ee5bcfc184412d034c4e516b87085",
"shasum": ""
},
"require": {
@ -1736,7 +1736,7 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"time": "2024-07-26T10:39:29+00:00"
"time": "2024-07-30T15:22:41+00:00"
},
{
"name": "laravel/intuit",
@ -3056,11 +3056,11 @@
},
{
"name": "leenooks/laravel",
"version": "11.1.7",
"version": "11.1.8",
"source": {
"type": "git",
"url": "https://gitea.dege.au/laravel/leenooks.git",
"reference": "eaece2b69d028fba0db5a5bb55b1386acf017cbc"
"reference": "8acc3a91af7e4ce622aec60934a2f942b4a19eda"
},
"type": "library",
"extra": {
@ -3093,7 +3093,7 @@
"laravel",
"leenooks"
],
"time": "2024-07-28T04:52:56+00:00"
"time": "2024-07-31T12:40:35+00:00"
},
{
"name": "leenooks/passkey",
@ -8909,16 +8909,16 @@
},
{
"name": "phpunit/phpunit",
"version": "11.2.8",
"version": "11.2.9",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "a7a29e8d3113806f18f99d670f580a30e8ffff39"
"reference": "c197bbaaca360efda351369bf1fd9cc1ca6bcbf7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a7a29e8d3113806f18f99d670f580a30e8ffff39",
"reference": "a7a29e8d3113806f18f99d670f580a30e8ffff39",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c197bbaaca360efda351369bf1fd9cc1ca6bcbf7",
"reference": "c197bbaaca360efda351369bf1fd9cc1ca6bcbf7",
"shasum": ""
},
"require": {
@ -8989,7 +8989,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/11.2.8"
"source": "https://github.com/sebastianbergmann/phpunit/tree/11.2.9"
},
"funding": [
{
@ -9005,7 +9005,7 @@
"type": "tidelift"
}
],
"time": "2024-07-18T14:56:37+00:00"
"time": "2024-07-30T11:09:23+00:00"
},
{
"name": "sebastian/cli-parser",

View File

@ -20,7 +20,7 @@
@endphp
<tr>
<td><a href="{{ url('r/switch/start',$ao->user_id) }}"><i class="fas fa-external-link-alt"></i></a></td>
<td>{{ $ao->name }}</td>
<td><a href="{{ url('u/home',$ao->user_id) }}">{{ $ao->name }}</a></td>
<td class="text-right">{{ $ao->services->where('active',TRUE)->count() }} <small>/{{ $ao->services->count() }}</small></td>
</tr>
@endforeach

View File

@ -0,0 +1,35 @@
<!-- $o=Account::class -->
@use(Carbon\Carbon)
<!-- Show next items for an invoice -->
@if(($x=$o->invoice_next())->count())
<div class="card">
<div class="card-body">
<p>The following items will be invoiced on or after <strong>{{ max($x->first()->start_at->subDays(config('osb.invoice_days')),Carbon::now())->format('Y-m-d') }}</strong></p>
<table class="table table-sm table-stripped">
<!-- Group by Service -->
@foreach ($x->groupBy('service_id') as $id => $oo)
<tr>
<td>{{ $oo->first()?->product?->category_name ?: '-' }}</td>
<td>
@if($id)
<a href="{{ url('u/service',$oo->first()->service_id) }}">{{ $oo->first()->service->name }}</a>
@else
Account Charges
@endif
</td>
<td class="text-right">${{ number_format($oo->sum('total'),2) }}</td>
</tr>
@endforeach
<tr>
<th class="text-right" colspan="2">TOTAL</th>
<th class="text-right">${{ number_format($x->sum('total'),2) }}</th>
</tr>
</table>
</div>
</div>
@else
<p>No items currently due to invoice.</p>
@endif

View File

@ -27,7 +27,7 @@
<td>{{ $so->product->category_name }}</td>
<td>{{ $so->name_short }}</td>
<td>{{ $so->product->name }}</td>
<td>{{ $so->external_billing ? '-' : $so->invoice_next->format('Y-m-d') }}</td>
<td>{{ ($so->external_billing || (! $so->invoice_next)) ? '-' : $so->invoice_next->format('Y-m-d') }}</td>
</tr>
@endforeach
</tbody>

View File

@ -30,6 +30,7 @@
<th>Service</th>
<th>Description</th>
<th class="text-right">Total</th>
<th>&nbsp;</th>
</tr>
</thead>
@ -42,7 +43,8 @@
<td>{{ $o->account->name }}</td>
<td><a href="{{ url('u/service',$o->service_id) }}">{{ $o->service->name_short }}</a></td>
<td>{{ $o->description }}</td>
<td class="text-right">{{ number_format($o->quantity*$o->amount,2) }}</td>
<td class="text-right">{{ number_format($o->total,2) }}</td>
<td><a class="charge_delete text-dark" data-id="{{ $o->id }}" href="{{ url('/r/charge/delete',$o->id) }}"><i class="fas fa-fw fa-ban"></i></a></td>
</tr>
@empty
<tr>
@ -55,18 +57,21 @@
</div>
</div>
</div>
<x-leenooks::modal.delete hide="row" trigger="charge_delete"/>
@endsection
@section('page-styles')
@css(datatables,bootstrap4)
@append
@section('page-scripts')
@js(datatables,bootstrap4)
@pa(datatables,rowgroup|conditionalpaging)
@section('page-scripts')
<script type="text/javascript">
$(document).ready(function() {
$('#unprocessed_charges').DataTable( {
order: [1,'desc'],
$('#unprocessed_charges').DataTable({
conditionalPaging: true,
order: [[3,'desc'],[1,'desc']],
rowGroup: {
dataSrc: [3],
},
});
});
</script>

View File

@ -76,7 +76,7 @@
<div class="tab-pane fade" id="tab-futureinvoice">
<div class="row">
<div class="col-12 col-xl-9">
@include('theme.backend.adminlte.invoice.widget.next',['future'=>TRUE])
@include('theme.backend.adminlte.account.widget.invoice_next',['o'=>$ao])
</div>
</div>
</div>

View File

@ -1,41 +0,0 @@
<!-- @todo These needs to be optimised, and change for $o = Account::class -->
<!-- Show next items for an invoice -->
@if(($x=$o->next_invoice_items($future))->count())
<div class="card">
<div class="card-body">
<table class="table">
<!-- Group by Account -->
@foreach ($x->groupBy('product_id') as $id => $oo)
<tr>
<th colspan="4">{{ $oo->first()->product->name }}</th>
<th class="text-right">${{ number_format($oo->sum('total'),2) }}</th>
</tr>
@foreach ($oo->groupBy('service_id') as $ooo)
<tr>
<td class="pt-0 pb-1" style="width: 12em;"><a href="{{ url('u/service',$ooo->first()->service_id) }}">{{ $ooo->first()->service->sid }}</a></td>
<td class="pt-0 pb-1" colspan="3">{{ $ooo->first()->service->name }}</td>
</tr>
@foreach ($ooo as $io)
<tr>
<td class="pt-0 pb-1">&nbsp;</td>
<td class="pt-0 pb-1">&nbsp;</td>
<td class="pt-0 pb-1">{{ $io->item_type_name }}</td>
<td class="text-right pt-0 pb-1">${{ number_format($io->total,2) }}</td>
</tr>
@endforeach
@endforeach
@endforeach
<tr>
<th class="text-right" colspan="4">TOTAL</th>
<th class="text-right">${{ number_format($x->sum('total'),2) }}</th>
</tr>
</table>
</div>
</div>
@else
<p>No items currently due to invoice.</p>
@endif

View File

@ -1,49 +1,21 @@
<!-- $o=Service\Phone::class -->
<div class="row">
<div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_text',[
'label'=>'Service Number',
'icon'=>'fas fa-phone',
'id'=>'service_number',
'old'=>'phone.service_number',
'name'=>'phone[service_number]',
'value'=>$o->service_number ?? '',
])
<x-leenooks::form.text id="service_number" name="phone[service_number]" icon="fa-phone" label="Service Number" old="phone.service_number" :value="$o->service_number"/>
</div>
<div class="col-12 col-sm-9 col-md-6 col-xl-7">
@include('adminlte::widget.form_text',[
'label'=>'Service Address',
'icon'=>'fas fa-map',
'id'=>'service_address',
'old'=>'phone.service_address',
'name'=>'phone[service_address]',
'value'=>$o->service_address ?? '',
])
<x-leenooks::form.text id="service_address" name="phone[service_address]" icon="fa-map" label="Service Address" old="phone.service_address" :value="$o->service_address"/>
</div>
</div>
<div class="row">
<div class="col-12 col-sm-9 col-md-12 col-xl-6">
@include('adminlte::widget.form_text',[
'label'=>'Service Username',
'icon'=>'fas fa-user',
'id'=>'service_username',
'old'=>'phone.service_username',
'name'=>'phone[service_username]',
'value'=>$o->service_username ?? '',
])
<x-leenooks::form.text id="service_username" name="phone[service_username]" icon="fa-user" label="Service Username" old="phone.service_username" :value="$o->service_username"/>
</div>
<div class="col-12 col-sm-9 col-md-5 col-xl-6">
@include('adminlte::widget.form_text',[
'label'=>'Service Password',
'icon'=>'fas fa-lock',
'id'=>'service_password',
'old'=>'phone.service_password',
'name'=>'phone[service_password]',
'value'=>$o->service_password ?? '',
])
<x-leenooks::form.text id="service_password" name="phone[service_password]" icon="fa-lock" label="Service Password" old="phone.service_password" :value="$o->service_password"/>
</div>
</div>
@ -52,24 +24,10 @@
<div class="row">
<div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_date',[
'label'=>'Connect Date',
'icon'=>'fas fa-calendar',
'id'=>'connect_at',
'old'=>'phone.connect_at',
'name'=>'phone[connect_at]',
'value'=>$o->connect_at ? $o->connect_at->format('Y-m-d') : '',
])
<x-leenooks::form.date id="connect_at" name="phone[connect_at]" icon="fa-calendar" label="Connect Date" old="phone.connect_at" :value="$o->connect_at?->format('Y-m-d')"/>
</div>
<div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_date',[
'label'=>'Contract End',
'icon'=>'fas fa-calendar',
'id'=>'expire_at',
'old'=>'phone.expire_at',
'name'=>'phone[expire_at]',
'value'=>$o->expire_at ? $o->expire_at->format('Y-m-d') : ($o->connect_at ? $o->connect_at->addMonths($o->contract_term)->format('Y-m-d') : ''),
])
<x-leenooks::form.date id="expire_at" name="phone[expire_at]" icon="fa-calendar" label="Contract End" old="phone.expire_at" :value="$o->expire_at?->format('Y-m-d') ?: ($o->connect_at?->addMonths($o->contract_term)->format('Y-m-d'))"/>
</div>
</div>