diff --git a/src/views/dashboards/departmentDashboard/modules/goals/DepartmentGoals.vue b/src/views/dashboards/departmentDashboard/modules/goals/DepartmentGoals.vue index 5b089b08..3724e585 100644 --- a/src/views/dashboards/departmentDashboard/modules/goals/DepartmentGoals.vue +++ b/src/views/dashboards/departmentDashboard/modules/goals/DepartmentGoals.vue @@ -16,6 +16,10 @@ const loading = ref(true); const activeTab = ref('active'); const toast = useToast(); +const timeframe = ref('all'); + +const currentTimeframe = computed(() => timeframe.value); + const fetchGoals = async () => { loading.value = true; try { @@ -79,10 +83,18 @@ const getGoalIconColor = (type) => { } }; -const getGoalProgress = (goal) => { +const getGoalProgress = (goal, deptId = null) => { + const key = currentTimeframe.value; // Use the .value to divided by .target and multiply by 100 - const value = parseFloat(goal.progress?.all?.count); - const target = parseFloat(goal.progress?.all?.target); + if (deptId && goal.progress?.departmental_distribution?.[deptId]?.[key]) { + const deptValue = parseFloat(goal.progress.departmental_distribution[deptId][key].count); + const deptTarget = getDailyGoalDepartmentTarget(goal, deptId, true); + if (isNaN(deptValue) || isNaN(deptTarget) || deptTarget === 0) return 0; + const deptProgress = (deptValue / deptTarget) * 100; + return Math.min(Math.round(deptProgress), 100); + } + const value = parseFloat(goal.progress?.[key]?.count); + const target = parseFloat(goal.progress?.[key]?.target); if (isNaN(value) || isNaN(target) || target === 0) return 0; const progress = (value / target) * 100; return Math.min(Math.round(progress), 100); @@ -162,9 +174,13 @@ const getDailyGoalDepartmentTarget = (goal, deptId, progressUntilNow = false) => return isNaN(x) ? 0 : x; }; const getEvenSplitPerDay = () => { - if (daysTotal === 0) return goal.criteria.target; // Avoid division by zero + if (daysTotal === 0) return goal.progress?.departmental_distribution?.[deptId]?.[currentTimeframe]?.target || 0; const deptCount = Math.max(1, goal.departments.length || 1); - return (normalizeInt(goal.criteria.target) / deptCount) / daysTotal; + // If the department has a custom daily target, use that, otherwise use the even split + if (hasOverride) { + return normalizeInt(overrides[String(deptId)]); + } + return (normalizeInt(goal.progress?.departmental_distribution?.[deptId]?.[currentTimeframe]?.target) || (normalizeInt(goal.criteria.target) / deptCount)) / daysTotal; }; const dailyTarget = hasOverride ? normalizeInt(overrides[String(deptId)]) : getEvenSplitPerDay(); @@ -255,6 +271,36 @@ const getGoalApplicableDaysInPeriod = (goal, fromDate, toDate) => { + +