diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 7ebeb78..b1727c9 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -50,6 +50,7 @@ class ApiConsts { static String ServiceProviderService_Get = "${baseUrlServices}api/ServiceProviders/ServiceProviderService_Get"; static String BranchesAndServices = "${baseUrlServices}api/ServiceProviders/ServiceProviderDetail_Get"; static String GetAllNearBranches = "${baseUrlServices}api/ServiceProviders/ServiceProviderBranchDetail_Get"; + static String GetServiceItemAppointmentScheduleSlots = "${baseUrlServices}api/ServiceProviders/ServiceItemAppointmentScheduleSlots_Get"; //Appointment APIs static String serviceProvidersAppointmentGet = "${baseUrlServices}api/ServiceProviders/ServiceProvidersAppointment_Get"; diff --git a/lib/models/schedule_model.dart b/lib/models/schedule_model.dart index 6676083..47c13e6 100644 --- a/lib/models/schedule_model.dart +++ b/lib/models/schedule_model.dart @@ -4,6 +4,8 @@ import 'dart:convert'; +import 'package:mc_common_app/models/services/service_model.dart'; + Schedule scheduleFromJson(String str) => Schedule.fromJson(json.decode(str)); String scheduleToJson(Schedule data) => json.encode(data.toJson()); @@ -53,7 +55,8 @@ class ScheduleData { final String? latitude; final String? longitude; final List? weeklyOffDays; - final List? scheduleServices; + final List? scheduleServices; + final List? selectedServices; String branchId; ScheduleData({ @@ -72,6 +75,7 @@ class ScheduleData { this.longitude, this.weeklyOffDays, this.scheduleServices, + this.selectedServices, this.branchId = "", }); @@ -91,7 +95,8 @@ class ScheduleData { latitude: json["latitude"], longitude: json["longitude"], weeklyOffDays: json["weeklyOffDays"] == null ? [] : List.from(json["weeklyOffDays"]!.map((x) => WeeklyOffDay.fromJson(x))), - scheduleServices: json["scheduleServices"] == null ? [] : List.from(json["scheduleServices"]!.map((x) => ScheduleService.fromJson(x))), + scheduleServices: json["scheduleServices"] == null ? [] : List.from(json["scheduleServices"]!.map((x) => ServiceModel.fromJson(x))), + selectedServices: [], ); Map toJson() => @@ -111,33 +116,14 @@ class ScheduleData { "longitude": longitude, "scheduleServices": scheduleServices == null ? [] : List.from(scheduleServices!.map((x) => x.toJson())), }; -} - -class ScheduleService { - final int? providerServiceId; - // final int? branchScheduleGroupServiceID; - final String? providerServiceName; - ScheduleService({ - this.providerServiceId, - // this.branchScheduleGroupServiceID, - this.providerServiceName, - }); - - factory ScheduleService.fromJson(Map json) => - ScheduleService( - providerServiceId: json["providerServiceID"], - // branchScheduleGroupServiceID: json["branchScheduleGroupServiceID"], - providerServiceName: json["providerServiceName"], - ); - - Map toJson() => - { - "providerServiceID": providerServiceId, - "providerServiceName": providerServiceName, - }; + @override + String toString() { + return 'ScheduleData{id: $id, scheduleName: $scheduleName, serviceProviderBranchId: $serviceProviderBranchId, fromDate: $fromDate, toDate: $toDate, startTime: $startTime, endTime: $endTime, slotDurationMinute: $slotDurationMinute, perSlotAppointment: $perSlotAppointment, branchName: $branchName, address: $address, latitude: $latitude, longitude: $longitude, weeklyOffDays: $weeklyOffDays, scheduleServices: $scheduleServices, branchId: $branchId}'; + } } + class WeeklyOffDay { final int? id; final int? dayNumber; diff --git a/lib/models/service_schedule_model.dart b/lib/models/service_schedule_model.dart new file mode 100644 index 0000000..b8081f5 --- /dev/null +++ b/lib/models/service_schedule_model.dart @@ -0,0 +1,180 @@ +import 'package:mc_common_app/extensions/string_extensions.dart'; +import 'package:mc_common_app/models/services/item_model.dart'; +import 'package:mc_common_app/models/widgets_models.dart'; + +class ServiceAppointmentScheduleModel { + List? serviceSlotList; + List? serviceItemList; + String? selectedDate; + String? selectedTimeSlot; + List? availableDates; + List? availableTimeSlots; + double? amountToPay; + double? amountTotal; + double? amountRem; + + ServiceAppointmentScheduleModel({ + this.serviceSlotList, + this.serviceItemList, + this.selectedDate, + this.selectedTimeSlot, + this.availableDates, + this.availableTimeSlots, + this.amountToPay, + this.amountTotal, + this.amountRem, + }); + + List getFormattedSlotTimes() { + var seenSlots = {}; + + var slotTimeData = serviceSlotList! + .where((slot) => seenSlots.add(TimeSlotModel( + slot: slot.startTime!, + slotId: slot.id!, + isSelected: false, + ))) + .toList(); + List slotTime = []; + for (var element in slotTimeData) { + slotTime.add(TimeSlotModel(isSelected: false, slotId: element.id!, slot: element.slotDate ?? "")); + } + + return slotTime; + } + + List getFormattedSlotDates() { + var seenDates = {}; + + var slotDatesData = serviceSlotList! + .where((slot) => seenDates.add(TimeSlotModel( + slot: slot.slotDate!, + slotId: slot.id!, + isSelected: false, + ))) + .toList(); + List slotDates = []; + for (var element in slotDatesData) { + slotDates.add(TimeSlotModel(isSelected: false, slotId: element.id!, slot: element.slotDate!.toFormattedDateWithoutTime() ?? "")); + } + + return slotDates; + } + + //TODO: I WILL START FROM HERE; I NEED TO ONLY PICK THE DISTINCT DATES FROM THE RESPONSE AND THEN BASED ON THE DATE SELECTION I WILL PICK THEIR SLOTS. + //TODO: AFTER THAT, I WILL + + ServiceAppointmentScheduleModel.fromJson(Map json) { + if (json['serviceSlotList'] != null) { + serviceSlotList = []; + json['serviceSlotList'].forEach((v) { + serviceSlotList!.add(ServiceSlotList.fromJson(v)); + }); + } + if (json['serviceItemList'] != null) { + serviceItemList = []; + json['serviceItemList'].forEach((v) { + serviceItemList!.add(ItemData.fromJson(v)); + }); + } + + amountToPay = json['amountToPay']; + selectedDate = ''; + selectedTimeSlot = ''; + availableDates = getFormattedSlotDates(); + availableTimeSlots = getFormattedSlotTimes(); + amountTotal = json['amountTotal']; + amountRem = json['amountRem']; + } + + Map toJson() { + final Map data = {}; + if (serviceSlotList != null) { + data['serviceSlotList'] = serviceSlotList!.map((v) => v.toJson()).toList(); + } + if (serviceItemList != null) { + data['serviceItemList'] = serviceItemList!.map((v) => v.toJson()).toList(); + } + data['amountToPay'] = amountToPay; + data['amountTotal'] = amountTotal; + data['amountRem'] = amountRem; + return data; + } +} + +class ServiceSlotList { + int? id; + int? branchAppointmentScheduleID; + String? branchAppointmentSchedule; + int? serviceProviderID; + String? slotDate; + String? startTime; + String? endTime; + int? bookAppointment; + int? allowAppointment; + int? slotDurationMinute; + int? appointmentType; + bool? isActive; + int? createdBy; + String? createdOn; + int? modifiedBy; + String? modifiedOn; + + ServiceSlotList( + {this.id, + this.branchAppointmentScheduleID, + this.branchAppointmentSchedule, + this.serviceProviderID, + this.slotDate, + this.startTime, + this.endTime, + this.bookAppointment, + this.allowAppointment, + this.slotDurationMinute, + this.appointmentType, + this.isActive, + this.createdBy, + this.createdOn, + this.modifiedBy, + this.modifiedOn}); + + ServiceSlotList.fromJson(Map json) { + id = json['id']; + branchAppointmentScheduleID = json['branchAppointmentScheduleID']; + branchAppointmentSchedule = json['branchAppointmentSchedule']; + serviceProviderID = json['serviceProviderID']; + slotDate = json['slotDate']; + startTime = json['startTime']; + endTime = json['endTime']; + bookAppointment = json['bookAppointment']; + allowAppointment = json['allowAppointment']; + slotDurationMinute = json['slotDurationMinute']; + appointmentType = json['appointmentType']; + isActive = json['isActive']; + createdBy = json['createdBy']; + createdOn = json['createdOn']; + modifiedBy = json['modifiedBy']; + modifiedOn = json['modifiedOn']; + } + + Map toJson() { + final Map data = {}; + data['id'] = id; + data['branchAppointmentScheduleID'] = branchAppointmentScheduleID; + data['branchAppointmentSchedule'] = branchAppointmentSchedule; + data['serviceProviderID'] = serviceProviderID; + data['slotDate'] = slotDate; + data['startTime'] = startTime; + data['endTime'] = endTime; + data['bookAppointment'] = bookAppointment; + data['allowAppointment'] = allowAppointment; + data['slotDurationMinute'] = slotDurationMinute; + data['appointmentType'] = appointmentType; + data['isActive'] = isActive; + data['createdBy'] = createdBy; + data['createdOn'] = createdOn; + data['modifiedBy'] = modifiedBy; + data['modifiedOn'] = modifiedOn; + return data; + } +} diff --git a/lib/models/services/item_model.dart b/lib/models/services/item_model.dart index 11c88c2..2ea572c 100644 --- a/lib/models/services/item_model.dart +++ b/lib/models/services/item_model.dart @@ -49,6 +49,7 @@ class ItemData { final bool? isAllowAppointment; final bool? isAppointmentCompanyLoc; final bool? isAppointmentCustomerLoc; + final double? appointmentPricePercentage; bool? isUpdateOrSelected; ItemData({ @@ -64,6 +65,7 @@ class ItemData { this.isAllowAppointment, this.isAppointmentCompanyLoc, this.isAppointmentCustomerLoc, + this.appointmentPricePercentage, this.isUpdateOrSelected, }); diff --git a/lib/widgets/common_widgets/provider_details_card.dart b/lib/widgets/common_widgets/provider_details_card.dart index f8106fa..169f1c2 100644 --- a/lib/widgets/common_widgets/provider_details_card.dart +++ b/lib/widgets/common_widgets/provider_details_card.dart @@ -66,7 +66,7 @@ class ProviderDetailsCard extends StatelessWidget { title.toText(fontSize: 16, isBold: true), Row( children: [ - (LocaleKeys.location.tr() + ":").toText(color: MyColors.lightTextColor, fontSize: 12), + ("${LocaleKeys.location.tr()}:").toText(color: MyColors.lightTextColor, fontSize: 12), 4.width, providerLocation.toText(fontSize: 12, isBold: true), ], @@ -74,7 +74,7 @@ class ProviderDetailsCard extends StatelessWidget { if (providerName != null) Row( children: [ - (LocaleKeys.providers.tr() + ":").toText(color: MyColors.lightTextColor, fontSize: 12), + ("${LocaleKeys.providers.tr()}:").toText(color: MyColors.lightTextColor, fontSize: 12), 4.width, providerName!.toText(fontSize: 12, isBold: true), ],