diff --git a/app/Models/Product.php b/app/Models/Product.php index 7d4e3ff..5e6475b 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -173,7 +173,7 @@ class Product extends Model implements IDs */ public function getBaseCostAttribute(): float { - return $this->supplied->base_cost*Invoice::billing_change($this->type->normalizeBillingInterval(),$this->billing_interval) ?: 0; + return round($this->supplied->base_cost,2)*Invoice::billing_change($this->type->billing_interval,$this->billing_interval) ?: 0; } /** @@ -184,7 +184,7 @@ class Product extends Model implements IDs */ public function getBillingIntervalAttribute(): int { - return max($this->price_recur_default,$this->type->normalizeBillingInterval()); + return max($this->price_recur_default,$this->type->billing_interval); } /** @@ -239,7 +239,18 @@ class Product extends Model implements IDs */ public function getMinChargeAttribute(int $timeperiod=NULL,Group $go=NULL): float { - return $this->getSetupChargeAttribute($timeperiod,$go)+$this->getBaseChargeAttribute($timeperiod,$go)*Invoice::billing_term($this->type->contract_term,$this->getBillingIntervalAttribute()); + return $this->getSetupChargeAttribute($timeperiod,$go) + + $this->getBaseChargeAttribute($timeperiod,$go)*Invoice::billing_change($this->billing_interval,$this->type->billing_interval)*$this->type->contract_term; + } + + /** + * Get the minimum cost for this product + * + * @return float + */ + public function getMinCostAttribute(): float + { + return $this->supplied->min_cost; } /** @@ -340,7 +351,7 @@ class Product extends Model implements IDs $go = $default; if (is_null($timeperiod)) - $timeperiod = $this->getBillingIntervalAttribute(); + $timeperiod = $this->billing_interval; // If the price doesnt exist for $go->id, use $go->id = 0 which is all users. if (! $price=$this->charge($timeperiod,$go,$type)) { diff --git a/app/Models/Product/Type.php b/app/Models/Product/Type.php index 67aa300..ee13908 100644 --- a/app/Models/Product/Type.php +++ b/app/Models/Product/Type.php @@ -6,11 +6,11 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Arr; use App\Models\Product; -use App\Traits\{OrderServiceOptions,SiteID}; +use App\Traits\{OrderServiceOptions,ProductDetails,SiteID}; abstract class Type extends Model { - use SiteID,OrderServiceOptions; + use SiteID,ProductDetails,OrderServiceOptions; /* RELATIONS */ @@ -36,6 +36,16 @@ abstract class Type extends Model /* ATTRIBUTES */ + /** + * The Billing interval that the supplier normally uses for this offering + * + * @return int + */ + public function getBillingIntervalAttribute(): int + { + return static::DefaultBill; + } + /** * The product contract term is the highest of our defined contract_term (in Products/*) vs the suppliers * contract term (defined in Supplier/*). @@ -46,11 +56,4 @@ abstract class Type extends Model { return max(Arr::get($this->attributes,'contract_term',0),$this->supplied->contract_term); } - - /* METHODs */ - - final public function normalizeBillingInterval(): int - { - return static::DefaultBill; - } } \ No newline at end of file diff --git a/app/Models/Service.php b/app/Models/Service.php index 25370ee..e090ea0 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -53,6 +53,7 @@ use App\Traits\SiteID; * * @package App\Models * @todo "Billing Start Date" = "connection date" for sub types?? + * @todo Add min_charge */ class Service extends Model implements IDs { @@ -577,13 +578,13 @@ class Service extends Model implements IDs /** * This function will determine the minimum contract term for a service, which is the maximum of - * supplier->type->contract_term, or the product->type->contract_term; + * supplied->contract_term, or the product->type->contract_term; * * @return int */ public function getContractTermAttribute(): int { - return $this->getSuppliedAttribute()->contract_term; + return max($this->supplied->contract_term,$this->product->type->contract_term); } /** @@ -1077,7 +1078,7 @@ class Service extends Model implements IDs */ public function charge_normalized(): float { - return number_format($this->getBillingChargeAttribute()*Invoice::billing_change($this->recur_schedule,$this->offering->normalizeBillingInterval()),2); + return number_format($this->getBillingChargeAttribute()*Invoice::billing_change($this->recur_schedule,$this->offering->billing_interval),2); } private function getOrderInfoValue(string $key): ?string diff --git a/app/Models/Supplier/Type.php b/app/Models/Supplier/Type.php index 4c938a3..108b4e7 100644 --- a/app/Models/Supplier/Type.php +++ b/app/Models/Supplier/Type.php @@ -7,11 +7,11 @@ use Illuminate\Support\Arr; use Leenooks\Traits\ScopeActive; use App\Models\{Invoice,SupplierDetail}; -use App\Traits\{ProductDetails,SiteID}; +use App\Traits\SiteID; abstract class Type extends Model { - use SiteID,ScopeActive,ProductDetails; + use SiteID,ScopeActive; /* RELATIONS */ @@ -58,21 +58,14 @@ abstract class Type extends Model return static::category_name; } - /** - * This contract term is the highest of - * + The defined contract_term - * + The default months in a billing interval - * - * @return int - */ - public function getContractTermAttribute(): int + final public function getContractTermAttribute(?int $val): int { - return max(Invoice::billing_period(static::getBillingIntervalAttribute()),Arr::get($this->attributes,'contract_term',0)); + return $val ?: 1; } public function getMinCostAttribute(): float { - return $this->attributes['setup_cost']+$this->attributes['base_cost']*Invoice::billing_term($this->getContractTermAttribute(),$this->getBillingIntervalAttribute()); + return $this->setup_cost+$this->base_cost*$this->contract_term; } public function getNameAttribute(): string 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 c406a44..75c34ad 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() }} @@ -146,26 +146,13 @@
-
+
-
-
-

Current Plan

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

Plan Information

-
-
- -
-
-
-

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 db17bf3..dac7134 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',['o'=>$o,'p'=>$o->product]) + @include('service.widget.internal',['o'=>$o,'p'=>new \App\Models\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 facebea..68af4bb 100644 --- a/resources/views/theme/backend/adminlte/service/widget/internal.blade.php +++ b/resources/views/theme/backend/adminlte/service/widget/internal.blade.php @@ -1,13 +1,24 @@ +@php($c=$o->product) - @if (($s=$o->supplied) && $s->exists) - + + + @if($p->exists) + + @endif - - @if ($s->exists) + + + + + + + @if($p->exists) + + @endif @@ -16,75 +27,91 @@ - @if ($s->exists) - - @endif - - @if ($s->exists) - + + @if ($p->exists) + + @endif + + - @if ($s->exists) - - + + - @else - + @if ($p->exists) + + + @endif - {{-- + - @if ($s->exists) - - @endif - @if ($s->exists) + + + @if ($p->exists) + + @endif + - @if ($s->exists) - - @endif - - @if ($s->exists) + + + + @if ($p->exists) + + @endif + - @if ($s->exists) - - @endif - - @if ($s->exists) + + + + @if ($p->exists) + + @endif + - @if ($s->exists) - - @endif - - @if ($s->exists) + + + + @if ($p->exists) + + @endif + - @if ($s->exists) - - + + + - @else - + @if ($p->exists) + + + @endif - --}}
 {{ $s->supplier->name }}This Plan Proposed Plan Us
 ClientSupplier ClientSupplier  
Product#{{ $s->id }}: {{ $s->name }}#{{ $p->id }}: {{ $p->name }}{{ $p->category_name }}#{{ $c->supplied->id }}: {{ $c->supplied->name_long }} #{{ $p->supplied->id }}: {{ $p->supplied->name_long }}{{ $c->category_name }}
Setup${{ number_format($a=$o->account->taxed($s->setup_cost),2) }}${{ number_format($b=$o->account->taxed($p->setup_charge),2) }}${{ number_format($b=$o->account->taxed($c->setup_charge),2) }}${{ number_format($a=$o->account->taxed($c->setup_cost),2) }} {!! markup($a,$b) !!}-${{ number_format($b=$o->account->taxed($p->setup_charge),2) }}${{ number_format($a=$o->account->taxed($p->setup_cost),2) }}{!! markup($a,$b) !!}
Billed{{ $s->billing_interval_string }}{{ $o->billing_interval_string }}{{ $c->type->billing_interval_string }} {{ $o->billing_interval_string }}{{ $p->type->billing_interval_string }}  
Billing Price${{ number_format($a=$o->account->taxed($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,$p->billing_interval)),2) }}${{ number_format($b=$o->billing_charge,2) }}isChargeOverriden())class="text-danger"@endif>${{ number_format($b=$o->billing_charge,2) }}${{ number_format($a=$o->account->taxed($c->base_cost),2) }}{!! markup($a,$b) !!}isChargeOverriden())class="text-danger"@endif>${{ number_format($b=$o->account->taxed($p->base_charge),2) }}${{ number_format($a=$o->account->taxed($p->base_cost),2) }} {!! markup($a,$b) !!}
Monthly Price${{ number_format($a=$o->account->taxed($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,1)),2) }}isChargeOverriden()) class="text-danger" @endif>${{ number_format($b=($x ? $o->account->taxed($p->base_charge) : $o->billing_monthly_price),2) }}isChargeOverriden()) class="text-danger" @endif> + @if($x) + ${{ number_format($b=$o->billing_monthly_price,2) }} + @else + {{ number_format($b=$o->account->taxed($c->base_charge)*\App\Models\Invoice::billing_change($o->billing_interval,\App\Models\Invoice::BILL_MONTHLY),2) }} + @endif + ${{ number_format($a=$o->account->taxed($c->base_cost)*\App\Models\Invoice::billing_change($o->billing_interval,\App\Models\Invoice::BILL_MONTHLY),2) }}{!! markup($a,$b) !!}isChargeOverriden()) class="text-danger" @endif>${{ number_format($b=$o->account->taxed($p->base_charge)*\App\Models\Invoice::billing_change($o->billing_interval,\App\Models\Invoice::BILL_MONTHLY),2) }}${{ number_format($a=$o->account->taxed($p->base_cost)*\App\Models\Invoice::billing_change($o->billing_interval,\App\Models\Invoice::BILL_MONTHLY),2) }} {!! markup($a,$b) !!}
Contract{{ $s->contract_term }} months{{ $p->contract_term }} months{{ $o->contract_term }} months{{ $c->supplied->contract_term }} months {{ $p->contract_term }} months{{ $p->supplied->contract_term }} months  
Min Price${{ number_format($a=$o->account->taxed($s->min_cost),2) }}${{ number_format($b=$o->account->taxed($p->getMinChargeAttribute($o->billing_interval)),2) }}${{ number_format($b=$o->account->taxed($o->product->min_charge),2) }}${{ number_format($a=$o->account->taxed($c->supplied->min_cost),2) }} {!! markup($a,$b) !!}-${{ number_format($a=$o->account->taxed($p->min_charge),2) }}${{ number_format($a=$o->account->taxed($p->supplied->min_cost ?? 0),2) }}{!! markup($a,$b) !!}
\ No newline at end of file