fix non business where unit is more than one

This commit is contained in:
arifal
2025-08-19 19:02:54 +07:00
parent 1b084ed485
commit 1bcd2023da
3 changed files with 168 additions and 37 deletions

View File

@@ -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)

View File

@@ -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)