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,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class RequestAssignmentController extends Controller
|
||||
// Apply year filter if provided (to match BigdataResume behavior)
|
||||
if ($request->has('year') && !empty($request->get('year'))) {
|
||||
$year = $request->get('year');
|
||||
$baseQuery->whereYear('task_created_at', $year);
|
||||
$baseQuery->where('due_date', '>=', $year.'-02-01');
|
||||
Log::info('RequestAssignmentController year filter applied', ['year' => $year]);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,27 +50,27 @@ class BigdataResume extends Model
|
||||
// Filter only valid data (is_valid = true)
|
||||
$verified_count = PbgTask::whereIn('status', PbgTaskStatus::getVerified())
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('pbg_task.due_date', '>=', $year.'-02-01')
|
||||
->count();
|
||||
$non_verified_count = PbgTask::whereIn('status', PbgTaskStatus::getNonVerified())
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('pbg_task.due_date', '>=', $year.'-02-01')
|
||||
->count();
|
||||
$waiting_click_dpmptsp_count = PbgTask::whereIn('status', PbgTaskStatus::getWaitingClickDpmptsp())
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('pbg_task.due_date', '>=', $year.'-02-01')
|
||||
->count();
|
||||
$issuance_realization_pbg_count = PbgTask::whereIn('status', PbgTaskStatus::getIssuanceRealizationPbg())
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('pbg_task.due_date', '>=', $year.'-02-01')
|
||||
->count();
|
||||
$process_in_technical_office_count = PbgTask::whereIn('status', PbgTaskStatus::getProcessInTechnicalOffice())
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('pbg_task.due_date', '>=', $year.'-02-01')
|
||||
->count();
|
||||
$potention_count = PbgTask::whereIn('status', PbgTaskStatus::getPotention())
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('pbg_task.due_date', '>=', $year.'-02-01')
|
||||
->count();
|
||||
|
||||
// Business count: function_type LIKE usaha OR (non-business with unit > 1)
|
||||
@@ -98,7 +98,7 @@ class BigdataResume extends Model
|
||||
->whereIn("status", PbgTaskStatus::getNonVerified());
|
||||
})
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('due_date', '>=', $year.'-02-01')
|
||||
->count();
|
||||
|
||||
// Non-business count: function_type NOT LIKE usaha AND (unit IS NULL OR unit <= 1)
|
||||
@@ -120,7 +120,7 @@ class BigdataResume extends Model
|
||||
});
|
||||
})
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('due_date', '>=', $year.'-02-01')
|
||||
->count();
|
||||
|
||||
// Business RAB count - for each business task with data_type=3:
|
||||
@@ -134,7 +134,7 @@ class BigdataResume extends Model
|
||||
->whereIn("status", PbgTaskStatus::getNonVerified());
|
||||
})
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('due_date', '>=', $year.'-02-01')
|
||||
->whereExists(function ($query) {
|
||||
$query->select(DB::raw(1))
|
||||
->from('pbg_task_detail_data_lists')
|
||||
@@ -167,7 +167,7 @@ class BigdataResume extends Model
|
||||
->whereIn("status", PbgTaskStatus::getNonVerified());
|
||||
})
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('due_date', '>=', $year.'-02-01')
|
||||
->whereExists(function ($query) {
|
||||
$query->select(DB::raw(1))
|
||||
->from('pbg_task_detail_data_lists')
|
||||
@@ -200,7 +200,7 @@ class BigdataResume extends Model
|
||||
->whereIn("status", PbgTaskStatus::getNonVerified());
|
||||
})
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('due_date', '>=', $year.'-02-01')
|
||||
->whereExists(function ($query) {
|
||||
$query->select(DB::raw(1))
|
||||
->from('pbg_task_detail_data_lists')
|
||||
@@ -236,7 +236,7 @@ class BigdataResume extends Model
|
||||
->whereIn("status", PbgTaskStatus::getNonVerified());
|
||||
})
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('due_date', '>=', $year.'-02-01')
|
||||
->whereExists(function ($query) {
|
||||
$query->select(DB::raw(1))
|
||||
->from('pbg_task_detail_data_lists')
|
||||
@@ -272,7 +272,7 @@ class BigdataResume extends Model
|
||||
->whereIn("status", PbgTaskStatus::getNonVerified());
|
||||
})
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('due_date', '>=', $year.'-02-01')
|
||||
->whereExists(function ($query) {
|
||||
$query->select(DB::raw(1))
|
||||
->from('pbg_task_detail_data_lists')
|
||||
@@ -297,7 +297,7 @@ class BigdataResume extends Model
|
||||
// Debug: Check if there are non-verified tasks and their retribution data
|
||||
$debug_non_verified = PbgTask::whereIn('status', PbgTaskStatus::getNonVerified())
|
||||
->where('is_valid', true)
|
||||
->whereYear('task_created_at', $year)
|
||||
->where('due_date', '>=', $year.'-02-01')
|
||||
->with('pbg_task_retributions')
|
||||
->get();
|
||||
|
||||
@@ -324,7 +324,7 @@ class BigdataResume extends Model
|
||||
// Get other sum values using proper aggregation to handle multiple retributions
|
||||
$stats = PbgTask::leftJoin('pbg_task_retributions as ptr', 'pbg_task.uuid', '=', 'ptr.pbg_task_uid')
|
||||
->where('pbg_task.is_valid', true)
|
||||
->whereYear('pbg_task.task_created_at', $year)
|
||||
->where('pbg_task.due_date', '>=', $year.'-02-01')
|
||||
->selectRaw("
|
||||
SUM(CASE WHEN pbg_task.status in (".implode(',', PbgTaskStatus::getVerified()).") THEN COALESCE(ptr.nilai_retribusi_bangunan, 0) ELSE 0 END) AS verified_total,
|
||||
SUM(CASE WHEN pbg_task.status in (".implode(',', PbgTaskStatus::getWaitingClickDpmptsp()).") THEN COALESCE(ptr.nilai_retribusi_bangunan, 0) ELSE 0 END) AS waiting_click_dpmptsp_total,
|
||||
|
||||
Reference in New Issue
Block a user