fix data count and sum for showing
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Models\SpatialPlanning;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\TourismBasedKBLI;
|
||||
use App\Models\Tax;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LackOfPotentialController extends Controller
|
||||
{
|
||||
@@ -39,6 +40,7 @@ class LackOfPotentialController extends Controller
|
||||
'data_pajak_hiburan' => $data_pajak_hiburan,
|
||||
'data_pajak_hotel' => $data_pajak_hotel,
|
||||
'data_pajak_parkir' => $data_pajak_parkir,
|
||||
'tata_ruang' => $this->getSpatialPlanningData()
|
||||
], 200);
|
||||
}catch(\Exception $e){
|
||||
return response()->json([
|
||||
@@ -46,4 +48,63 @@ class LackOfPotentialController extends Controller
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
$businessSum = 0;
|
||||
$nonBusinessSum = 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++;
|
||||
$businessSum += $calculatedAmount;
|
||||
} else {
|
||||
$nonBusinessCount++;
|
||||
$nonBusinessSum += $calculatedAmount;
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
'business_sum' => (float) $businessSum,
|
||||
'non_business_sum' => (float) $nonBusinessSum,
|
||||
];
|
||||
} 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,
|
||||
'business_sum' => 0.0,
|
||||
'non_business_sum' => 0.0,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user