add status spatial plannings

This commit is contained in:
arifal
2025-08-19 18:15:58 +07:00
parent 71ca8dc553
commit 1b084ed485
20 changed files with 892 additions and 250 deletions

View File

@@ -8,6 +8,7 @@ use App\Http\Controllers\Controller;
use App\Http\Resources\BigdataResumeResource;
use App\Models\BigdataResume;
use App\Models\DataSetting;
use App\Models\SpatialPlanning;
use Barryvdh\DomPDF\Facade\Pdf;
use Carbon\Carbon;
use Illuminate\Http\Request;
@@ -26,13 +27,12 @@ class BigDataResumeController extends Controller
$type = $request->get("type");
if (!$filterDate || $filterDate === "latest") {
$big_data_resume = BigdataResume::where('resume_type', $type)->latest()->first();
$big_data_resume = BigdataResume::latest()->first();
if (!$big_data_resume) {
return $this->response_empty_resume();
}
} else {
$big_data_resume = BigdataResume::where('resume_type', $type)
->whereDate('created_at', $filterDate)
$big_data_resume = BigdataResume::whereDate('created_at', $filterDate)
->orderBy('id', 'desc')
->first();
@@ -54,7 +54,11 @@ class BigDataResumeController extends Controller
$proses_dinas_teknis_sum = $big_data_resume->process_in_technical_office_sum;
$proses_dinas_teknis_count = $big_data_resume->process_in_technical_office_count;
$tata_ruang = $big_data_resume->spatial_sum;
// Get real-time spatial planning data using new calculation formula
$spatialData = $this->getSpatialPlanningData();
$tata_ruang = $spatialData['sum'];
$tata_ruang_count = $spatialData['count'];
$kekurangan_potensi = $target_pad - $big_data_resume->potention_sum;
// percentage kekurangan potensi
@@ -115,8 +119,8 @@ class BigDataResumeController extends Controller
'percentage' => 100,
],
'tata_ruang' => [
'sum' => $big_data_resume->spatial_sum,
'count' => $big_data_resume->spatial_count,
'sum' => $tata_ruang,
'count' => $tata_ruang_count,
'percentage' => $tata_ruang_percentage,
],
'kekurangan_potensi' => [
@@ -399,4 +403,58 @@ class BigDataResumeController extends Controller
return response()->json($result);
}
/**
* Get spatial planning data using new calculation formula
*/
private function getSpatialPlanningData(): array
{
try {
// Get spatial plannings that are not yet issued (is_terbit = false) and have valid data
$spatialPlannings = SpatialPlanning::where('land_area', '>', 0)
->where('site_bcr', '>', 0)
->where('is_terbit', false)
->get();
$totalSum = 0;
$businessCount = 0;
$nonBusinessCount = 0;
foreach ($spatialPlannings as $spatialPlanning) {
// Use new calculation formula: LUAS LAHAN × BCR × HARGA SATUAN
$calculatedAmount = $spatialPlanning->calculated_retribution;
$totalSum += $calculatedAmount;
// Count business types
if ($spatialPlanning->is_business_type) {
$businessCount++;
} else {
$nonBusinessCount++;
}
}
Log::info("Real-time Spatial Planning Data (is_terbit = false only)", [
'total_records' => $spatialPlannings->count(),
'business_count' => $businessCount,
'non_business_count' => $nonBusinessCount,
'total_sum' => $totalSum,
'filtered_by' => 'is_terbit = false'
]);
return [
'count' => $spatialPlannings->count(),
'sum' => (float) $totalSum,
'business_count' => $businessCount,
'non_business_count' => $nonBusinessCount,
];
} catch (\Exception $e) {
Log::error("Error getting spatial planning data", ['error' => $e->getMessage()]);
return [
'count' => 0,
'sum' => 0.0,
'business_count' => 0,
'non_business_count' => 0,
];
}
}
}