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

@@ -539,14 +539,16 @@ class ServiceGoogleSheet
}
/**
* Get count of spatial plannings that have active retribution calculations
* Get count of spatial plannings that can be calculated with new formula
*/
public function getSpatialPlanningWithCalculationCount(): int
{
try {
return SpatialPlanning::whereHas('retributionCalculations', function ($query) {
$query->where('is_active', true);
})->count();
// Count spatial plannings that have valid data and are not yet issued (is_terbit = false)
return SpatialPlanning::where('land_area', '>', 0)
->where('site_bcr', '>', 0)
->where('is_terbit', false)
->count();
} catch (\Exception $e) {
Log::error("Error getting spatial planning with calculation count", ['error' => $e->getMessage()]);
return 0;
@@ -554,25 +556,29 @@ class ServiceGoogleSheet
}
/**
* Get total sum of retribution amounts for spatial plannings with active calculations
* Get total sum of retribution amounts using new calculation formula
*/
public function getSpatialPlanningCalculationSum(): float
{
try {
// Get all spatial plannings that have active calculations
$spatialPlannings = SpatialPlanning::whereHas('retributionCalculations', function ($query) {
$query->where('is_active', true);
})->with(['retributionCalculations.retributionCalculation'])
->get();
// 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;
foreach ($spatialPlannings as $spatialPlanning) {
$activeCalculation = $spatialPlanning->activeRetributionCalculation;
if ($activeCalculation && $activeCalculation->retributionCalculation) {
$totalSum += $activeCalculation->retributionCalculation->retribution_amount;
}
// Use new calculation formula: LUAS LAHAN × BCR × HARGA SATUAN
$totalSum += $spatialPlanning->calculated_retribution;
}
Log::info("Spatial Planning Calculation Sum (is_terbit = false only)", [
'total_records' => $spatialPlannings->count(),
'total_sum' => $totalSum,
'filtered_by' => 'is_terbit = false'
]);
return (float) $totalSum;
} catch (\Exception $e) {
Log::error("Error getting spatial planning calculation sum", ['error' => $e->getMessage()]);