More works on products

This commit is contained in:
Deon George
2022-02-01 16:40:46 +11:00
parent 1e9f15b40f
commit b9b4416737
36 changed files with 952 additions and 312 deletions

View File

@@ -8,6 +8,7 @@ use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Leenooks\Traits\ScopeActive;
use App\Interfaces\IDs;
@@ -299,7 +300,7 @@ class Product extends Model implements IDs
*/
public function hasUsage(): bool
{
return $this->type->supplied->hasUsage();
return $this->type->hasUsage();
}
/**
@@ -324,12 +325,24 @@ class Product extends Model implements IDs
$timeperiod = $this->getBillingIntervalAttribute();
// If the price doesnt exist for $go->id, use $go->id = 0 which is all users.
if (! $price=Arr::get($this->pricing,sprintf('%d.%d.%s',$timeperiod,$go->id,$type)))
$price = Arr::get($this->pricing,sprintf('%d.%d.%s',$timeperiod,0,$type));
if (! $price=Arr::get($this->pricing,sprintf('%d.%d.%s',$timeperiod,$go->id,$type))) {
$alt_tp = $timeperiod;
while (is_null($price=Arr::get($this->pricing,sprintf('%d.%d.%s',$alt_tp,0,$type))) && ($alt_tp >= 0)) {
$alt_tp--;
}
if (! is_null($price) && $alt_tp !== $timeperiod) {
$price = $price*Invoice::billing_change($alt_tp,$timeperiod);
}
}
// @todo - if price doesnt exist for the time period, reduce down to timeperiod 1 and multiply appropriately.
if (is_null($price))
abort(500,sprintf('Price is NULL, we need to find it timeperiod[%s] group[%s]',$timeperiod,$go->id));
if (is_null($price)) {
Log::error(sprintf('Price is still null for [%d] timeperiod [%d] group [%d]',$this->id,$timeperiod,$go->id));
$price = 0;
}
return round($price,2);
}