This commit is contained in:
@@ -125,18 +125,11 @@ const RouteEdit = () => {
|
|||||||
if (!validateRoute()) {
|
if (!validateRoute()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Merge attendance-based absences into the customer list for saving
|
// Do not persist scheduled-absence entries into route_customer_list.
|
||||||
const existingAbsentInRoute = (currentRoute?.route_customer_list || []).filter(
|
const filteredCustomerList = (newCustomerList || []).filter(
|
||||||
c => c?.customer_route_status === PERSONAL_ROUTE_STATUS.SCHEDULED_ABSENT
|
(customer) => customer?.customer_route_status !== PERSONAL_ROUTE_STATUS.SCHEDULED_ABSENT
|
||||||
);
|
);
|
||||||
const existingAbsentIds = new Set(existingAbsentInRoute.map(a => a.customer_id));
|
let data = Object.assign({}, currentRoute, {name: routeName, driver: newDriver, vehicle: newVehicle, type: newRouteType, route_customer_list: filteredCustomerList});
|
||||||
// Also exclude attendance-absent customers from newCustomerList (they shouldn't be in the main list)
|
|
||||||
const attendanceAbsentIds = new Set(attendanceAbsentCustomers.map(a => a.customer_id));
|
|
||||||
const filteredCustomerList = (newCustomerList || []).filter(c => !attendanceAbsentIds.has(c.customer_id));
|
|
||||||
// Add attendance-based absences that aren't already in existing absences
|
|
||||||
const newAttendanceAbsences = attendanceAbsentCustomers.filter(a => !existingAbsentIds.has(a.customer_id));
|
|
||||||
const fullCustomerList = [...filteredCustomerList, ...existingAbsentInRoute, ...newAttendanceAbsences];
|
|
||||||
let data = Object.assign({}, currentRoute, {name: routeName, driver: newDriver, vehicle: newVehicle, type: newRouteType, route_customer_list: fullCustomerList});
|
|
||||||
if (estimatedStartTime && estimatedStartTime !== '') {
|
if (estimatedStartTime && estimatedStartTime !== '') {
|
||||||
data = Object.assign({}, data, {estimated_start_time: combineDateAndTime(currentRoute.schedule_date, estimatedStartTime)})
|
data = Object.assign({}, data, {estimated_start_time: combineDateAndTime(currentRoute.schedule_date, estimatedStartTime)})
|
||||||
}
|
}
|
||||||
@@ -595,8 +588,7 @@ const RouteEdit = () => {
|
|||||||
currentRoute={currentRoute ? {
|
currentRoute={currentRoute ? {
|
||||||
...currentRoute,
|
...currentRoute,
|
||||||
route_customer_list: currentRoute.route_customer_list?.filter(
|
route_customer_list: currentRoute.route_customer_list?.filter(
|
||||||
customer => customer?.customer_route_status !== PERSONAL_ROUTE_STATUS.SCHEDULED_ABSENT &&
|
customer => customer?.customer_route_status !== PERSONAL_ROUTE_STATUS.SCHEDULED_ABSENT
|
||||||
!attendanceAbsentCustomers.some(a => a.customer_id === customer.customer_id)
|
|
||||||
) || []
|
) || []
|
||||||
} : undefined}
|
} : undefined}
|
||||||
setNewCustomerList={setNewCustomerList}
|
setNewCustomerList={setNewCustomerList}
|
||||||
|
|||||||
Reference in New Issue
Block a user