135 lines
3.8 KiB
PHP
135 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class BuildingFunctionParameter extends Model
|
|
{
|
|
protected $fillable = [
|
|
'building_function_id',
|
|
'fungsi_bangunan',
|
|
'ip_permanen',
|
|
'ip_kompleksitas',
|
|
'indeks_lokalitas',
|
|
'asumsi_prasarana',
|
|
'koefisien_dasar',
|
|
'faktor_penyesuaian',
|
|
'custom_parameters',
|
|
'parameter_notes'
|
|
];
|
|
|
|
protected $casts = [
|
|
'fungsi_bangunan' => 'decimal:6',
|
|
'ip_permanen' => 'decimal:6',
|
|
'ip_kompleksitas' => 'decimal:6',
|
|
'indeks_lokalitas' => 'decimal:6',
|
|
'asumsi_prasarana' => 'decimal:6',
|
|
'koefisien_dasar' => 'decimal:6',
|
|
'faktor_penyesuaian' => 'decimal:6',
|
|
'custom_parameters' => 'array'
|
|
];
|
|
|
|
/**
|
|
* Building function relationship (1:1)
|
|
*/
|
|
public function buildingFunction(): BelongsTo
|
|
{
|
|
return $this->belongsTo(BuildingFunction::class);
|
|
}
|
|
|
|
/**
|
|
* Scope: Active parameters only
|
|
*/
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->where('is_active', true);
|
|
}
|
|
|
|
/**
|
|
* Get all parameter values as array
|
|
*/
|
|
public function getParametersArray(): array
|
|
{
|
|
return [
|
|
'fungsi_bangunan' => $this->fungsi_bangunan,
|
|
'ip_permanen' => $this->ip_permanen,
|
|
'ip_kompleksitas' => $this->ip_kompleksitas,
|
|
'indeks_lokalitas' => $this->indeks_lokalitas,
|
|
'asumsi_prasarana' => $this->asumsi_prasarana,
|
|
'koefisien_dasar' => $this->koefisien_dasar,
|
|
'faktor_penyesuaian' => $this->faktor_penyesuaian,
|
|
'custom_parameters' => $this->custom_parameters
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get formatted parameters for display
|
|
*/
|
|
public function getFormattedParameters(): array
|
|
{
|
|
return [
|
|
'Fungsi Bangunan' => $this->fungsi_bangunan,
|
|
'IP Permanen' => $this->ip_permanen,
|
|
'IP Kompleksitas' => $this->ip_kompleksitas,
|
|
'Indeks Lokalitas' => $this->indeks_lokalitas,
|
|
'Asumsi Prasarana' => $this->asumsi_prasarana,
|
|
'Koefisien Dasar' => $this->koefisien_dasar,
|
|
'Faktor Penyesuaian' => $this->faktor_penyesuaian
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Calculate floor result using the main formula
|
|
*/
|
|
public function calculateFloorResult(float $ipKetinggian): float
|
|
{
|
|
return $this->fungsi_bangunan * (
|
|
$this->ip_permanen +
|
|
$this->ip_kompleksitas +
|
|
(0.5 * $ipKetinggian)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Calculate full retribution for given building area and floor result
|
|
*/
|
|
public function calculateRetribution(float $luasBangunan, float $floorResult): float
|
|
{
|
|
$baseValue = 70350; // Base retribution value
|
|
$mainCalculation = 1 * $luasBangunan * ($this->indeks_lokalitas * $baseValue * $floorResult * 1);
|
|
$additionalCalculation = 0.5 * $mainCalculation;
|
|
|
|
return $mainCalculation + $additionalCalculation;
|
|
}
|
|
|
|
/**
|
|
* Apply custom parameters if available
|
|
*/
|
|
public function getParameterValue(string $key, $default = null)
|
|
{
|
|
// First check if it's a standard parameter
|
|
if (property_exists($this, $key) && $this->$key !== null) {
|
|
return $this->$key;
|
|
}
|
|
|
|
// Then check custom parameters
|
|
if ($this->custom_parameters && is_array($this->custom_parameters)) {
|
|
return $this->custom_parameters[$key] ?? $default;
|
|
}
|
|
|
|
return $default;
|
|
}
|
|
|
|
/**
|
|
* Set custom parameter
|
|
*/
|
|
public function setCustomParameter(string $key, $value): void
|
|
{
|
|
$customParams = $this->custom_parameters ?? [];
|
|
$customParams[$key] = $value;
|
|
$this->custom_parameters = $customParams;
|
|
}
|
|
}
|