add spatial plannings retribution calculations
This commit is contained in:
209
app/Console/Commands/TestExcelFormulaCommand.php
Normal file
209
app/Console/Commands/TestExcelFormulaCommand.php
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\BuildingFunction;
|
||||
use App\Models\FloorHeightIndex;
|
||||
use App\Models\RetributionProposal;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class TestExcelFormulaCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'test:excel-formula {--building-function=10} {--floor-area=100} {--floor-number=2}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Test Excel formula calculation with sample data';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('🧮 Testing Excel Formula Calculation');
|
||||
$this->newLine();
|
||||
|
||||
// Get parameters
|
||||
$buildingFunctionId = $this->option('building-function');
|
||||
$floorArea = (float) $this->option('floor-area');
|
||||
$floorNumber = (int) $this->option('floor-number');
|
||||
|
||||
// Get building function and parameters
|
||||
$buildingFunction = BuildingFunction::with('parameter')->find($buildingFunctionId);
|
||||
if (!$buildingFunction || !$buildingFunction->parameter) {
|
||||
$this->error("Building function with ID {$buildingFunctionId} not found or has no parameters.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get IP ketinggian for floor
|
||||
$floorHeightIndex = FloorHeightIndex::where('floor_number', $floorNumber)->first();
|
||||
$ipKetinggian = $floorHeightIndex ? $floorHeightIndex->ip_ketinggian : 1.0;
|
||||
|
||||
// Get parameters
|
||||
$parameters = $buildingFunction->parameter->getParametersArray();
|
||||
|
||||
$this->info("Test Parameters:");
|
||||
$this->table(
|
||||
['Parameter', 'Excel Cell', 'Value'],
|
||||
[
|
||||
['Building Function', 'Building Function', $buildingFunction->name],
|
||||
['Floor Area (D13)', 'D13', $floorArea . ' m²'],
|
||||
['Fungsi Bangunan (E13)', 'E13', $parameters['fungsi_bangunan']],
|
||||
['IP Permanen (F13)', 'F13', $parameters['ip_permanen']],
|
||||
['IP Kompleksitas (G13)', 'G13', $parameters['ip_kompleksitas']],
|
||||
['IP Ketinggian (H$3)', 'H$3', $ipKetinggian],
|
||||
['Indeks Lokalitas (N13)', 'N13', $parameters['indeks_lokalitas']],
|
||||
['Base Value', '70350', '70,350'],
|
||||
['Additional Factor ($O$3)', '$O$3', '0.5 (50%)']
|
||||
]
|
||||
);
|
||||
|
||||
$this->newLine();
|
||||
|
||||
// Calculate manually using the Excel formula
|
||||
$fungsi_bangunan = $parameters['fungsi_bangunan'];
|
||||
$ip_permanen = $parameters['ip_permanen'];
|
||||
$ip_kompleksitas = $parameters['ip_kompleksitas'];
|
||||
$indeks_lokalitas = $parameters['indeks_lokalitas'];
|
||||
$base_value = 70350;
|
||||
$additional_factor = 0.5;
|
||||
|
||||
// Step 1: Calculate H13 (floor coefficient)
|
||||
$h13 = $fungsi_bangunan * ($ip_permanen + $ip_kompleksitas + (0.5 * $ipKetinggian));
|
||||
|
||||
// Step 2: Main calculation
|
||||
$main_calculation = 1 * $floorArea * ($indeks_lokalitas * $base_value * $h13 * 1);
|
||||
|
||||
// Step 3: Additional (50%)
|
||||
$additional_calculation = $additional_factor * $main_calculation;
|
||||
|
||||
// Step 4: Total
|
||||
$total_retribution = $main_calculation + $additional_calculation;
|
||||
|
||||
// Create breakdown array
|
||||
$breakdown = [
|
||||
'calculation_steps' => [
|
||||
'step_1_h13' => [
|
||||
'formula' => 'fungsi_bangunan * (ip_permanen + ip_kompleksitas + (0.5 * ip_ketinggian))',
|
||||
'calculation' => "{$fungsi_bangunan} * ({$ip_permanen} + {$ip_kompleksitas} + (0.5 * {$ipKetinggian}))",
|
||||
'result' => $h13
|
||||
],
|
||||
'step_2_main' => [
|
||||
'formula' => '(1*D13*(N13*70350*H13*1))',
|
||||
'calculation' => "1 * {$floorArea} * ({$indeks_lokalitas} * {$base_value} * {$h13} * 1)",
|
||||
'result' => $main_calculation
|
||||
],
|
||||
'step_3_additional' => [
|
||||
'formula' => '($O$3*(1*D13*(N13*70350*H13*1)))',
|
||||
'calculation' => "{$additional_factor} * {$main_calculation}",
|
||||
'result' => $additional_calculation
|
||||
],
|
||||
'step_4_total' => [
|
||||
'formula' => 'main + additional',
|
||||
'calculation' => "{$main_calculation} + {$additional_calculation}",
|
||||
'result' => $total_retribution
|
||||
]
|
||||
],
|
||||
'formatted_results' => [
|
||||
'H13' => number_format($h13, 6),
|
||||
'main_calculation' => 'Rp ' . number_format($main_calculation, 2),
|
||||
'additional_calculation' => 'Rp ' . number_format($additional_calculation, 2),
|
||||
'total_result' => 'Rp ' . number_format($total_retribution, 2)
|
||||
]
|
||||
];
|
||||
|
||||
$this->info("📊 Calculation Breakdown:");
|
||||
$this->newLine();
|
||||
|
||||
// Show each step
|
||||
foreach ($breakdown['calculation_steps'] as $stepName => $step) {
|
||||
$this->info("🔸 " . strtoupper(str_replace('_', ' ', $stepName)));
|
||||
$this->line(" Formula: " . $step['formula']);
|
||||
$this->line(" Calculation: " . $step['calculation']);
|
||||
$this->line(" Result: " . (is_numeric($step['result']) ? number_format($step['result'], 6) : $step['result']));
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
$this->info("💰 Final Results:");
|
||||
$this->table(
|
||||
['Component', 'Value'],
|
||||
[
|
||||
['H13 (Floor Coefficient)', $breakdown['formatted_results']['H13']],
|
||||
['Main Calculation', $breakdown['formatted_results']['main_calculation']],
|
||||
['Additional (50%)', $breakdown['formatted_results']['additional_calculation']],
|
||||
['Total Retribution', $breakdown['formatted_results']['total_result']]
|
||||
]
|
||||
);
|
||||
|
||||
$this->newLine();
|
||||
$this->info("🔍 Excel Formula Verification:");
|
||||
$this->line("Main Formula: =(1*D13*(N13*70350*H13*1))+(\$O\$3*(1*D13*(N13*70350*H13*1)))");
|
||||
$this->line("H13 Formula: =(\$E13*(\$F13+\$G13+(0.5*H\$3)))");
|
||||
|
||||
// Test with different floor numbers
|
||||
if ($this->confirm('Test with different floor numbers?')) {
|
||||
$this->testMultipleFloors($buildingFunction, $floorArea, $parameters);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test calculation with multiple floor numbers
|
||||
*/
|
||||
protected function testMultipleFloors(BuildingFunction $buildingFunction, float $floorArea, array $parameters)
|
||||
{
|
||||
$this->newLine();
|
||||
$this->info("🏢 Testing Multiple Floors:");
|
||||
|
||||
$tableData = [];
|
||||
$totalRetribution = 0;
|
||||
|
||||
for ($floor = 1; $floor <= 5; $floor++) {
|
||||
$floorHeightIndex = FloorHeightIndex::where('floor_number', $floor)->first();
|
||||
$ipKetinggian = $floorHeightIndex ? $floorHeightIndex->ip_ketinggian : 1.0;
|
||||
|
||||
// Calculate using Excel formula
|
||||
$fungsi_bangunan = $parameters['fungsi_bangunan'];
|
||||
$ip_permanen = $parameters['ip_permanen'];
|
||||
$ip_kompleksitas = $parameters['ip_kompleksitas'];
|
||||
$indeks_lokalitas = $parameters['indeks_lokalitas'];
|
||||
$base_value = 70350;
|
||||
$additional_factor = 0.5;
|
||||
|
||||
// Calculate H13 and result
|
||||
$H13 = $fungsi_bangunan * ($ip_permanen + $ip_kompleksitas + (0.5 * $ipKetinggian));
|
||||
$main_calc = 1 * $floorArea * ($indeks_lokalitas * $base_value * $H13 * 1);
|
||||
$additional_calc = $additional_factor * $main_calc;
|
||||
$result = $main_calc + $additional_calc;
|
||||
|
||||
$totalRetribution += $result;
|
||||
|
||||
$tableData[] = [
|
||||
"L{$floor}",
|
||||
$ipKetinggian,
|
||||
number_format($H13, 6),
|
||||
'Rp ' . number_format($result, 2)
|
||||
];
|
||||
}
|
||||
|
||||
$this->table(
|
||||
['Floor', 'IP Ketinggian', 'H13 Value', 'Retribution Amount'],
|
||||
$tableData
|
||||
);
|
||||
|
||||
$this->newLine();
|
||||
$this->info("🏗️ Total Building Retribution (5 floors): Rp " . number_format($totalRetribution, 2));
|
||||
$this->info("📏 Total Building Area: " . number_format($floorArea * 5, 2) . " m²");
|
||||
$this->info("💡 Average per m²: Rp " . number_format($totalRetribution / ($floorArea * 5), 2));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user