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

@@ -25,7 +25,7 @@ class RequestAssignmentController extends Controller
// Build base query for counting (without relationships to avoid duplicates)
$baseQuery = PbgTask::query();
// Filter only valid data (is_valid = true)
// Always filter only valid data (is_valid = true)
$baseQuery->where('is_valid', true);
// Apply year filter if provided (to match BigdataResume behavior)
@@ -35,100 +35,17 @@ class RequestAssignmentController extends Controller
Log::info('RequestAssignmentController year filter applied', ['year' => $year]);
}
// Apply filters to base query (matching BigdataResume logic exactly)
if ($request->has('filter') && !empty($request->get('filter'))) {
$filter = strtolower(trim($request->get('filter')));
// Log filter for debugging
Log::info('RequestAssignmentController filter applied', ['filter' => $filter, 'original' => $request->get('filter')]);
switch ($filter) {
case 'non-business':
// Match BigdataResume non-business logic exactly
$baseQuery->where(function ($q) {
$q->where(function ($q2) {
$q2->where(function ($q3) {
$q3->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%'])
->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']);
})
->orWhereNull('function_type');
})
->whereIn("status", PbgTaskStatus::getNonVerified());
});
break;
case 'business':
// Match BigdataResume business logic exactly
$baseQuery->where(function ($q) {
$q->where(function ($q2) {
$q2->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%'])
->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']);
})
->whereIn("status", PbgTaskStatus::getNonVerified());
});
break;
case 'verified':
// Match BigdataResume verified logic exactly
$baseQuery->whereIn("status", PbgTaskStatus::getVerified());
break;
case 'non-verified':
// Match BigdataResume non-verified logic exactly
$baseQuery->whereIn("status", PbgTaskStatus::getNonVerified());
break;
case 'potention':
// Match BigdataResume potention logic exactly
$baseQuery->whereIn("status", PbgTaskStatus::getPotention());
break;
case 'issuance-realization-pbg':
// Match BigdataResume issuance realization logic exactly
$baseQuery->whereIn("status", PbgTaskStatus::getIssuanceRealizationPbg());
break;
case 'process-in-technical-office':
// Match BigdataResume process in technical office logic exactly
$baseQuery->whereIn("status", PbgTaskStatus::getProcessInTechnicalOffice());
break;
case 'waiting-click-dpmptsp':
// Match BigdataResume waiting click DPMPTSP logic exactly
$baseQuery->whereIn("status", PbgTaskStatus::getWaitingClickDpmptsp());
break;
default:
// Log unrecognized filter for debugging
Log::warning('Unrecognized filter value', ['filter' => $filter, 'original' => $request->get('filter')]);
break;
}
}
// Apply search to base query
if ($request->has('search') && !empty($request->get("search"))) {
$search = $request->get('search');
// Search in pbg_task columns
$baseQuery->where(function ($q) use ($search) {
$q->where('name', 'LIKE', "%$search%")
->orWhere('registration_number', 'LIKE', "%$search%")
->orWhere('owner_name', 'LIKE', "%$search%")
->orWhere('address', 'LIKE', "%$search%");
});
// If search term exists, also find UUIDs from name_building search
$namesBuildingUuids = DB::table('pbg_task_details')
->where('name_building', 'LIKE', "%$search%")
->pluck('pbg_task_uid')
->toArray();
// If we found matching name_building records, include them in the search
if (!empty($namesBuildingUuids)) {
$baseQuery->orWhereIn('uuid', $namesBuildingUuids);
}
}
// Get filter value, default to 'all' if not provided or empty
$filter = $request->has('filter') && !empty($request->get('filter'))
? strtolower(trim($request->get('filter')))
: 'all';
// Log filter for debugging
Log::info('RequestAssignmentController filter applied', ['filter' => $filter, 'original' => $request->get('filter')]);
// Apply filters to base query using single consolidated method
$this->applyFilter($baseQuery, $filter);
// Get accurate count from base query (without relationships)
$accurateCount = $baseQuery->count();
@@ -144,7 +61,7 @@ class RequestAssignmentController extends Controller
// Log final query count for debugging
Log::info('RequestAssignmentController final result', [
'filter' => $request->get('filter'),
'filter' => $filter,
'search' => $request->get('search'),
'year' => $request->get('year'),
'accurate_count' => $accurateCount,
@@ -153,13 +70,17 @@ class RequestAssignmentController extends Controller
]);
// Cross-validation with BigdataResume logic (for debugging consistency)
if ($request->has('filter') && $request->has('year') &&
!empty($request->get('filter')) && !empty($request->get('year'))) {
$this->validateConsistencyWithBigdataResume($request->get('filter'), $request->get('year'), $accurateCount);
if ($filter !== 'all' && $request->has('year') && !empty($request->get('year'))) {
$this->validateConsistencyWithBigdataResume($filter, $request->get('year'), $accurateCount);
}
// Apply search to data query
if ($request->has('search') && !empty($request->get("search"))) {
$this->applySearch($dataQuery, $request->get('search'));
}
// Additional logging for potention filter
if ($request->get('filter') === 'potention') {
if ($filter === 'potention') {
$rejectedCount = PbgTask::whereIn('status', PbgTaskStatus::getRejected())->count();
Log::info('Potention filter details', [
'potention_count' => $accurateCount,
@@ -170,8 +91,8 @@ class RequestAssignmentController extends Controller
}
// Also log to console for immediate debugging
if ($request->has('filter') && !empty($request->get('filter'))) {
error_log('RequestAssignment Filter Debug: ' . $request->get('filter') . ' -> Count: ' . $accurateCount);
if ($filter !== 'all') {
error_log('RequestAssignment Filter Debug: ' . $filter . ' -> Count: ' . $accurateCount);
}
// Get paginated results with relationships
@@ -183,6 +104,198 @@ class RequestAssignmentController extends Controller
return RequestAssignmentResouce::collection($paginatedResults);
}
/**
* Apply filter logic to the query
*/
private function applyFilter($query, string $filter)
{
switch ($filter) {
case 'all':
// No additional filters, just return all valid records
break;
case 'non-business':
// Match BigdataResume non-business logic exactly
$query->where(function ($q) {
$q->where(function ($q2) {
$q2->where(function ($q3) {
$q3->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%'])
->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']);
})
->orWhereNull('function_type');
})
->whereIn("status", PbgTaskStatus::getNonVerified());
});
break;
case 'business':
// Match BigdataResume business logic exactly
$query->where(function ($q) {
$q->where(function ($q2) {
$q2->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%'])
->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']);
})
->whereIn("status", PbgTaskStatus::getNonVerified());
});
break;
case 'verified':
// Match BigdataResume verified logic exactly
$query->whereIn("status", PbgTaskStatus::getVerified());
break;
case 'non-verified':
// Match BigdataResume non-verified logic exactly
$query->whereIn("status", PbgTaskStatus::getNonVerified());
break;
case 'potention':
// Match BigdataResume potention logic exactly
$query->whereIn("status", PbgTaskStatus::getPotention());
break;
case 'issuance-realization-pbg':
// Match BigdataResume issuance realization logic exactly
$query->whereIn("status", PbgTaskStatus::getIssuanceRealizationPbg());
break;
case 'process-in-technical-office':
// Match BigdataResume process in technical office logic exactly
$query->whereIn("status", PbgTaskStatus::getProcessInTechnicalOffice());
break;
case 'waiting-click-dpmptsp':
// Match BigdataResume waiting click DPMPTSP logic exactly
$query->whereIn("status", PbgTaskStatus::getWaitingClickDpmptsp());
break;
case 'non-business-rab':
// Non-business tasks that have RAB documents (data_type = 3) with at least one status != 1
$query->where(function ($q) {
$q->where(function ($q2) {
$q2->where(function ($q3) {
$q3->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%'])
->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']);
})
->orWhereNull('function_type');
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 3)
->where('pbg_task_detail_data_lists.status', '!=', 1);
});
break;
case 'non-business-krk':
// Non-business tasks that have KRK documents (data_type = 2) with at least one status != 1
$query->where(function ($q) {
$q->where(function ($q2) {
$q2->where(function ($q3) {
$q3->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%'])
->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']);
})
->orWhereNull('function_type');
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 2)
->where('pbg_task_detail_data_lists.status', '!=', 1);
});
break;
case 'business-rab':
// Business tasks that have RAB documents (data_type = 3) with at least one status != 1
$query->where(function ($q) {
$q->where(function ($q2) {
$q2->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%'])
->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']);
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 3)
->where('pbg_task_detail_data_lists.status', '!=', 1);
});
break;
case 'business-krk':
// Business tasks that have KRK documents (data_type = 2) with at least one status != 1
$query->where(function ($q) {
$q->where(function ($q2) {
$q2->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%'])
->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']);
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 2)
->where('pbg_task_detail_data_lists.status', '!=', 1);
});
break;
case 'business-dlh':
// Business tasks that have DLH documents (data_type = 5) with at least one status != 1
$query->where(function ($q) {
$q->where(function ($q2) {
$q2->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%'])
->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']);
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 5)
->where('pbg_task_detail_data_lists.status', '!=', 1);
});
break;
default:
// Log unrecognized filter for debugging
Log::warning('Unrecognized filter value', ['filter' => $filter]);
break;
}
}
/**
* Apply search logic to the query
*/
private function applySearch($query, string $search)
{
// Search in pbg_task columns
$query->where(function ($q) use ($search) {
$q->where('name', 'LIKE', "%$search%")
->orWhere('registration_number', 'LIKE', "%$search%")
->orWhere('owner_name', 'LIKE', "%$search%")
->orWhere('address', 'LIKE', "%$search%");
});
// If search term exists, also find UUIDs from name_building search
$namesBuildingUuids = DB::table('pbg_task_details')
->where('name_building', 'LIKE', "%$search%")
->pluck('pbg_task_uid')
->toArray();
// If we found matching name_building records, include them in the search
if (!empty($namesBuildingUuids)) {
$query->orWhereIn('uuid', $namesBuildingUuids);
}
}
public function report_payment_recaps(Request $request)
{
try {
@@ -369,6 +482,112 @@ class RequestAssignmentController extends Controller
->whereYear('task_created_at', $year)
->count();
break;
case 'non-business-rab':
$bigdataResumeCount = PbgTask::where(function ($q) {
$q->where(function ($q2) {
$q2->where(function ($q3) {
$q3->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%'])
->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']);
})
->orWhereNull('function_type');
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->where('is_valid', true)
->whereYear('task_created_at', $year)
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 3)
->where('pbg_task_detail_data_lists.status', '!=', 1);
})
->count();
break;
case 'non-business-krk':
$bigdataResumeCount = PbgTask::where(function ($q) {
$q->where(function ($q2) {
$q2->where(function ($q3) {
$q3->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%'])
->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']);
})
->orWhereNull('function_type');
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->where('is_valid', true)
->whereYear('task_created_at', $year)
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 2)
->where('pbg_task_detail_data_lists.status', '!=', 1);
})
->count();
break;
case 'business-rab':
$bigdataResumeCount = PbgTask::where(function ($q) {
$q->where(function ($q2) {
$q2->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%'])
->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']);
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->where('is_valid', true)
->whereYear('task_created_at', $year)
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 3)
->where('pbg_task_detail_data_lists.status', '!=', 1);
})
->count();
break;
case 'business-krk':
$bigdataResumeCount = PbgTask::where(function ($q) {
$q->where(function ($q2) {
$q2->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%'])
->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']);
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->where('is_valid', true)
->whereYear('task_created_at', $year)
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 2)
->where('pbg_task_detail_data_lists.status', '!=', 1);
})
->count();
break;
case 'business-dlh':
$bigdataResumeCount = PbgTask::where(function ($q) {
$q->where(function ($q2) {
$q2->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%'])
->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']);
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->where('is_valid', true)
->whereYear('task_created_at', $year)
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 5)
->where('pbg_task_detail_data_lists.status', '!=', 1);
})
->count();
break;
default:
Log::info('Unknown filter for consistency validation', [