diff --git a/app/Http/Controllers/ServiceController.php b/app/Http/Controllers/ServiceController.php index 647a73e..8bf2028 100644 --- a/app/Http/Controllers/ServiceController.php +++ b/app/Http/Controllers/ServiceController.php @@ -96,6 +96,7 @@ class ServiceController extends Controller $co->save(); $o->product_id = Arr::get($request->broadband,'product_id'); + $o->price = Arr::get($request->broadband,'price'); $o->order_status = 'ACTIVE'; $o->save(); @@ -345,7 +346,7 @@ class ServiceController extends Controller $co->type = $iio->item_type; $co->start_at = $start_at; $co->stop_at = $iio->stop_at; - $co->amount = $po->base_charge; + $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; $charges->push($co); diff --git a/app/Http/Requests/ServiceChangeRequest.php b/app/Http/Requests/ServiceChangeRequest.php index a313fb7..91a074b 100644 --- a/app/Http/Requests/ServiceChangeRequest.php +++ b/app/Http/Requests/ServiceChangeRequest.php @@ -32,6 +32,7 @@ class ServiceChangeRequest extends FormRequest return [ 'broadband.product_id' => 'required|exists:products,id', 'broadband.change_fee' => 'nullable|numeric', + 'broadband.price' => 'nullable|numeric', 'broadband.start_at' => 'required|date', // @todo Check that it is not more than 1 billing cycle ago, and not future. ]; } diff --git a/app/Models/Product.php b/app/Models/Product.php index c9aa3f4..83de383 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -184,11 +184,11 @@ class Product extends Model implements IDs /** * Return the type of service is provided. eg: Broadband, Phone. * - * @return string + * @return string|null */ - public function getCategoryAttribute(): string + public function getCategoryAttribute(): ?string { - return $this->supplied->getCategoryAttribute(); + return $this->supplied ? $this->supplied->getCategoryAttribute() : NULL; } /** diff --git a/app/Models/Service.php b/app/Models/Service.php index 8eb9f84..b0c79d6 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -35,6 +35,7 @@ use App\Traits\SiteID; * + 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_name : The type of service this is, eg: Broadband, Telephone (in human friendly) + * + isChargedOverride : Has the price been overridden? * + 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 @@ -1216,6 +1217,11 @@ class Service extends Model implements IDs AND ! in_array($this->order_status,array_merge(self::INACTIVE_STATUS,['INACTIVE'])); } + public function isChargeOverriden(): bool + { + return (! is_null($this->price)) || (! is_null($this->price_override)); + } + /** * Generate a collection of invoice_item objects that will be billed for the next invoice * diff --git a/resources/views/theme/backend/adminlte/service/change_pending.blade.php b/resources/views/theme/backend/adminlte/service/change_pending.blade.php index 9a5fab0..c406a44 100644 --- a/resources/views/theme/backend/adminlte/service/change_pending.blade.php +++ b/resources/views/theme/backend/adminlte/service/change_pending.blade.php @@ -17,7 +17,7 @@ @section('main-content')
-
+
{{ csrf_field() }} @@ -55,8 +55,8 @@ @@ -112,6 +112,24 @@
+ +
+ +
+ +
+
+ +
+ + + @error('broadband.price') + {{ $message }} + @enderror + +
+
+
@@ -126,8 +144,31 @@
+ +
- @include('service.widget.internal') +
+
+
+

Current Plan

+
+ + @include('service.widget.internal',['o'=>$o,'p'=>$o->product]) +
+
+
+ + +
+
+
+
+

Proposed Plan

+
+ + @include('service.widget.internal',['o'=>$o,'p'=>\App\Models\Product::where('id',Arr::get($o->order_info,'change_product_id'))->singleOrFail()]) +
+
diff --git a/resources/views/theme/backend/adminlte/service/home.blade.php b/resources/views/theme/backend/adminlte/service/home.blade.php index 9b565ad..db17bf3 100644 --- a/resources/views/theme/backend/adminlte/service/home.blade.php +++ b/resources/views/theme/backend/adminlte/service/home.blade.php @@ -89,7 +89,7 @@ @can('wholesaler')
- @include('service.widget.internal') + @include('service.widget.internal',['o'=>$o,'p'=>$o->product])
diff --git a/resources/views/theme/backend/adminlte/service/widget/internal.blade.php b/resources/views/theme/backend/adminlte/service/widget/internal.blade.php index c8c7102..fdd2b72 100644 --- a/resources/views/theme/backend/adminlte/service/widget/internal.blade.php +++ b/resources/views/theme/backend/adminlte/service/widget/internal.blade.php @@ -1,4 +1,4 @@ - + @@ -19,16 +19,16 @@ @if ($s->exists) @endif - + @if ($s->exists) - + @endif @if ($s->exists) - + @else @@ -47,7 +47,7 @@ @if ($s->exists) - + @endif @if ($s->exists) @@ -59,7 +59,7 @@ @if ($s->exists) @endif - + @if ($s->exists) @endif @@ -69,7 +69,7 @@ @if ($s->exists) @endif - + @if ($s->exists) @endif @@ -78,19 +78,11 @@ @if ($s->exists) - + @else @endif -
#{{ $s->id }}: {{ $s->name }}#{{ $o->product->id }}: {{ $o->product->name }}#{{ $p->id }}: {{ $p->name }}{{ $o->product->category_name }}{{ $p->category_name }}
Setup${{ number_format($a=\App\Models\Tax::tax_calc($s->setup_cost,$o->account->taxes),2) }}${{ number_format($b=\App\Models\Tax::tax_calc($o->product->setup_charge,$o->account->taxes),2) }}${{ number_format($b=\App\Models\Tax::tax_calc($p->setup_charge,$o->account->taxes),2) }} {!! markup($a,$b) !!}-
Billing Price${{ number_format($a=\App\Models\Tax::tax_calc($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,$o->product->billing_interval),$o->account->taxes),2) }}${{ number_format($a=\App\Models\Tax::tax_calc($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,$p->billing_interval),$o->account->taxes),2) }}${{ number_format($b=$o->billing_charge,2) }}${{ number_format($a=\App\Models\Tax::tax_calc($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,1),$o->account->taxes),2) }}${{ number_format($b=$o->billing_monthly_price,2) }}isChargeOverriden()) class="text-danger" @endif>${{ number_format($b=($x ? $p->base_charge_taxable : $o->billing_monthly_price),2) }}{!! markup($a,$b) !!}{{ $s->contract_term }} months{{ $o->contract_term }} months{{ $p->contract_term }} months Min Price${{ number_format($a=\App\Models\Tax::tax_calc($s->min_cost,$o->account->taxes),2) }}${{ number_format($b=\App\Models\Tax::tax_calc($o->product->getMinChargeAttribute($o->billing_interval),$o->account->taxes),2) }}${{ number_format($b=\App\Models\Tax::tax_calc($p->getMinChargeAttribute($o->billing_interval),$o->account->taxes),2) }} {!! markup($a,$b) !!}-
- -@php -function markup($a,$b) { - return ($a > $b) - ? sprintf('(%3.1f%%)',$a ? ($b-$a)/($b ?: 1)*100 : 100) - : sprintf('%3.1f%%',$a ? ($b-$a)/($b ?: 1)*100 : ($b ? 100: 0)); -} -@endphp \ No newline at end of file + \ No newline at end of file