diff --git a/app/Http/Controllers/Api/RequestAssignmentController.php b/app/Http/Controllers/Api/RequestAssignmentController.php index e85f961..1456430 100644 --- a/app/Http/Controllers/Api/RequestAssignmentController.php +++ b/app/Http/Controllers/Api/RequestAssignmentController.php @@ -114,7 +114,7 @@ class RequestAssignmentController extends Controller // No additional filters, just return all valid records break; case 'non-business': - // Match BigdataResume non-business logic exactly + // Non-business: function_type NOT LIKE usaha AND (unit IS NULL OR unit <= 1) $query->where(function ($q) { $q->where(function ($q2) { $q2->where(function ($q3) { @@ -123,16 +123,39 @@ class RequestAssignmentController extends Controller }) ->orWhereNull('function_type'); }) - ->whereIn("status", PbgTaskStatus::getNonVerified()); + ->whereIn("status", PbgTaskStatus::getNonVerified()) + // Additional condition: unit IS NULL OR unit <= 1 + ->where(function ($q3) { + $q3->whereDoesntHave('pbg_task_detail', function ($q4) { + $q4->where('unit', '>', 1); + }) + ->orWhereDoesntHave('pbg_task_detail'); + }); }); break; case 'business': - // Match BigdataResume business logic exactly + // Business: function_type LIKE usaha OR (non-business with unit > 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%']); + // Traditional business: function_type LIKE usaha + $q2->where(function ($q3) { + $q3->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%']) + ->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']); + }) + // OR non-business with unit > 1 (becomes business) + ->orWhere(function ($q3) { + $q3->where(function ($q4) { + $q4->where(function ($q5) { + $q5->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%']) + ->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']); + }) + ->orWhereNull('function_type'); + }) + ->whereHas('pbg_task_detail', function ($q4) { + $q4->where('unit', '>', 1); + }); + }); }) ->whereIn("status", PbgTaskStatus::getNonVerified()); }); @@ -169,7 +192,7 @@ class RequestAssignmentController extends Controller break; case 'non-business-rab': - // Non-business tasks that have RAB documents (data_type = 3) with at least one status != 1 + // Non-business tasks: function_type NOT LIKE usaha AND (unit IS NULL OR unit <= 1) $query->where(function ($q) { $q->where(function ($q2) { $q2->where(function ($q3) { @@ -178,7 +201,14 @@ class RequestAssignmentController extends Controller }) ->orWhereNull('function_type'); }) - ->whereIn("status", PbgTaskStatus::getNonVerified()); + ->whereIn("status", PbgTaskStatus::getNonVerified()) + // Additional condition: unit IS NULL OR unit <= 1 + ->where(function ($q3) { + $q3->whereDoesntHave('pbg_task_detail', function ($q4) { + $q4->where('unit', '>', 1); + }) + ->orWhereDoesntHave('pbg_task_detail'); + }); }) ->whereExists(function ($query) { $query->select(DB::raw(1)) @@ -190,7 +220,7 @@ class RequestAssignmentController extends Controller break; case 'non-business-krk': - // Non-business tasks that have KRK documents (data_type = 2) with at least one status != 1 + // Non-business tasks: function_type NOT LIKE usaha AND (unit IS NULL OR unit <= 1) $query->where(function ($q) { $q->where(function ($q2) { $q2->where(function ($q3) { @@ -199,7 +229,14 @@ class RequestAssignmentController extends Controller }) ->orWhereNull('function_type'); }) - ->whereIn("status", PbgTaskStatus::getNonVerified()); + ->whereIn("status", PbgTaskStatus::getNonVerified()) + // Additional condition: unit IS NULL OR unit <= 1 + ->where(function ($q3) { + $q3->whereDoesntHave('pbg_task_detail', function ($q4) { + $q4->where('unit', '>', 1); + }) + ->orWhereDoesntHave('pbg_task_detail'); + }); }) ->whereExists(function ($query) { $query->select(DB::raw(1)) @@ -211,11 +248,27 @@ class RequestAssignmentController extends Controller break; case 'business-rab': - // Business tasks that have RAB documents (data_type = 3) with at least one status != 1 + // Business tasks: function_type LIKE usaha OR (non-business with unit > 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%']); + // Traditional business: function_type LIKE usaha + $q2->where(function ($q3) { + $q3->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%']) + ->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']); + }) + // OR non-business with unit > 1 (becomes business) + ->orWhere(function ($q3) { + $q3->where(function ($q4) { + $q4->where(function ($q5) { + $q5->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%']) + ->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']); + }) + ->orWhereNull('function_type'); + }) + ->whereHas('pbg_task_detail', function ($q4) { + $q4->where('unit', '>', 1); + }); + }); }) ->whereIn("status", PbgTaskStatus::getNonVerified()); }) @@ -229,11 +282,27 @@ class RequestAssignmentController extends Controller break; case 'business-krk': - // Business tasks that have KRK documents (data_type = 2) with at least one status != 1 + // Business tasks: function_type LIKE usaha OR (non-business with unit > 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%']); + // Traditional business: function_type LIKE usaha + $q2->where(function ($q3) { + $q3->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%']) + ->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']); + }) + // OR non-business with unit > 1 (becomes business) + ->orWhere(function ($q3) { + $q3->where(function ($q4) { + $q4->where(function ($q5) { + $q5->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%']) + ->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']); + }) + ->orWhereNull('function_type'); + }) + ->whereHas('pbg_task_detail', function ($q4) { + $q4->where('unit', '>', 1); + }); + }); }) ->whereIn("status", PbgTaskStatus::getNonVerified()); }) @@ -247,11 +316,27 @@ class RequestAssignmentController extends Controller break; case 'business-dlh': - // Business tasks that have DLH documents (data_type = 5) with at least one status != 1 + // Business tasks: function_type LIKE usaha OR (non-business with unit > 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%']); + // Traditional business: function_type LIKE usaha + $q2->where(function ($q3) { + $q3->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%']) + ->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']); + }) + // OR non-business with unit > 1 (becomes business) + ->orWhere(function ($q3) { + $q3->where(function ($q4) { + $q4->where(function ($q5) { + $q5->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%']) + ->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']); + }) + ->orWhereNull('function_type'); + }) + ->whereHas('pbg_task_detail', function ($q4) { + $q4->where('unit', '>', 1); + }); + }); }) ->whereIn("status", PbgTaskStatus::getNonVerified()); }) @@ -285,7 +370,7 @@ class RequestAssignmentController extends Controller }); // If search term exists, also find UUIDs from name_building search - $namesBuildingUuids = DB::table('pbg_task_details') + $namesBuildingUuids = DB::table('pbg_task_detail') ->where('name_building', 'LIKE', "%$search%") ->pluck('pbg_task_uid') ->toArray(); @@ -429,8 +514,24 @@ class RequestAssignmentController extends Controller case 'business': $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%']); + // Traditional business: function_type LIKE usaha + $q2->where(function ($q3) { + $q3->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%']) + ->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']); + }) + // OR non-business with unit > 1 (becomes business) + ->orWhere(function ($q3) { + $q3->where(function ($q4) { + $q4->where(function ($q5) { + $q5->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%']) + ->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']); + }) + ->orWhereNull('function_type'); + }) + ->whereHas('pbg_task_detail', function ($q4) { + $q4->where('unit', '>', 1); + }); + }); }) ->whereIn("status", PbgTaskStatus::getNonVerified()); }) @@ -448,7 +549,14 @@ class RequestAssignmentController extends Controller }) ->orWhereNull('function_type'); }) - ->whereIn("status", PbgTaskStatus::getNonVerified()); + ->whereIn("status", PbgTaskStatus::getNonVerified()) + // Additional condition: unit IS NULL OR unit <= 1 + ->where(function ($q3) { + $q3->whereDoesntHave('pbg_task_detail', function ($q4) { + $q4->where('unit', '>', 1); + }) + ->orWhereDoesntHave('pbg_task_detail'); + }); }) ->where('is_valid', true) ->whereYear('task_created_at', $year) diff --git a/app/Models/BigdataResume.php b/app/Models/BigdataResume.php index 26b8428..01c468e 100644 --- a/app/Models/BigdataResume.php +++ b/app/Models/BigdataResume.php @@ -73,11 +73,27 @@ class BigdataResume extends Model ->whereYear('task_created_at', $year) ->count(); - // Business count (same logic as RequestAssignmentController) + // Business count: function_type LIKE usaha OR (non-business with unit > 1) $business_count = 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%']); + // Traditional business: function_type LIKE usaha + $q2->where(function ($q3) { + $q3->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%']) + ->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']); + }) + // OR non-business with unit > 1 (becomes business) + ->orWhere(function ($q3) { + $q3->where(function ($q4) { + $q4->where(function ($q5) { + $q5->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%']) + ->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']); + }) + ->orWhereNull('function_type'); + }) + ->whereHas('pbg_task_detail', function ($q4) { + $q4->where('unit', '>', 1); + }); + }); }) ->whereIn("status", PbgTaskStatus::getNonVerified()); }) @@ -85,7 +101,7 @@ class BigdataResume extends Model ->whereYear('task_created_at', $year) ->count(); - // Non-business count (same logic as RequestAssignmentController) + // Non-business count: function_type NOT LIKE usaha AND (unit IS NULL OR unit <= 1) $non_business_count = PbgTask::where(function ($q) { $q->where(function ($q2) { $q2->where(function ($q3) { @@ -94,7 +110,14 @@ class BigdataResume extends Model }) ->orWhereNull('function_type'); }) - ->whereIn("status", PbgTaskStatus::getNonVerified()); + ->whereIn("status", PbgTaskStatus::getNonVerified()) + // Additional condition: unit IS NULL OR unit <= 1 + ->where(function ($q3) { + $q3->whereDoesntHave('pbg_task_detail', function ($q4) { + $q4->where('unit', '>', 1); + }) + ->orWhereDoesntHave('pbg_task_detail'); + }); }) ->where('is_valid', true) ->whereYear('task_created_at', $year) @@ -271,8 +294,6 @@ class BigdataResume extends Model ') ->value('total_count') ?? 0; - - // Debug: Check if there are non-verified tasks and their retribution data $debug_non_verified = PbgTask::whereIn('status', PbgTaskStatus::getNonVerified()) ->where('is_valid', true) diff --git a/resources/js/dashboards/bigdata.js b/resources/js/dashboards/bigdata.js index 53bf3f1..8e45b35 100644 --- a/resources/js/dashboards/bigdata.js +++ b/resources/js/dashboards/bigdata.js @@ -535,14 +535,16 @@ class BigData { }); } initChartNonBusinessDLH() { - document.querySelectorAll("#business-dlh-count").forEach((element) => { - const count = this.safeGet( - this.resumeBigData, - "business_dlh_count", - 0 - ); - element.innerText = `${count}`; - }); + document + .querySelectorAll("#non-business-dlh-count") + .forEach((element) => { + const count = this.safeGet( + this.resumeBigData, + "business_dlh_count", + 0 + ); + element.innerText = `${count}`; + }); } }