update retribution calculation spatial plannings

This commit is contained in:
arifal
2025-06-17 17:58:37 +07:00
parent 236b6f9bfc
commit 6946fa7074
14 changed files with 1069 additions and 1 deletions

View File

@@ -0,0 +1,145 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\BuildingFunction;
class BuildingFunctionSeeder extends Seeder
{
public function run(): void
{
$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,
]
]
]
];
foreach ($buildingFunctions as $function) {
$this->insertOrUpdateByCode($function);
}
}
private function insertOrUpdateByCode(array $data, ?int $parentId = null): void
{
$children = $data['children'] ?? [];
unset($data['children']);
$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);
}
}
}