diff --git a/Layout/default/VueViews/WorkorderCompanyPWA.php b/Layout/default/VueViews/WorkorderCompanyPWA.php index 78ff29bdc..edf027ab9 100644 --- a/Layout/default/VueViews/WorkorderCompanyPWA.php +++ b/Layout/default/VueViews/WorkorderCompanyPWA.php @@ -145,7 +145,55 @@ ); } - return filtered.sort((a,b) => (a.deadlineDate || 0) - (b.deadlineDate || 0)); + const getStatusRank = (status) => { + switch (status) { + // Priority 0: Active and scheduled, sorted by appointment date + case 'scheduled': + case 'civil_engineering_completed': + return 0; + // Priority 1: New/Assigned tasks, sorted by deadline + case 'assigned': + case 'new': + case 'problem_solved': + return 1; + // Priority 2: Tasks with issues, sorted by deadline + case 'intervention_required': + case 'correction_requested': + case 'civil_engineering_required': + return 2; + // Priority 3: Finished tasks, sorted by deadline + case 'documented': + case 'completed': + return 3; + // Priority 4: Cancelled tasks + case 'cancelled': + return 4; + default: + return 99; // Fallback for any other status + } + }; + + return filtered.sort((a, b) => { + const rankA = getStatusRank(a.status); + const rankB = getStatusRank(b.status); + + if (rankA !== rankB) { + return rankA - rankB; + } + + // For the highest priority group, sort by appointment date + if (rankA === 0) { + const dateA = a.appointmentDate || Infinity; + const dateB = b.appointmentDate || Infinity; + if (dateA === dateB) { + return (a.deadlineDate || Infinity) - (b.deadlineDate || Infinity); + } + return dateA - dateB; + } + + // For all other groups, sort by deadline + return (a.deadlineDate || Infinity) - (b.deadlineDate || Infinity); + }); }); @@ -386,7 +434,7 @@
-
@@ -577,13 +625,12 @@