solving the problem of bad information in live today
This commit is contained in:
@@ -26,10 +26,11 @@ class CoverageDashboard extends StatelessWidget {
|
||||
final int needed = s['workersNeeded'] as int? ?? 0;
|
||||
final int confirmed = s['filled'] as int? ?? 0;
|
||||
final double rate = s['hourlyRate'] as double? ?? 0.0;
|
||||
final double hours = s['hours'] as double? ?? 0.0;
|
||||
|
||||
totalNeeded += needed;
|
||||
totalConfirmed += confirmed;
|
||||
todayCost += rate * 8 * confirmed;
|
||||
todayCost += rate * hours;
|
||||
}
|
||||
|
||||
final int coveragePercent = totalNeeded > 0
|
||||
@@ -104,15 +105,13 @@ class CoverageDashboard extends StatelessWidget {
|
||||
icon: UiIcons.warning,
|
||||
isWarning: unfilledPositions > 0,
|
||||
),
|
||||
if (lateWorkersCount > 0) ...<Widget>[
|
||||
const SizedBox(height: UiConstants.space2),
|
||||
_StatusCard(
|
||||
label: 'Running Late',
|
||||
value: '$lateWorkersCount',
|
||||
icon: UiIcons.error,
|
||||
isError: true,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: UiConstants.space2),
|
||||
_StatusCard(
|
||||
label: 'Running Late',
|
||||
value: '$lateWorkersCount',
|
||||
icon: UiIcons.error,
|
||||
isError: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -122,7 +121,7 @@ class CoverageDashboard extends StatelessWidget {
|
||||
children: <Widget>[
|
||||
_StatusCard(
|
||||
label: 'Checked In',
|
||||
value: '$checkedInCount/$totalConfirmed',
|
||||
value: '$checkedInCount/$totalNeeded',
|
||||
icon: UiIcons.success,
|
||||
isInfo: true,
|
||||
),
|
||||
|
||||
@@ -31,6 +31,15 @@ class _LiveActivityWidgetState extends State<LiveActivityWidget> {
|
||||
final DateTime now = DateTime.now();
|
||||
final DateTime start = DateTime(now.year, now.month, now.day);
|
||||
final DateTime end = DateTime(now.year, now.month, now.day, 23, 59, 59, 999);
|
||||
final fdc.QueryResult<dc.ListShiftRolesByBusinessAndDateRangeData,
|
||||
dc.ListShiftRolesByBusinessAndDateRangeVariables> shiftRolesResult =
|
||||
await dc.ExampleConnector.instance
|
||||
.listShiftRolesByBusinessAndDateRange(
|
||||
businessId: businessId,
|
||||
start: _toTimestamp(start),
|
||||
end: _toTimestamp(end),
|
||||
)
|
||||
.execute();
|
||||
final fdc.QueryResult<dc.ListStaffsApplicationsByBusinessForDayData,
|
||||
dc.ListStaffsApplicationsByBusinessForDayVariables> result =
|
||||
await dc.ExampleConnector.instance
|
||||
@@ -41,33 +50,20 @@ class _LiveActivityWidgetState extends State<LiveActivityWidget> {
|
||||
)
|
||||
.execute();
|
||||
|
||||
if (result.data.applications.isEmpty) {
|
||||
if (shiftRolesResult.data.shiftRoles.isEmpty &&
|
||||
result.data.applications.isEmpty) {
|
||||
return _LiveActivityData.empty();
|
||||
}
|
||||
|
||||
final Map<String, _LiveShiftAggregate> aggregates =
|
||||
<String, _LiveShiftAggregate>{};
|
||||
for (final dc.ListStaffsApplicationsByBusinessForDayApplications app
|
||||
in result.data.applications) {
|
||||
final String key = '${app.shiftId}:${app.roleId}';
|
||||
final _LiveShiftAggregate aggregate = aggregates[key] ??
|
||||
_LiveShiftAggregate(
|
||||
workersNeeded: app.shiftRole.count,
|
||||
assigned: app.shiftRole.assigned ?? 0,
|
||||
cost: app.shiftRole.shift.cost ?? 0,
|
||||
);
|
||||
aggregates[key] = aggregate;
|
||||
}
|
||||
|
||||
int totalNeeded = 0;
|
||||
int totalAssigned = 0;
|
||||
double totalCost = 0;
|
||||
for (final _LiveShiftAggregate aggregate in aggregates.values) {
|
||||
totalNeeded += aggregate.workersNeeded;
|
||||
totalAssigned += aggregate.assigned;
|
||||
totalCost += aggregate.cost;
|
||||
for (final dc.ListShiftRolesByBusinessAndDateRangeShiftRoles shiftRole
|
||||
in shiftRolesResult.data.shiftRoles) {
|
||||
totalNeeded += shiftRole.count;
|
||||
totalCost += shiftRole.totalValue ?? 0;
|
||||
}
|
||||
|
||||
final int totalAssigned = result.data.applications.length;
|
||||
int lateCount = 0;
|
||||
int checkedInCount = 0;
|
||||
for (final dc.ListStaffsApplicationsByBusinessForDayApplications app
|
||||
@@ -137,9 +133,8 @@ class _LiveActivityWidgetState extends State<LiveActivityWidget> {
|
||||
<String, Object>{
|
||||
'workersNeeded': data.totalNeeded,
|
||||
'filled': data.totalAssigned,
|
||||
'hourlyRate': data.totalAssigned == 0
|
||||
? 0.0
|
||||
: data.totalCost / data.totalAssigned,
|
||||
'hourlyRate': 1.0,
|
||||
'hours': data.totalCost,
|
||||
'status': 'OPEN',
|
||||
'date': DateTime.now().toIso8601String().split('T')[0],
|
||||
},
|
||||
@@ -193,15 +188,3 @@ class _LiveActivityData {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _LiveShiftAggregate {
|
||||
_LiveShiftAggregate({
|
||||
required this.workersNeeded,
|
||||
required this.assigned,
|
||||
required this.cost,
|
||||
});
|
||||
|
||||
final int workersNeeded;
|
||||
final int assigned;
|
||||
final double cost;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user