add spatial plannings retribution calculations
This commit is contained in:
@@ -5,141 +5,152 @@ 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 = [
|
||||
[
|
||||
'code' => 'AGAMA',
|
||||
'name' => 'Fungsi Keagamaan',
|
||||
'description' => 'Fungsi Keagamaan',
|
||||
'parent_id' => null,
|
||||
'is_active' => true,
|
||||
'level' => 0,
|
||||
'sort_order' => 1,
|
||||
],
|
||||
[
|
||||
'code' => 'SOSIAL_BUDAYA',
|
||||
'name' => 'Fungsi Sosial Budaya',
|
||||
'description' => 'Fungsi Sosial Budaya',
|
||||
'parent_id' => null,
|
||||
'is_active' => true,
|
||||
'level' => 0,
|
||||
'sort_order' => 2,
|
||||
],
|
||||
[
|
||||
'code' => 'CAMPURAN',
|
||||
'name' => 'Fungsi Campuran',
|
||||
'description' => 'Fungsi Campuran',
|
||||
'parent_id' => null,
|
||||
'is_active' => true,
|
||||
'level' => 0,
|
||||
'sort_order' => 3,
|
||||
'children' => [
|
||||
[
|
||||
'code' => 'CAMPURAN_KECIL',
|
||||
'name' => 'Fungsi Campuran Kecil',
|
||||
'description' => 'Fungsi Campuran Kecil',
|
||||
'is_active' => true,
|
||||
'level' => 1,
|
||||
'sort_order' => 1,
|
||||
],
|
||||
[
|
||||
'code' => 'CAMPURAN_BESAR',
|
||||
'name' => 'Fungsi Campuran Besar',
|
||||
'description' => 'Fungsi Campuran Besar',
|
||||
'is_active' => true,
|
||||
'level' => 1,
|
||||
'sort_order' => 2,
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'code' => 'USAHA',
|
||||
'name' => 'Fungsi Usaha',
|
||||
'description' => 'Fungsi Usaha',
|
||||
'parent_id' => null,
|
||||
'is_active' => true,
|
||||
'level' => 0,
|
||||
'sort_order' => 4,
|
||||
'children' => [
|
||||
[
|
||||
'code' => 'USAHA_KECIL',
|
||||
'name' => 'UMKM',
|
||||
'description' => 'Fungsi Usaha Kecil',
|
||||
'is_active' => true,
|
||||
'level' => 1,
|
||||
'sort_order' => 1,
|
||||
],
|
||||
[
|
||||
'code' => 'USAHA_BESAR',
|
||||
'name' => 'Usaha Besar (Non-Mikro)',
|
||||
'description' => 'Fungsi Usaha Besar',
|
||||
'is_active' => true,
|
||||
'level' => 1,
|
||||
'sort_order' => 2,
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'code' => 'HUNIAN',
|
||||
'name' => 'Fungsi Hunian',
|
||||
'description' => 'Fungsi Hunian',
|
||||
'parent_id' => null,
|
||||
'is_active' => true,
|
||||
'level' => 0,
|
||||
'sort_order' => 5,
|
||||
'children' => [
|
||||
[
|
||||
'code' => 'HUNIAN_KECIL',
|
||||
'name' => 'Sederhana < 100 m2',
|
||||
'description' => 'Sederhana < 100 m2',
|
||||
'is_active' => true,
|
||||
'level' => 1,
|
||||
'sort_order' => 1,
|
||||
],
|
||||
[
|
||||
'code' => 'HUNIAN_BESAR',
|
||||
'name' => 'Sederhana > 100 m2',
|
||||
'description' => 'Sederhana > 100 m2',
|
||||
'is_active' => true,
|
||||
'level' => 1,
|
||||
'sort_order' => 2,
|
||||
],
|
||||
[
|
||||
'code' => 'HUNIAN_MBR',
|
||||
'name' => 'MBR',
|
||||
'description' => 'Rumah Tinggal Deret (MBR) dan Rumah Tinggal Tunggal (MBR)',
|
||||
'is_active' => true,
|
||||
'level' => 1,
|
||||
'sort_order' => 3,
|
||||
]
|
||||
]
|
||||
]
|
||||
// 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) {
|
||||
$this->insertOrUpdateByCode($function);
|
||||
DB::table('building_functions')->updateOrInsert(
|
||||
['id' => $function['id']],
|
||||
array_merge($function, [
|
||||
'description' => 'Deskripsi untuk ' . $function['name'],
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function insertOrUpdateByCode(array $data, ?int $parentId = null): void
|
||||
{
|
||||
$children = $data['children'] ?? [];
|
||||
unset($data['children']);
|
||||
// 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],
|
||||
];
|
||||
|
||||
$data['parent_id'] = $parentId;
|
||||
|
||||
// Insert or update by code
|
||||
$record = BuildingFunction::updateOrCreate(
|
||||
['code' => $data['code']],
|
||||
$data
|
||||
);
|
||||
|
||||
foreach ($children as $child) {
|
||||
$this->insertOrUpdateByCode($child, $record->id);
|
||||
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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user