fix shit
This commit is contained in:
@@ -564,10 +564,13 @@ func (r *TaskRepository) GetTaskStatistics(residenceIDs []uint) (*TaskStatistics
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count overdue tasks (due date < now, no completions)
|
// Count overdue tasks: due_date or next_due_date < now, and NOT completed
|
||||||
|
// A task is "completed" if next_due_date IS NULL AND has at least one completion
|
||||||
err = r.db.Model(&models.Task{}).
|
err = r.db.Model(&models.Task{}).
|
||||||
Where("residence_id IN ? AND is_cancelled = ? AND is_archived = ? AND due_date < ?", residenceIDs, false, false, now).
|
Where("residence_id IN ? AND is_cancelled = ? AND is_archived = ?", residenceIDs, false, false).
|
||||||
Where("id NOT IN (?)", r.db.Table("task_taskcompletion").Select("task_id")).
|
Where("(due_date < ? OR next_due_date < ?)", now, now).
|
||||||
|
// Exclude completed tasks: tasks with no next_due_date AND at least one completion
|
||||||
|
Where("NOT (next_due_date IS NULL AND EXISTS (SELECT 1 FROM task_taskcompletion tc WHERE tc.task_id = task_task.id))").
|
||||||
Count(&totalOverdue).Error
|
Count(&totalOverdue).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user