Files
sibedas/database/seeders/BuildingFunctionSeeder.php
2025-06-18 02:54:41 +07:00

156 lines
8.9 KiB
PHP

<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\BuildingFunction;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
class BuildingFunctionSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$now = Carbon::now();
// 1. Building Functions Data - Fixed structure with proper parent-child relationships
$buildingFunctions = [
// Parent Categories
['id' => 1, 'code' => 'AGAMA', 'name' => 'Bangunan Keagamaan', 'parent_id' => null, 'level' => 0, 'sort_order' => 1, 'base_tariff' => 0.00],
['id' => 2, 'code' => 'SOSIAL_BUDAYA', 'name' => 'Bangunan Sosial Budaya', 'parent_id' => null, 'level' => 0, 'sort_order' => 2, 'base_tariff' => 30000.00],
['id' => 3, 'code' => 'CAMPURAN', 'name' => 'Bangunan Campuran', 'parent_id' => null, 'level' => 0, 'sort_order' => 3, 'base_tariff' => 70000.00],
['id' => 4, 'code' => 'USAHA', 'name' => 'Bangunan Usaha', 'parent_id' => null, 'level' => 0, 'sort_order' => 4, 'base_tariff' => 60000.00],
['id' => 5, 'code' => 'HUNIAN', 'name' => 'Bangunan Hunian', 'parent_id' => null, 'level' => 0, 'sort_order' => 5, 'base_tariff' => 40000.00],
// Sub Categories - Campuran
['id' => 6, 'code' => 'CAMPURAN_KECIL', 'name' => 'Bangunan Campuran Kecil', 'parent_id' => 3, 'level' => 1, 'sort_order' => 1, 'base_tariff' => 60000.00],
['id' => 7, 'code' => 'CAMPURAN_BESAR', 'name' => 'Bangunan Campuran Besar', 'parent_id' => 3, 'level' => 1, 'sort_order' => 2, 'base_tariff' => 80000.00],
// Sub Categories - Usaha
['id' => 8, 'code' => 'USAHA_KECIL', 'name' => 'Bangunan Usaha Kecil (UMKM)', 'parent_id' => 4, 'level' => 1, 'sort_order' => 1, 'base_tariff' => 50000.00],
['id' => 9, 'code' => 'USAHA_BESAR', 'name' => 'Bangunan Usaha Besar', 'parent_id' => 4, 'level' => 1, 'sort_order' => 2, 'base_tariff' => 70000.00],
// Sub Categories - Hunian
['id' => 10, 'code' => 'HUNIAN_SEDERHANA', 'name' => 'Hunian Sederhana', 'parent_id' => 5, 'level' => 1, 'sort_order' => 1, 'base_tariff' => 35000.00],
['id' => 11, 'code' => 'HUNIAN_TIDAK_SEDERHANA', 'name' => 'Hunian Tidak Sederhana', 'parent_id' => 5, 'level' => 1, 'sort_order' => 2, 'base_tariff' => 45000.00],
['id' => 12, 'code' => 'MBR', 'name' => 'Hunian MBR (Masyarakat Berpenghasilan Rendah)', 'parent_id' => 5, 'level' => 1, 'sort_order' => 3, 'base_tariff' => 0.00],
];
foreach ($buildingFunctions as $function) {
DB::table('building_functions')->updateOrInsert(
['id' => $function['id']],
array_merge($function, [
'description' => 'Deskripsi untuk ' . $function['name'],
'created_at' => $now,
'updated_at' => $now
])
);
}
// 2. Building Function Parameters
$parameters = [
// AGAMA - No charge
['building_function_id' => 1, 'fungsi_bangunan' => 0, 'ip_permanen' => 0, 'ip_kompleksitas' => 0, 'indeks_lokalitas' => 0, 'asumsi_prasarana' => 0.5],
// SOSIAL_BUDAYA
['building_function_id' => 2, 'fungsi_bangunan' => 0.3, 'ip_permanen' => 0.4, 'ip_kompleksitas' => 0.6, 'indeks_lokalitas' => 0.3, 'asumsi_prasarana' => 0.5],
// CAMPURAN_KECIL
['building_function_id' => 6, 'fungsi_bangunan' => 0.6, 'ip_permanen' => 0.4, 'ip_kompleksitas' => 0.6, 'indeks_lokalitas' => 0.5, 'asumsi_prasarana' => 0.5],
// CAMPURAN_BESAR
['building_function_id' => 7, 'fungsi_bangunan' => 0.8, 'ip_permanen' => 0.4, 'ip_kompleksitas' => 0.6, 'indeks_lokalitas' => 0.5, 'asumsi_prasarana' => 0.5],
// USAHA_KECIL
['building_function_id' => 8, 'fungsi_bangunan' => 0.5, 'ip_permanen' => 0.4, 'ip_kompleksitas' => 0.6, 'indeks_lokalitas' => 0.4, 'asumsi_prasarana' => 0.5],
// USAHA_BESAR
['building_function_id' => 9, 'fungsi_bangunan' => 0.7, 'ip_permanen' => 0.4, 'ip_kompleksitas' => 0.6, 'indeks_lokalitas' => 0.5, 'asumsi_prasarana' => 0.5],
// HUNIAN_SEDERHANA
['building_function_id' => 10, 'fungsi_bangunan' => 0.15, 'ip_permanen' => 0.4, 'ip_kompleksitas' => 0.3, 'indeks_lokalitas' => 0.4, 'asumsi_prasarana' => 0.5],
// HUNIAN_TIDAK_SEDERHANA
['building_function_id' => 11, 'fungsi_bangunan' => 0.17, 'ip_permanen' => 0.4, 'ip_kompleksitas' => 0.6, 'indeks_lokalitas' => 0.4, 'asumsi_prasarana' => 0.5],
// MBR - No charge
['building_function_id' => 12, 'fungsi_bangunan' => 0, 'ip_permanen' => 0, 'ip_kompleksitas' => 0, 'indeks_lokalitas' => 0, 'asumsi_prasarana' => 0.5],
];
foreach ($parameters as $param) {
DB::table('building_function_parameters')->updateOrInsert(
['building_function_id' => $param['building_function_id']],
array_merge($param, [
'koefisien_dasar' => 1.0,
'created_at' => $now,
'updated_at' => $now
])
);
}
// 3. Floor Height Indices (IP Ketinggian per lantai)
$floorHeightIndices = [
['floor_number' => 1, 'ip_ketinggian' => 1.000000, 'description' => 'IP ketinggian untuk lantai 1'],
['floor_number' => 2, 'ip_ketinggian' => 1.090000, 'description' => 'IP ketinggian untuk lantai 2'],
['floor_number' => 3, 'ip_ketinggian' => 1.120000, 'description' => 'IP ketinggian untuk lantai 3'],
['floor_number' => 4, 'ip_ketinggian' => 1.350000, 'description' => 'IP ketinggian untuk lantai 4'],
['floor_number' => 5, 'ip_ketinggian' => 1.620000, 'description' => 'IP ketinggian untuk lantai 5'],
['floor_number' => 6, 'ip_ketinggian' => 1.197000, 'description' => 'IP ketinggian untuk lantai 6'],
];
foreach ($floorHeightIndices as $heightIndex) {
DB::table('floor_height_indices')->updateOrInsert(
['floor_number' => $heightIndex['floor_number']],
array_merge($heightIndex, [
'created_at' => $now,
'updated_at' => $now
])
);
}
// Formula Templates removed - not used in current system
// 5. Retribution Formulas per Floor (for child building functions only)
$childBuildingFunctionIds = [1, 2, 6, 7, 8, 9, 10, 11, 12]; // All leaf nodes
$formulaExpression = '(1 * luas_bangunan * (indeks_lokalitas * 70350 * ((fungsi_bangunan * (ip_permanen + ip_kompleksitas + (0.5 * ip_ketinggian)))) * 1)) + (0.5 * (1 * luas_bangunan * (indeks_lokalitas * 70350 * ((fungsi_bangunan * (ip_permanen + ip_kompleksitas + (0.5 * ip_ketinggian)))) * 1)))';
foreach ($childBuildingFunctionIds as $buildingFunctionId) {
$buildingFunction = DB::table('building_functions')->where('id', $buildingFunctionId)->first();
if ($buildingFunction) {
// Create formulas for floors 1-5
for ($floorNumber = 1; $floorNumber <= 5; $floorNumber++) {
DB::table('retribution_formulas')->updateOrInsert(
[
'building_function_id' => $buildingFunctionId,
'floor_number' => $floorNumber
],
[
'name' => "{$buildingFunction->name} - Lantai {$floorNumber}",
'formula_expression' => $formulaExpression,
'created_at' => $now,
'updated_at' => $now
]
);
}
}
}
$this->command->info('Building Function data seeded successfully!');
$this->command->info('Building Function Parameters seeded successfully!');
$this->command->info('Floor Height Indices seeded successfully!');
$this->command->info('Retribution Formulas with IP Ketinggian seeded successfully!');
// Display summary
$this->command->info('=== SUMMARY ===');
$this->command->info('Parent Functions: ' . DB::table('building_functions')->whereNull('parent_id')->count());
$this->command->info('Child Functions: ' . DB::table('building_functions')->whereNotNull('parent_id')->count());
$this->command->info('Parameters: ' . DB::table('building_function_parameters')->count());
$this->command->info('Floor Height Indices: ' . DB::table('floor_height_indices')->count());
$this->command->info('Retribution Formulas: ' . DB::table('retribution_formulas')->count());
}
}