refactor: Update reorder suggestions to fetch and display completed orders with aggregated totals instead of individual shift roles.

This commit is contained in:
Achintha Isuru
2026-02-21 22:44:26 -05:00
parent 2c6cd9cd45
commit c5e48ffbc6
4 changed files with 160 additions and 33 deletions

View File

@@ -148,31 +148,59 @@ class HomeRepositoryImpl implements HomeRepositoryInterface {
final DateTime start = now.subtract(const Duration(days: 30));
final QueryResult<
dc.ListShiftRolesByBusinessDateRangeCompletedOrdersData,
dc.ListShiftRolesByBusinessDateRangeCompletedOrdersVariables
dc.ListCompletedOrdersByBusinessAndDateRangeData,
dc.ListCompletedOrdersByBusinessAndDateRangeVariables
>
result = await _service.connector
.listShiftRolesByBusinessDateRangeCompletedOrders(
.listCompletedOrdersByBusinessAndDateRange(
businessId: businessId,
start: _service.toTimestamp(start),
end: _service.toTimestamp(now),
)
.execute();
return result.data.shiftRoles.map((
dc.ListShiftRolesByBusinessDateRangeCompletedOrdersShiftRoles shiftRole,
return result.data.orders.map((
dc.ListCompletedOrdersByBusinessAndDateRangeOrders order,
) {
final String location =
shiftRole.shift.location ?? shiftRole.shift.locationAddress ?? '';
final String type = shiftRole.shift.order.orderType.stringValue;
final String title =
order.eventName ??
(order.shifts_on_order.isNotEmpty
? order.shifts_on_order[0].title
: 'Order');
final String location = order.shifts_on_order.isNotEmpty
? (order.shifts_on_order[0].location ??
order.shifts_on_order[0].locationAddress ??
'')
: '';
int totalWorkers = 0;
double totalHours = 0;
double totalRate = 0;
int roleCount = 0;
for (final dc.ListCompletedOrdersByBusinessAndDateRangeOrdersShiftsOnOrder
shift
in order.shifts_on_order) {
for (final dc.ListCompletedOrdersByBusinessAndDateRangeOrdersShiftsOnOrderShiftRolesOnShift
role
in shift.shiftRoles_on_shift) {
totalWorkers += role.count;
totalHours += role.hours ?? 0;
totalRate += role.role.costPerHour;
roleCount++;
}
}
return ReorderItem(
orderId: shiftRole.shift.order.id,
title: '${shiftRole.role.name} - ${shiftRole.shift.title}',
orderId: order.id,
title: title,
location: location,
hourlyRate: shiftRole.role.costPerHour,
hours: shiftRole.hours ?? 0,
workers: shiftRole.count,
type: type,
totalCost: order.total ?? 0.0,
workers: totalWorkers,
type: order.orderType.stringValue,
hourlyRate: roleCount > 0 ? totalRate / roleCount : 0.0,
hours: totalHours,
);
}).toList();
});

View File

@@ -5,7 +5,6 @@ import 'package:krow_domain/krow_domain.dart';
/// A widget that allows clients to reorder recent shifts.
class ReorderWidget extends StatelessWidget {
/// Creates a [ReorderWidget].
const ReorderWidget({
super.key,
@@ -13,6 +12,7 @@ class ReorderWidget extends StatelessWidget {
required this.onReorderPressed,
this.subtitle,
});
/// Recent completed orders for reorder.
final List<ReorderItem> orders;
@@ -55,8 +55,7 @@ class ReorderWidget extends StatelessWidget {
const SizedBox(width: UiConstants.space3),
itemBuilder: (BuildContext context, int index) {
final ReorderItem order = recentOrders[index];
final double totalCost =
order.hourlyRate * order.hours * order.workers;
final double totalCost = order.totalCost;
return Container(
width: 260,
@@ -163,6 +162,7 @@ class ReorderWidget extends StatelessWidget {
'hours': order.hours,
'workers': order.workers,
'type': order.type,
'totalCost': order.totalCost,
}),
),
],
@@ -177,7 +177,6 @@ class ReorderWidget extends StatelessWidget {
}
class _Badge extends StatelessWidget {
const _Badge({
required this.icon,
required this.text,