75 lines
3.1 KiB
PHP
75 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
use Illuminate\Database\Seeder;
|
|
use App\Models\BuildingFunction;
|
|
use App\Models\RetributionFormula;
|
|
|
|
class RetributionFormulaSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
// Get building function codes from the actual seeded data (child functions only)
|
|
$buildingFunctionCodes = [
|
|
'AGAMA',
|
|
'SOSIAL_BUDAYA',
|
|
'CAMPURAN_KECIL',
|
|
'CAMPURAN_BESAR',
|
|
'USAHA_KECIL',
|
|
'USAHA_BESAR',
|
|
'HUNIAN_SEDERHANA',
|
|
'HUNIAN_TIDAK_SEDERHANA',
|
|
'MBR'
|
|
];
|
|
|
|
// Formula lengkap retribusi dengan perhitungan per lantai
|
|
// Bagian 1: Perhitungan per lantai
|
|
$floorCalculationFormula = "(fungsi_bangunan * (ip_permanen + ip_kompleksitas + (0.5 * ip_ketinggian)))";
|
|
|
|
// Bagian 2: Formula retribusi lengkap
|
|
$mainFormula = "(1 * luas_bangunan * (indeks_lokalitas * 70350 * ({$floorCalculationFormula}) * 1))";
|
|
$additionalFormula = "(0.5 * (1 * luas_bangunan * (indeks_lokalitas * 70350 * ({$floorCalculationFormula}) * 1)))";
|
|
$fullFormulaExpression = "{$mainFormula} + {$additionalFormula}";
|
|
|
|
// Buat formula untuk 5 lantai pertama saja
|
|
for ($floorNumber = 1; $floorNumber <= 5; $floorNumber++) {
|
|
foreach ($buildingFunctionCodes as $code) {
|
|
$buildingFunction = BuildingFunction::where('code', $code)->first();
|
|
|
|
if ($buildingFunction) {
|
|
$formulaName = "{$buildingFunction->name} - Lantai {$floorNumber}";
|
|
|
|
RetributionFormula::updateOrCreate(
|
|
[
|
|
'building_function_id' => $buildingFunction->id,
|
|
'floor_number' => $floorNumber
|
|
],
|
|
[
|
|
'name' => $formulaName,
|
|
'formula_expression' => $fullFormulaExpression,
|
|
'description' => "Formula retribusi untuk {$buildingFunction->name} dengan {$floorNumber} lantai. Formula: {$fullFormulaExpression}",
|
|
'floor_number' => $floorNumber,
|
|
'luas_bangunan_rate' => $buildingFunction->base_tariff ?? 50000,
|
|
'is_active' => true
|
|
]
|
|
);
|
|
|
|
$this->command->info("Created formula for: {$formulaName}");
|
|
} else {
|
|
$this->command->warn("Building function not found: {$code}");
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->command->info('Retribution Formulas seeding completed for 5 floors!');
|
|
$this->command->info("Building functions processed: " . implode(', ', $buildingFunctionCodes));
|
|
$this->command->info("Floor calculation formula: {$floorCalculationFormula}");
|
|
$this->command->info("Full retribution formula: {$fullFormulaExpression}");
|
|
}
|
|
}
|