fix calculated and truncate calculation spatial plannings

This commit is contained in:
arifal
2025-07-03 19:19:20 +07:00
parent 5aab6fa3d1
commit 6a22b55a1c
5 changed files with 350 additions and 72 deletions

View File

@@ -453,9 +453,9 @@ class InjectSpatialPlanningsData extends Command
$location = $columnD;
}
// Calculate area: total luas lahan dibagi persentase BCR
// Calculate area: total luas lahan dikali persentase BCR
$calculatedArea = $landArea > 0 && $bcrPercentage > 0 ?
($landArea / ($bcrPercentage / 100)) : 0;
round($landArea * ($bcrPercentage / 100), 2) : 0;
return [
'data_type' => $columnD,
@@ -586,9 +586,9 @@ class InjectSpatialPlanningsData extends Command
$noSKKL = !empty($noSKKLValues) ? implode('|', $noSKKLValues) : null;
$noUKL = !empty($noUKLValues) ? implode('|', $noUKLValues) : null;
// Calculate area using BCR formula: land_area / (bcr_percentage / 100)
// Calculate area using BCR formula: land_area * (bcr_percentage / 100)
$calculatedArea = $landArea > 0 && $bcrPercentage > 0 ?
($landArea / ($bcrPercentage / 100)) : 0;
round($landArea * ($bcrPercentage / 100), 2) : 0;
// Determine building_function and sub_building_function based on activities and applicant name
$buildingFunction = 'Mixed Development'; // Default
@@ -598,21 +598,8 @@ class InjectSpatialPlanningsData extends Command
$applicantName = $section['applicant_name'] ?? '';
$isCompany = (strpos($applicantName, 'PT ') === 0 || strpos($applicantName, 'PT.') === 0);
// PRIORITY: PT Company validation - PT/PT. automatically classified as Fungsi Usaha
if ($isCompany) {
$buildingFunction = 'Fungsi Usaha';
// For PT companies: area-based classification
if ($landArea > 0 && $landArea < 500) { // < 500 m² for PT = Non-Mikro (since PT is already established business)
$subBuildingFunction = 'Usaha Besar (Non-Mikro)';
} elseif ($landArea >= 500) { // >= 500 m² for PT = Large Business
$subBuildingFunction = 'Usaha Besar (Non-Mikro)';
} else {
$subBuildingFunction = 'Usaha Besar (Non-Mikro)'; // Default for PT
}
}
// For non-PT applicants, use activity-based classification
elseif (!empty($activities)) {
// Activity-based classification (priority over PT validation for specific activities)
if (!empty($activities)) {
$activitiesLower = strtolower($activities);
// 1. FUNGSI KEAGAMAAN
@@ -629,7 +616,39 @@ class InjectSpatialPlanningsData extends Command
$subBuildingFunction = 'Fungsi Keagamaan';
}
// 2. FUNGSI SOSIAL BUDAYA
// 2. FUNGSI HUNIAN (PERUMAHAN) - PRIORITY HIGHER THAN PT VALIDATION
elseif (strpos($activitiesLower, 'perumahan') !== false ||
strpos($activitiesLower, 'perumhan') !== false ||
strpos($activitiesLower, 'perum') !== false ||
strpos($activitiesLower, 'rumah') !== false ||
strpos($activitiesLower, 'hunian') !== false ||
strpos($activitiesLower, 'residence') !== false ||
strpos($activitiesLower, 'residential') !== false ||
strpos($activitiesLower, 'housing') !== false ||
strpos($activitiesLower, 'town') !== false) {
$buildingFunction = 'Fungsi Hunian';
// Determine housing type based on area and keywords
if (strpos($activitiesLower, 'mbr') !== false ||
strpos($activitiesLower, 'masyarakat berpenghasilan rendah') !== false ||
strpos($activitiesLower, 'sederhana') !== false ||
($landArea > 0 && $landArea < 2000)) { // Small area indicates MBR
$subBuildingFunction = 'Rumah Tinggal Deret (MBR) dan Rumah Tinggal Tunggal (MBR)';
}
elseif ($landArea > 0 && $landArea < 100) {
$subBuildingFunction = 'Sederhana <100';
}
elseif ($landArea > 0 && $landArea > 100) {
$subBuildingFunction = 'Tidak Sederhana >100';
}
else {
$subBuildingFunction = 'Tidak Sederhana >100'; // Default for housing
}
}
// 3. FUNGSI SOSIAL BUDAYA
elseif (strpos($activitiesLower, 'sekolah') !== false ||
strpos($activitiesLower, 'rumah sakit') !== false ||
strpos($activitiesLower, 'puskesmas') !== false ||
@@ -648,7 +667,7 @@ class InjectSpatialPlanningsData extends Command
$subBuildingFunction = 'Fungsi Sosial Budaya';
}
// 3. FUNGSI USAHA
// 4. FUNGSI USAHA
elseif (strpos($activitiesLower, 'perdagangan') !== false ||
strpos($activitiesLower, 'dagang') !== false ||
strpos($activitiesLower, 'toko') !== false ||
@@ -681,37 +700,6 @@ class InjectSpatialPlanningsData extends Command
}
}
// 4. FUNGSI HUNIAN (PERUMAHAN)
elseif (strpos($activitiesLower, 'rumah') !== false ||
strpos($activitiesLower, 'hunian') !== false ||
strpos($activitiesLower, 'residence') !== false ||
strpos($activitiesLower, 'residential') !== false ||
strpos($activitiesLower, 'housing') !== false ||
strpos($activitiesLower, 'town') !== false) {
$buildingFunction = 'Fungsi Hunian';
// Determine housing type based on area and keywords
if (strpos($activitiesLower, 'mbr') !== false ||
strpos($activitiesLower, 'masyarakat berpenghasilan rendah') !== false ||
strpos($activitiesLower, 'perumahan') !== false ||
strpos($activitiesLower, 'perumhan') !== false ||
strpos($activitiesLower, 'sederhana') !== false ||
($landArea > 0 && $landArea < 2000)) { // Small area indicates MBR
$subBuildingFunction = 'Rumah Tinggal Deret (MBR) dan Rumah Tinggal Tunggal (MBR)';
}
elseif ($landArea > 0 && $landArea < 100) {
$subBuildingFunction = 'Sederhana <100';
}
elseif ($landArea > 0 && $landArea > 100) {
$subBuildingFunction = 'Tidak Sederhana >100';
}
else {
$subBuildingFunction = 'Fungsi Hunian'; // Default for housing
}
}
// 5. FUNGSI CAMPURAN
elseif (strpos($activitiesLower, 'campuran') !== false ||
strpos($activitiesLower, 'mixed') !== false ||
@@ -727,6 +715,38 @@ class InjectSpatialPlanningsData extends Command
$subBuildingFunction = 'Campuran Kecil';
}
}
// If no specific activity detected, fall back to PT validation
else {
// PT Company validation - PT/PT. automatically classified as Fungsi Usaha
if ($isCompany) {
$buildingFunction = 'Fungsi Usaha';
// For PT companies: area-based classification
if ($landArea > 0 && $landArea < 500) { // < 500 m² for PT = Non-Mikro (since PT is already established business)
$subBuildingFunction = 'Usaha Besar (Non-Mikro)';
} elseif ($landArea >= 500) { // >= 500 m² for PT = Large Business
$subBuildingFunction = 'Usaha Besar (Non-Mikro)';
} else {
$subBuildingFunction = 'Usaha Besar (Non-Mikro)'; // Default for PT
}
}
}
}
// If no activities, fall back to PT validation
else {
// PT Company validation - PT/PT. automatically classified as Fungsi Usaha
if ($isCompany) {
$buildingFunction = 'Fungsi Usaha';
// For PT companies: area-based classification
if ($landArea > 0 && $landArea < 500) { // < 500 m² for PT = Non-Mikro (since PT is already established business)
$subBuildingFunction = 'Usaha Besar (Non-Mikro)';
} elseif ($landArea >= 500) { // >= 500 m² for PT = Large Business
$subBuildingFunction = 'Usaha Besar (Non-Mikro)';
} else {
$subBuildingFunction = 'Usaha Besar (Non-Mikro)'; // Default for PT
}
}
}
return [