Bring back some services logic to still needed by charges

This commit is contained in:
Deon George 2022-06-13 14:21:48 +10:00
parent c1080481ec
commit 2590997b1a
5 changed files with 61 additions and 4 deletions

View File

@ -0,0 +1,19 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\Account;
class ResellerServicesController extends Controller
{
public function services(Request $request,Account $o)
{
return $o->services
->filter(function($item) use ($request) {
return $item->active || ($item->id == $request->include);
});
}
}

View File

@ -33,6 +33,7 @@ use App\Traits\SiteID;
* + billing_interval_string : The period that this service is billed for by default as a name * + billing_interval_string : The period that this service is billed for by default as a name
* + billed_to : When this service has been billed to // @todo rename all references to invoice_to * + 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 : 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_term : The term that this service must be active
* + contract_end : The date that the contract ends for this service * + contract_end : The date that the contract ends for this service
* + name : Service short name with service address * + name : Service short name with service address
@ -65,6 +66,27 @@ class Service extends Model implements IDs
'stop_at', 'stop_at',
]; ];
protected $appends = [
'category_name',
'name_short',
];
protected $visible = [
// 'account_name',
// 'admin_service_id_url',
'active',
'category_name',
// 'billing_price',
// 'data_orig',
'id',
'name_short',
// 'next_invoice',
// 'product.name',
// 'service_id',
// 'service_id_url',
// 'status',
];
protected $with = [ protected $with = [
'invoice_items', 'invoice_items',
'product.type.supplied', 'product.type.supplied',
@ -483,6 +505,16 @@ class Service extends Model implements IDs
return number_format($this->getBillingChargeAttribute()/Arr::get(Invoice::billing_periods,$this->recur_schedule.'.interval',1),2); return number_format($this->getBillingChargeAttribute()/Arr::get(Invoice::billing_periods,$this->recur_schedule.'.interval',1),2);
} }
public function getCategoryAttribute(): string
{
return $this->product->category;
}
public function getCategoryNameAttribute(): string
{
return $this->product->category_name;
}
/** /**
* The date the contract ends * The date the contract ends
* *

View File

@ -284,7 +284,7 @@
success: function(data) { success: function(data) {
$("select[name=service_id]").empty(); $("select[name=service_id]").empty();
$.each(data,function(i,j) { $.each(data,function(i,j) {
var row = '<option value="' + j.id + '" '+(j.id == {{ $o->service_id ?: 'null' }} ? 'selected' : '')+'>' + j.id + ': ' + j.product_name + ' ' + j.name_short + ((! j.active) ? ' **' : '') +'</option>'; var row = '<option value="' + j.id + '" '+(j.id == {{ $o->service_id ?: 'null' }} ? 'selected' : '')+'>' + j.id + ': ' + j.category_name + ' ' + j.name_short + ((! j.active) ? ' **' : '') +'</option>';
$(row).appendTo("select[name=service_id]"); $(row).appendTo("select[name=service_id]");
}); });

View File

@ -22,8 +22,8 @@
@foreach ($x as $co) @foreach ($x as $co)
<tr> <tr>
<td><a href="{{ url('a/charge/addedit',[$co->id]) }}">{{ $co->id }}</a></td> <td><a href="{{ url('a/charge/addedit',[$co->id]) }}">{{ $co->id }}</a></td>
<td>{{ $co->date_orig->format('Y-m-d') }}</td> <td>{{ $co->created_at->format('Y-m-d') }}</td>
<td>{{ $co->charge_date->format('Y-m-d') }}</td> <td>{{ $co->charged_at ? $co->charged_at->format('Y-m-d') : '-' }}</td>
<td>{{ $co->service->sid }}</td> <td>{{ $co->service->sid }}</td>
<td>{{ $co->type }}</td> <td>{{ $co->type }}</td>
<td>{{ $co->description }}</td> <td>{{ $co->description }}</td>

View File

@ -1,6 +1,6 @@
<?php <?php
use App\Http\Controllers\{CheckoutController,ProductController}; use App\Http\Controllers\{CheckoutController,ProductController,ResellerServicesController};
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -18,6 +18,12 @@ Route::group(['middleware'=>['auth:api','role:wholesaler']], function() {
Route::get('a/supplier_products',[ProductController::class,'api_supplier_products']); Route::get('a/supplier_products',[ProductController::class,'api_supplier_products']);
}); });
// Reseller API calls
Route::group(['middleware'=>['auth:api','role:reseller']], function() {
Route::get('/r/services/{o}',[ResellerServicesController::class,'services'])
->where('o','[0-9]+');
});
Route::group(['middleware'=>'auth:api'], function() { Route::group(['middleware'=>'auth:api'], function() {
Route::post('/u/checkout/fee/{o}',[CheckoutController::class,'fee']) Route::post('/u/checkout/fee/{o}',[CheckoutController::class,'fee'])
->where('o','[0-9]+'); ->where('o','[0-9]+');