update retribution calculation spatial plannings
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('spatial_plannings', function (Blueprint $table) {
|
||||
$table->text('no_tapak')->nullable();
|
||||
$table->text('no_skkl')->nullable();
|
||||
$table->text('no_ukl')->nullable();
|
||||
$table->string('building_function')->nullable();
|
||||
$table->string('sub_building_function')->nullable();
|
||||
$table->integer('number_of_floors')->default(1);
|
||||
$table->decimal('land_area', 18, 6)->nullable();
|
||||
$table->decimal('site_bcr', 10, 6)->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('spatial_plannings', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'no_tapak',
|
||||
'no_skkl',
|
||||
'no_ukl',
|
||||
'building_function',
|
||||
'sub_building_function',
|
||||
'number_of_floors',
|
||||
'land_area',
|
||||
'site_bcr',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('building_functions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('code')->unique();
|
||||
$table->string('name');
|
||||
$table->string('description')->nullable();
|
||||
$table->unsignedBigInteger('parent_id')->nullable();
|
||||
$table->foreign('parent_id')->references('id')->on('building_functions')->onDelete('cascade');
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->integer('level')->default(0);
|
||||
$table->integer('sort_order')->default(0);
|
||||
$table->index(['parent_id', 'is_active']);
|
||||
$table->index(['level', 'sort_order']);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('building_functions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('building_function_parameters', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('building_function_id')->constrained('building_functions')->onDelete('cascade');
|
||||
$table->decimal('fungsi_bangunan', 10, 6)->comment('Parameter fungsi bangunan');
|
||||
$table->decimal('ip_permanen', 10, 6)->comment('Parameter IP permanen');
|
||||
$table->decimal('ip_kompleksitas', 10, 6)->comment('Parameter IP kompleksitas');
|
||||
$table->decimal('ip_ketinggian', 10, 6)->comment('Parameter IP ketinggian');
|
||||
$table->decimal('indeks_lokalitas', 10, 6)->comment('Parameter indeks lokalitas');
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
// Unique constraint untuk 1:1 relationship
|
||||
$table->unique('building_function_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('building_function_parameters');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('retribution_formulas', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('building_function_id')->constrained('building_functions')->onDelete('cascade');
|
||||
$table->string('name')->comment('Nama formula');
|
||||
$table->text('formula_expression')->comment('Rumus matematika untuk perhitungan');
|
||||
$table->text('description')->nullable()->comment('Deskripsi formula');
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
|
||||
// Unique constraint untuk 1:1 relationship
|
||||
$table->unique('building_function_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('retribution_formulas');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('retribution_calculations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('spatial_planning_id')->constrained('spatial_plannings')->onDelete('cascade');
|
||||
$table->foreignId('retribution_formula_id')->nullable()->constrained('retribution_formulas')->onDelete('set null');
|
||||
$table->foreignId('detected_building_function_id')->nullable()->constrained('building_functions')->onDelete('set null');
|
||||
$table->decimal('luas_bangunan', 15, 6)->comment('Luas bangunan yang digunakan dalam perhitungan');
|
||||
$table->json('used_parameters')->nullable()->comment('Parameter yang digunakan dalam perhitungan');
|
||||
$table->string('used_formula')->nullable()->comment('Formula yang digunakan dalam perhitungan');
|
||||
$table->decimal('calculation_result', 15, 6)->nullable()->comment('Hasil perhitungan retribusi');
|
||||
$table->datetime('calculation_date')->nullable()->comment('Tanggal perhitungan');
|
||||
$table->foreignId('calculated_by')->nullable()->constrained('users')->onDelete('set null');
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
// Unique constraint untuk 1:1 relationship dengan spatial_plannings
|
||||
$table->unique('spatial_planning_id');
|
||||
|
||||
// Index untuk performa query dengan nama yang lebih pendek
|
||||
$table->index(['retribution_formula_id', 'calculation_date'], 'idx_formula_calc_date');
|
||||
$table->index(['detected_building_function_id', 'calculation_date'], 'idx_building_func_calc_date');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('retribution_calculations');
|
||||
}
|
||||
};
|
||||
145
database/seeders/BuildingFunctionSeeder.php
Normal file
145
database/seeders/BuildingFunctionSeeder.php
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@ class DatabaseSeeder extends Seeder
|
||||
MenuSeeder::class,
|
||||
UsersRoleMenuSeeder::class,
|
||||
GlobalSettingSeeder::class,
|
||||
BuildingFunctionSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user