spending in home view working
This commit is contained in:
@@ -1,16 +1,16 @@
|
|||||||
# Basic Usage
|
# Basic Usage
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
ExampleConnector.instance.listRoleCategories().execute();
|
ExampleConnector.instance.listClientFeedbacks(listClientFeedbacksVariables).execute();
|
||||||
ExampleConnector.instance.getRoleCategoryById(getRoleCategoryByIdVariables).execute();
|
ExampleConnector.instance.getClientFeedbackById(getClientFeedbackByIdVariables).execute();
|
||||||
ExampleConnector.instance.getRoleCategoriesByCategory(getRoleCategoriesByCategoryVariables).execute();
|
ExampleConnector.instance.listClientFeedbacksByBusinessId(listClientFeedbacksByBusinessIdVariables).execute();
|
||||||
ExampleConnector.instance.createCourse(createCourseVariables).execute();
|
ExampleConnector.instance.listClientFeedbacksByVendorId(listClientFeedbacksByVendorIdVariables).execute();
|
||||||
ExampleConnector.instance.updateCourse(updateCourseVariables).execute();
|
ExampleConnector.instance.listClientFeedbacksByBusinessAndVendor(listClientFeedbacksByBusinessAndVendorVariables).execute();
|
||||||
ExampleConnector.instance.deleteCourse(deleteCourseVariables).execute();
|
ExampleConnector.instance.filterClientFeedbacks(filterClientFeedbacksVariables).execute();
|
||||||
ExampleConnector.instance.listAttireOptions().execute();
|
ExampleConnector.instance.listClientFeedbackRatingsByVendorId(listClientFeedbackRatingsByVendorIdVariables).execute();
|
||||||
ExampleConnector.instance.getAttireOptionById(getAttireOptionByIdVariables).execute();
|
ExampleConnector.instance.createStaffAvailabilityStats(createStaffAvailabilityStatsVariables).execute();
|
||||||
ExampleConnector.instance.filterAttireOptions(filterAttireOptionsVariables).execute();
|
ExampleConnector.instance.updateStaffAvailabilityStats(updateStaffAvailabilityStatsVariables).execute();
|
||||||
ExampleConnector.instance.listFaqDatas().execute();
|
ExampleConnector.instance.deleteStaffAvailabilityStats(deleteStaffAvailabilityStatsVariables).execute();
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -23,8 +23,8 @@ Optional fields can be discovered based on classes that have `Optional` object t
|
|||||||
This is an example of a mutation with an optional field:
|
This is an example of a mutation with an optional field:
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
await ExampleConnector.instance.updateWorkforce({ ... })
|
await ExampleConnector.instance.listWorkforceByStaffId({ ... })
|
||||||
.workforceNumber(...)
|
.offset(...)
|
||||||
.execute();
|
.execute();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,268 @@
|
|||||||
|
part of 'generated.dart';
|
||||||
|
|
||||||
|
class GetCompletedShiftsByBusinessIdVariablesBuilder {
|
||||||
|
String businessId;
|
||||||
|
Timestamp dateFrom;
|
||||||
|
Timestamp dateTo;
|
||||||
|
Optional<int> _offset = Optional.optional(nativeFromJson, nativeToJson);
|
||||||
|
Optional<int> _limit = Optional.optional(nativeFromJson, nativeToJson);
|
||||||
|
|
||||||
|
final FirebaseDataConnect _dataConnect; GetCompletedShiftsByBusinessIdVariablesBuilder offset(int? t) {
|
||||||
|
_offset.value = t;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
GetCompletedShiftsByBusinessIdVariablesBuilder limit(int? t) {
|
||||||
|
_limit.value = t;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetCompletedShiftsByBusinessIdVariablesBuilder(this._dataConnect, {required this.businessId,required this.dateFrom,required this.dateTo,});
|
||||||
|
Deserializer<GetCompletedShiftsByBusinessIdData> dataDeserializer = (dynamic json) => GetCompletedShiftsByBusinessIdData.fromJson(jsonDecode(json));
|
||||||
|
Serializer<GetCompletedShiftsByBusinessIdVariables> varsSerializer = (GetCompletedShiftsByBusinessIdVariables vars) => jsonEncode(vars.toJson());
|
||||||
|
Future<QueryResult<GetCompletedShiftsByBusinessIdData, GetCompletedShiftsByBusinessIdVariables>> execute() {
|
||||||
|
return ref().execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryRef<GetCompletedShiftsByBusinessIdData, GetCompletedShiftsByBusinessIdVariables> ref() {
|
||||||
|
GetCompletedShiftsByBusinessIdVariables vars= GetCompletedShiftsByBusinessIdVariables(businessId: businessId,dateFrom: dateFrom,dateTo: dateTo,offset: _offset,limit: _limit,);
|
||||||
|
return _dataConnect.query("getCompletedShiftsByBusinessId", dataDeserializer, varsSerializer, vars);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@immutable
|
||||||
|
class GetCompletedShiftsByBusinessIdShifts {
|
||||||
|
final String id;
|
||||||
|
final Timestamp? date;
|
||||||
|
final Timestamp? startTime;
|
||||||
|
final Timestamp? endTime;
|
||||||
|
final double? hours;
|
||||||
|
final double? cost;
|
||||||
|
final int? workersNeeded;
|
||||||
|
final int? filled;
|
||||||
|
final Timestamp? createdAt;
|
||||||
|
final GetCompletedShiftsByBusinessIdShiftsOrder order;
|
||||||
|
GetCompletedShiftsByBusinessIdShifts.fromJson(dynamic json):
|
||||||
|
|
||||||
|
id = nativeFromJson<String>(json['id']),
|
||||||
|
date = json['date'] == null ? null : Timestamp.fromJson(json['date']),
|
||||||
|
startTime = json['startTime'] == null ? null : Timestamp.fromJson(json['startTime']),
|
||||||
|
endTime = json['endTime'] == null ? null : Timestamp.fromJson(json['endTime']),
|
||||||
|
hours = json['hours'] == null ? null : nativeFromJson<double>(json['hours']),
|
||||||
|
cost = json['cost'] == null ? null : nativeFromJson<double>(json['cost']),
|
||||||
|
workersNeeded = json['workersNeeded'] == null ? null : nativeFromJson<int>(json['workersNeeded']),
|
||||||
|
filled = json['filled'] == null ? null : nativeFromJson<int>(json['filled']),
|
||||||
|
createdAt = json['createdAt'] == null ? null : Timestamp.fromJson(json['createdAt']),
|
||||||
|
order = GetCompletedShiftsByBusinessIdShiftsOrder.fromJson(json['order']);
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if(identical(this, other)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(other.runtimeType != runtimeType) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final GetCompletedShiftsByBusinessIdShifts otherTyped = other as GetCompletedShiftsByBusinessIdShifts;
|
||||||
|
return id == otherTyped.id &&
|
||||||
|
date == otherTyped.date &&
|
||||||
|
startTime == otherTyped.startTime &&
|
||||||
|
endTime == otherTyped.endTime &&
|
||||||
|
hours == otherTyped.hours &&
|
||||||
|
cost == otherTyped.cost &&
|
||||||
|
workersNeeded == otherTyped.workersNeeded &&
|
||||||
|
filled == otherTyped.filled &&
|
||||||
|
createdAt == otherTyped.createdAt &&
|
||||||
|
order == otherTyped.order;
|
||||||
|
|
||||||
|
}
|
||||||
|
@override
|
||||||
|
int get hashCode => Object.hashAll([id.hashCode, date.hashCode, startTime.hashCode, endTime.hashCode, hours.hashCode, cost.hashCode, workersNeeded.hashCode, filled.hashCode, createdAt.hashCode, order.hashCode]);
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
Map<String, dynamic> json = {};
|
||||||
|
json['id'] = nativeToJson<String>(id);
|
||||||
|
if (date != null) {
|
||||||
|
json['date'] = date!.toJson();
|
||||||
|
}
|
||||||
|
if (startTime != null) {
|
||||||
|
json['startTime'] = startTime!.toJson();
|
||||||
|
}
|
||||||
|
if (endTime != null) {
|
||||||
|
json['endTime'] = endTime!.toJson();
|
||||||
|
}
|
||||||
|
if (hours != null) {
|
||||||
|
json['hours'] = nativeToJson<double?>(hours);
|
||||||
|
}
|
||||||
|
if (cost != null) {
|
||||||
|
json['cost'] = nativeToJson<double?>(cost);
|
||||||
|
}
|
||||||
|
if (workersNeeded != null) {
|
||||||
|
json['workersNeeded'] = nativeToJson<int?>(workersNeeded);
|
||||||
|
}
|
||||||
|
if (filled != null) {
|
||||||
|
json['filled'] = nativeToJson<int?>(filled);
|
||||||
|
}
|
||||||
|
if (createdAt != null) {
|
||||||
|
json['createdAt'] = createdAt!.toJson();
|
||||||
|
}
|
||||||
|
json['order'] = order.toJson();
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetCompletedShiftsByBusinessIdShifts({
|
||||||
|
required this.id,
|
||||||
|
this.date,
|
||||||
|
this.startTime,
|
||||||
|
this.endTime,
|
||||||
|
this.hours,
|
||||||
|
this.cost,
|
||||||
|
this.workersNeeded,
|
||||||
|
this.filled,
|
||||||
|
this.createdAt,
|
||||||
|
required this.order,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@immutable
|
||||||
|
class GetCompletedShiftsByBusinessIdShiftsOrder {
|
||||||
|
final EnumValue<OrderStatus> status;
|
||||||
|
GetCompletedShiftsByBusinessIdShiftsOrder.fromJson(dynamic json):
|
||||||
|
|
||||||
|
status = orderStatusDeserializer(json['status']);
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if(identical(this, other)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(other.runtimeType != runtimeType) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final GetCompletedShiftsByBusinessIdShiftsOrder otherTyped = other as GetCompletedShiftsByBusinessIdShiftsOrder;
|
||||||
|
return status == otherTyped.status;
|
||||||
|
|
||||||
|
}
|
||||||
|
@override
|
||||||
|
int get hashCode => status.hashCode;
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
Map<String, dynamic> json = {};
|
||||||
|
json['status'] =
|
||||||
|
orderStatusSerializer(status)
|
||||||
|
;
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetCompletedShiftsByBusinessIdShiftsOrder({
|
||||||
|
required this.status,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@immutable
|
||||||
|
class GetCompletedShiftsByBusinessIdData {
|
||||||
|
final List<GetCompletedShiftsByBusinessIdShifts> shifts;
|
||||||
|
GetCompletedShiftsByBusinessIdData.fromJson(dynamic json):
|
||||||
|
|
||||||
|
shifts = (json['shifts'] as List<dynamic>)
|
||||||
|
.map((e) => GetCompletedShiftsByBusinessIdShifts.fromJson(e))
|
||||||
|
.toList();
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if(identical(this, other)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(other.runtimeType != runtimeType) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final GetCompletedShiftsByBusinessIdData otherTyped = other as GetCompletedShiftsByBusinessIdData;
|
||||||
|
return shifts == otherTyped.shifts;
|
||||||
|
|
||||||
|
}
|
||||||
|
@override
|
||||||
|
int get hashCode => shifts.hashCode;
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
Map<String, dynamic> json = {};
|
||||||
|
json['shifts'] = shifts.map((e) => e.toJson()).toList();
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetCompletedShiftsByBusinessIdData({
|
||||||
|
required this.shifts,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@immutable
|
||||||
|
class GetCompletedShiftsByBusinessIdVariables {
|
||||||
|
final String businessId;
|
||||||
|
final Timestamp dateFrom;
|
||||||
|
final Timestamp dateTo;
|
||||||
|
late final Optional<int>offset;
|
||||||
|
late final Optional<int>limit;
|
||||||
|
@Deprecated('fromJson is deprecated for Variable classes as they are no longer required for deserialization.')
|
||||||
|
GetCompletedShiftsByBusinessIdVariables.fromJson(Map<String, dynamic> json):
|
||||||
|
|
||||||
|
businessId = nativeFromJson<String>(json['businessId']),
|
||||||
|
dateFrom = Timestamp.fromJson(json['dateFrom']),
|
||||||
|
dateTo = Timestamp.fromJson(json['dateTo']) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
offset = Optional.optional(nativeFromJson, nativeToJson);
|
||||||
|
offset.value = json['offset'] == null ? null : nativeFromJson<int>(json['offset']);
|
||||||
|
|
||||||
|
|
||||||
|
limit = Optional.optional(nativeFromJson, nativeToJson);
|
||||||
|
limit.value = json['limit'] == null ? null : nativeFromJson<int>(json['limit']);
|
||||||
|
|
||||||
|
}
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if(identical(this, other)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(other.runtimeType != runtimeType) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final GetCompletedShiftsByBusinessIdVariables otherTyped = other as GetCompletedShiftsByBusinessIdVariables;
|
||||||
|
return businessId == otherTyped.businessId &&
|
||||||
|
dateFrom == otherTyped.dateFrom &&
|
||||||
|
dateTo == otherTyped.dateTo &&
|
||||||
|
offset == otherTyped.offset &&
|
||||||
|
limit == otherTyped.limit;
|
||||||
|
|
||||||
|
}
|
||||||
|
@override
|
||||||
|
int get hashCode => Object.hashAll([businessId.hashCode, dateFrom.hashCode, dateTo.hashCode, offset.hashCode, limit.hashCode]);
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
Map<String, dynamic> json = {};
|
||||||
|
json['businessId'] = nativeToJson<String>(businessId);
|
||||||
|
json['dateFrom'] = dateFrom.toJson();
|
||||||
|
json['dateTo'] = dateTo.toJson();
|
||||||
|
if(offset.state == OptionalState.set) {
|
||||||
|
json['offset'] = offset.toJson();
|
||||||
|
}
|
||||||
|
if(limit.state == OptionalState.set) {
|
||||||
|
json['limit'] = limit.toJson();
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetCompletedShiftsByBusinessIdVariables({
|
||||||
|
required this.businessId,
|
||||||
|
required this.dateFrom,
|
||||||
|
required this.dateTo,
|
||||||
|
required this.offset,
|
||||||
|
required this.limit,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@@ -18,13 +18,64 @@ class HomeRepositoryImpl implements HomeRepositoryInterface {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<HomeDashboardData> getDashboardData() async {
|
Future<HomeDashboardData> getDashboardData() async {
|
||||||
final HomeDashboardData baseData = await _mock.getDashboardData();
|
|
||||||
final String? businessId = ClientSessionStore.instance.session?.business?.id;
|
final String? businessId = ClientSessionStore.instance.session?.business?.id;
|
||||||
if (businessId == null || businessId.isEmpty) {
|
if (businessId == null || businessId.isEmpty) {
|
||||||
return baseData;
|
return const HomeDashboardData(
|
||||||
|
weeklySpending: 0,
|
||||||
|
next7DaysSpending: 0,
|
||||||
|
weeklyShifts: 0,
|
||||||
|
next7DaysScheduled: 0,
|
||||||
|
totalNeeded: 0,
|
||||||
|
totalFilled: 0,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final DateTime now = DateTime.now();
|
final DateTime now = DateTime.now();
|
||||||
|
final int daysFromMonday = now.weekday - DateTime.monday;
|
||||||
|
final DateTime monday =
|
||||||
|
DateTime(now.year, now.month, now.day).subtract(Duration(days: daysFromMonday));
|
||||||
|
final DateTime weekRangeStart = DateTime(monday.year, monday.month, monday.day);
|
||||||
|
final DateTime weekRangeEnd =
|
||||||
|
DateTime(monday.year, monday.month, monday.day + 13, 23, 59, 59, 999);
|
||||||
|
final fdc.QueryResult<
|
||||||
|
GetCompletedShiftsByBusinessIdData,
|
||||||
|
GetCompletedShiftsByBusinessIdVariables> completedResult =
|
||||||
|
await _dataConnect
|
||||||
|
.getCompletedShiftsByBusinessId(
|
||||||
|
businessId: businessId,
|
||||||
|
dateFrom: _toTimestamp(weekRangeStart),
|
||||||
|
dateTo: _toTimestamp(weekRangeEnd),
|
||||||
|
)
|
||||||
|
.execute();
|
||||||
|
print(
|
||||||
|
'Home spending: businessId=$businessId dateFrom=${weekRangeStart.toIso8601String()} '
|
||||||
|
'dateTo=${weekRangeEnd.toIso8601String()} shifts=${completedResult.data.shifts.length}',
|
||||||
|
);
|
||||||
|
|
||||||
|
double weeklySpending = 0.0;
|
||||||
|
double next7DaysSpending = 0.0;
|
||||||
|
int weeklyShifts = 0;
|
||||||
|
int next7DaysScheduled = 0;
|
||||||
|
for (final GetCompletedShiftsByBusinessIdShifts shift
|
||||||
|
in completedResult.data.shifts) {
|
||||||
|
final DateTime? shiftDate = shift.date?.toDateTime();
|
||||||
|
if (shiftDate == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final int offset = shiftDate.difference(weekRangeStart).inDays;
|
||||||
|
if (offset < 0 || offset > 13) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final double cost = shift.cost ?? 0.0;
|
||||||
|
if (offset <= 6) {
|
||||||
|
weeklySpending += cost;
|
||||||
|
weeklyShifts += 1;
|
||||||
|
} else {
|
||||||
|
next7DaysSpending += cost;
|
||||||
|
next7DaysScheduled += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final DateTime start = DateTime(now.year, now.month, now.day);
|
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 DateTime end = DateTime(now.year, now.month, now.day, 23, 59, 59, 999);
|
||||||
|
|
||||||
@@ -48,10 +99,10 @@ class HomeRepositoryImpl implements HomeRepositoryInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return HomeDashboardData(
|
return HomeDashboardData(
|
||||||
weeklySpending: baseData.weeklySpending,
|
weeklySpending: weeklySpending,
|
||||||
next7DaysSpending: baseData.next7DaysSpending,
|
next7DaysSpending: next7DaysSpending,
|
||||||
weeklyShifts: baseData.weeklyShifts,
|
weeklyShifts: weeklyShifts,
|
||||||
next7DaysScheduled: baseData.next7DaysScheduled,
|
next7DaysScheduled: next7DaysScheduled,
|
||||||
totalNeeded: totalNeeded,
|
totalNeeded: totalNeeded,
|
||||||
totalFilled: totalFilled,
|
totalFilled: totalFilled,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -464,3 +464,63 @@ query listShiftRolesByBusinessAndDatesSummary(
|
|||||||
role { id name }
|
role { id name }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
# BUSINESS: GET COMPLETED SHIFTS FOR A BUSINESS (via order.businessId)
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
#for spending insights in home view
|
||||||
|
query getCompletedShiftsByBusinessId(
|
||||||
|
$businessId: UUID!
|
||||||
|
$dateFrom: Timestamp!
|
||||||
|
$dateTo: Timestamp!
|
||||||
|
$offset: Int
|
||||||
|
$limit: Int
|
||||||
|
) @auth(level: USER) {
|
||||||
|
shifts(
|
||||||
|
where: {
|
||||||
|
order: { businessId: { eq: $businessId } }
|
||||||
|
status: {in: [IN_PROGRESS, CONFIRMED, COMPLETED, OPEN]}
|
||||||
|
date: { ge: $dateFrom, le: $dateTo }
|
||||||
|
}
|
||||||
|
offset: $offset
|
||||||
|
limit: $limit
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
#title
|
||||||
|
|
||||||
|
#orderId
|
||||||
|
|
||||||
|
date
|
||||||
|
startTime
|
||||||
|
endTime
|
||||||
|
hours
|
||||||
|
cost
|
||||||
|
|
||||||
|
#location
|
||||||
|
#locationAddress
|
||||||
|
#latitude
|
||||||
|
#longitude
|
||||||
|
#description
|
||||||
|
|
||||||
|
#status
|
||||||
|
workersNeeded
|
||||||
|
filled
|
||||||
|
#filledAt
|
||||||
|
|
||||||
|
#managers
|
||||||
|
#durationDays
|
||||||
|
|
||||||
|
createdAt
|
||||||
|
|
||||||
|
order {
|
||||||
|
#id
|
||||||
|
#eventName
|
||||||
|
status
|
||||||
|
#orderType
|
||||||
|
#businessId
|
||||||
|
#vendorId
|
||||||
|
#business { id businessName email contactName }
|
||||||
|
#vendor { id companyName }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user