More product cleanup
This commit is contained in:
parent
dc74a064ba
commit
691180b3f0
@ -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)) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -17,7 +17,7 @@
|
||||
<!-- $o = App\Models\Service::class -->
|
||||
@section('main-content')
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<div class="col-12 col-lg-4">
|
||||
<form role="form" method="POST" enctype="multipart/form-data">
|
||||
<div class="card card-dark">
|
||||
{{ csrf_field() }}
|
||||
@ -146,26 +146,13 @@
|
||||
</div>
|
||||
|
||||
<!-- Current Plan -->
|
||||
<div class="col-4">
|
||||
<div class="col-12 col-lg-8">
|
||||
<div class="card card-dark">
|
||||
<div class="card-body">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Current Plan</h3>
|
||||
<h3 class="card-title">Plan Information</h3>
|
||||
</div>
|
||||
|
||||
@include('service.widget.internal',['o'=>$o,'p'=>$o->product])
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Proposed Plan -->
|
||||
<div class="col-4">
|
||||
<div class="card card-dark">
|
||||
<div class="card-body">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Proposed Plan</h3>
|
||||
</div>
|
||||
|
||||
@include('service.widget.internal',['o'=>$o,'p'=>\App\Models\Product::where('id',Arr::get($o->order_info,'change_product_id'))->singleOrFail()])
|
||||
</div>
|
||||
</div>
|
||||
|
@ -89,7 +89,7 @@
|
||||
</div>
|
||||
@can('wholesaler')
|
||||
<div class="tab-pane fade" id="internal" role="tabpanel">
|
||||
@include('service.widget.internal',['o'=>$o,'p'=>$o->product])
|
||||
@include('service.widget.internal',['o'=>$o,'p'=>new \App\Models\Product()])
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade {{ session()->pull('service_update') ? 'active show' : '' }}" id="update" role="tabpanel">
|
||||
|
@ -1,13 +1,24 @@
|
||||
<!-- $o = Service::class, $p = Product::class -->
|
||||
@php($c=$o->product)
|
||||
<table class="table table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
@if (($s=$o->supplied) && $s->exists)
|
||||
<th>{{ $s->supplier->name }}</th>
|
||||
<th class="text-center" colspan="2">This Plan</th>
|
||||
<th> </th>
|
||||
@if($p->exists)
|
||||
<th class="text-center" colspan="2">Proposed Plan</th>
|
||||
<th> </th>
|
||||
@endif
|
||||
<th>Us</th>
|
||||
@if ($s->exists)
|
||||
</tr>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th>Client</th>
|
||||
<th>Supplier</th>
|
||||
<th> </th>
|
||||
@if($p->exists)
|
||||
<th>Client</th>
|
||||
<th>Supplier</th>
|
||||
<th> </th>
|
||||
@endif
|
||||
</tr>
|
||||
@ -16,75 +27,91 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Product</th>
|
||||
@if ($s->exists)
|
||||
<td>#{{ $s->id }}: {{ $s->name }}</td>
|
||||
@endif
|
||||
<td>#{{ $p->id }}: {{ $p->name }}</td>
|
||||
@if ($s->exists)
|
||||
<td>{{ $p->category_name }}</td>
|
||||
<td class="text-center" colspan="2">#{{ $c->supplied->id }}: {{ $c->supplied->name_long }}</td>
|
||||
@if ($p->exists)
|
||||
<th> </th>
|
||||
<td class="text-center" colspan="2">#{{ $p->supplied->id }}: {{ $p->supplied->name_long }}</td>
|
||||
@endif
|
||||
<td>{{ $c->category_name }}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Setup</th>
|
||||
@if ($s->exists)
|
||||
<td>${{ number_format($a=$o->account->taxed($s->setup_cost),2) }}</td>
|
||||
<td>${{ number_format($b=$o->account->taxed($p->setup_charge),2) }}</td>
|
||||
<td>${{ number_format($b=$o->account->taxed($c->setup_charge),2) }}</td>
|
||||
<td>${{ number_format($a=$o->account->taxed($c->setup_cost),2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@if ($p->exists)
|
||||
<td>${{ number_format($b=$o->account->taxed($p->setup_charge),2) }}</td>
|
||||
<td>${{ number_format($a=$o->account->taxed($p->setup_cost),2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@else
|
||||
<td>-</td>
|
||||
@endif
|
||||
</tr>
|
||||
{{--
|
||||
|
||||
<tr>
|
||||
<th>Billed</th>
|
||||
@if ($s->exists)
|
||||
<td>{{ $s->billing_interval_string }}</td>
|
||||
@endif
|
||||
<td>{{ $o->billing_interval_string }}</td>
|
||||
@if ($s->exists)
|
||||
<td>{{ $c->type->billing_interval_string }}</td>
|
||||
<td> </td>
|
||||
@if ($p->exists)
|
||||
<td>{{ $o->billing_interval_string }}</td>
|
||||
<td>{{ $p->type->billing_interval_string }}</td>
|
||||
<td> </td>
|
||||
@endif
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Billing Price</th>
|
||||
@if ($s->exists)
|
||||
<td>${{ number_format($a=$o->account->taxed($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,$p->billing_interval)),2) }}</td>
|
||||
@endif
|
||||
<td>${{ number_format($b=$o->billing_charge,2) }}</td>
|
||||
@if ($s->exists)
|
||||
<td @if($o->isChargeOverriden())class="text-danger"@endif>${{ number_format($b=$o->billing_charge,2) }}</td>
|
||||
<td>${{ number_format($a=$o->account->taxed($c->base_cost),2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@if ($p->exists)
|
||||
<td @if($o->isChargeOverriden())class="text-danger"@endif>${{ number_format($b=$o->account->taxed($p->base_charge),2) }}</td>
|
||||
<td>${{ number_format($a=$o->account->taxed($p->base_cost),2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@endif
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Monthly Price</th>
|
||||
@if ($s->exists)
|
||||
<td>${{ number_format($a=$o->account->taxed($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,1)),2) }}</td>
|
||||
<td @if($x=$o->isChargeOverriden()) class="text-danger" @endif>
|
||||
@if($x)
|
||||
<abbr title="${{ number_format($b=$o->account->taxed($c->base_charge)*\App\Models\Invoice::billing_change($o->billing_interval,\App\Models\Invoice::BILL_MONTHLY),2) }}">${{ 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
|
||||
<td @if($x=$o->isChargeOverriden()) class="text-danger" @endif>${{ number_format($b=($x ? $o->account->taxed($p->base_charge) : $o->billing_monthly_price),2) }}</td>
|
||||
@if ($s->exists)
|
||||
</td>
|
||||
<td>${{ number_format($a=$o->account->taxed($c->base_cost)*\App\Models\Invoice::billing_change($o->billing_interval,\App\Models\Invoice::BILL_MONTHLY),2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@if ($p->exists)
|
||||
<td @if($x=$o->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) }}</td>
|
||||
<td>${{ number_format($a=$o->account->taxed($p->base_cost)*\App\Models\Invoice::billing_change($o->billing_interval,\App\Models\Invoice::BILL_MONTHLY),2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@endif
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Contract</th>
|
||||
@if ($s->exists)
|
||||
<td>{{ $s->contract_term }} months</td>
|
||||
@endif
|
||||
<td>{{ $o->contract_term }} months</td>
|
||||
<td>{{ $c->supplied->contract_term }} months</td>
|
||||
<td> </td>
|
||||
@if ($p->exists)
|
||||
<td>{{ $p->contract_term }} months</td>
|
||||
@if ($s->exists)
|
||||
<td>{{ $p->supplied->contract_term }} months</td>
|
||||
<td> </td>
|
||||
@endif
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Min Price</th>
|
||||
@if ($s->exists)
|
||||
<td>${{ number_format($a=$o->account->taxed($s->min_cost),2) }}</td>
|
||||
<td>${{ number_format($b=$o->account->taxed($p->getMinChargeAttribute($o->billing_interval)),2) }}</td>
|
||||
<!-- @todo change this to $o->min_charge when implemented -->
|
||||
<td>${{ number_format($b=$o->account->taxed($o->product->min_charge),2) }}</td>
|
||||
<td>${{ number_format($a=$o->account->taxed($c->supplied->min_cost),2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@if ($p->exists)
|
||||
<td>${{ number_format($a=$o->account->taxed($p->min_charge),2) }}</td>
|
||||
<td>${{ number_format($a=$o->account->taxed($p->supplied->min_cost ?? 0),2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@else
|
||||
<td>-</td>
|
||||
@endif
|
||||
</tr>
|
||||
--}}
|
||||
</tbody>
|
||||
</table>
|
Loading…
Reference in New Issue
Block a user