You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
car_common_app/lib/models/appointments_models/service_schedule_model.dart

171 lines
5.9 KiB
Dart

import 'package:mc_common_app/extensions/string_extensions.dart';
import 'package:mc_common_app/models/services/service_model.dart';
import 'package:mc_common_app/models/general/widgets_models.dart';
class CustomTimeDateSlotModel {
TimeSlotModel? date;
List<TimeSlotModel>? availableSlots;
CustomTimeDateSlotModel({this.date, this.availableSlots});
}
class ServiceAppointmentScheduleModel {
List<ServiceSlotList>? serviceSlotList;
List<ServiceModel>? servicesListInAppointment;
int? selectedDateIndex;
List<CustomTimeDateSlotModel>? customTimeDateSlotList;
CustomTimeDateSlotModel? selectedCustomTimeDateSlotModel;
double? amountToPay;
double? amountTotal;
double? amountRem;
int? appointmentType;
ServiceAppointmentScheduleModel({
this.serviceSlotList,
this.servicesListInAppointment,
this.selectedDateIndex,
this.customTimeDateSlotList,
this.selectedCustomTimeDateSlotModel,
this.amountToPay,
this.amountTotal,
this.amountRem,
this.appointmentType,
});
List<CustomTimeDateSlotModel> getFormattedDateTimeSlotPackage() {
List<CustomTimeDateSlotModel> customTimeDateSlotList = [];
for (var element in serviceSlotList!) {
if (!isAlreadyThere(element.slotDate!, customTimeDateSlotList)) {
customTimeDateSlotList.add(CustomTimeDateSlotModel(
date: TimeSlotModel(slotId: element.id!, isSelected: false, date: element.slotDate!, allowAppointment: (element.allowAppointment ?? 0) > (element.bookAppointment ?? 0)),
availableSlots: getAvailableSlotsByDate(element.slotDate!),
));
}
}
return customTimeDateSlotList;
}
List<TimeSlotModel>? getAvailableSlotsByDate(String date) {
List<TimeSlotModel> timeslots = [];
for (var element in serviceSlotList!) {
if (element.slotDate == date) {
timeslots.add(TimeSlotModel(slotId: element.id!, slot: element.startTime!, date: element.slotDate!, isSelected: false, allowAppointment: element.bookAppointment! < element.allowAppointment!));
}
}
return timeslots;
}
List<TimeSlotModel> getFormattedSlotTimes() {
var seenSlots = <TimeSlotModel>{};
var slotTimeData = serviceSlotList!
.where((slot) => seenSlots.add(TimeSlotModel(
slot: slot.startTime!,
slotId: slot.id!,
isSelected: false,
date: slot.slotDate!.toFormattedDateWithoutTime(),
)))
.toList();
List<TimeSlotModel> slotTime = [];
for (var element in slotTimeData) {
slotTime.add(TimeSlotModel(isSelected: false, slotId: element.id!, slot: element.startTime ?? "", date: element.slotDate!.toFormattedDateWithoutTime() ?? ""));
}
return slotTime;
}
bool isAlreadyThere(String dateToFind, List<CustomTimeDateSlotModel> slots) {
int index = slots.indexWhere((element) {
return element.date!.date == dateToFind;
});
if (index == -1) {
return false;
} else {
return true;
}
}
ServiceAppointmentScheduleModel.fromJson(Map<String, dynamic> json, {bool isForAppointment = false}) {
if (json['serviceSlotList'] != null) {
serviceSlotList = <ServiceSlotList>[];
json['serviceSlotList'].forEach((v) {
serviceSlotList!.add(ServiceSlotList.fromJson(v));
});
}
if (json['serviceList'] != null) {
servicesListInAppointment = <ServiceModel>[];
json['serviceList'].forEach((v) {
servicesListInAppointment!.add(ServiceModel.fromJson(v, isForAppointment: isForAppointment));
});
}
customTimeDateSlotList = getFormattedDateTimeSlotPackage();
amountToPay = json['amountToPay'];
selectedDateIndex = null;
amountTotal = json['amountTotal'];
amountRem = json['amountRem'];
appointmentType = json['appointmentType'];
}
}
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<String, dynamic> json) {
id = json['id'];
branchAppointmentScheduleID = json['branchAppointmentScheduleID'];
branchAppointmentSchedule = json['branchAppointmentSchedule'];
serviceProviderID = json['serviceProviderID'];
slotDate = (json['slotDate'] as String).toFormattedDateWithoutTime();
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'];
}
@override
String toString() {
return 'ServiceSlotList{id: $id, branchAppointmentScheduleID: $branchAppointmentScheduleID, branchAppointmentSchedule: $branchAppointmentSchedule, serviceProviderID: $serviceProviderID, slotDate: $slotDate, startTime: $startTime, endTime: $endTime, bookAppointment: $bookAppointment, allowAppointment: $allowAppointment, slotDurationMinute: $slotDurationMinute, appointmentType: $appointmentType, isActive: $isActive, createdBy: $createdBy, createdOn: $createdOn, modifiedBy: $modifiedBy, modifiedOn: $modifiedOn}';
}
}