|
|
|
|
@ -39,10 +39,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
final ProviderRepo providerRepo;
|
|
|
|
|
final AppointmentRepo scheduleRepo;
|
|
|
|
|
|
|
|
|
|
AppointmentsVM({required this.commonServices,
|
|
|
|
|
required this.scheduleRepo,
|
|
|
|
|
required this.providerRepo,
|
|
|
|
|
required this.commonRepo});
|
|
|
|
|
AppointmentsVM({required this.commonServices, required this.scheduleRepo, required this.providerRepo, required this.commonRepo});
|
|
|
|
|
|
|
|
|
|
bool isFetchingLists = false;
|
|
|
|
|
int selectedBranch = 0;
|
|
|
|
|
@ -68,8 +65,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
List<ServiceAppointmentScheduleModel> serviceAppointmentScheduleList = [];
|
|
|
|
|
|
|
|
|
|
bool ifItemAlreadySelected(int id) {
|
|
|
|
|
int indexFound = allSelectedItemsInAppointments
|
|
|
|
|
.indexWhere((element) => element.id == id);
|
|
|
|
|
int indexFound = allSelectedItemsInAppointments.indexWhere((element) => element.id == id);
|
|
|
|
|
if (indexFound != -1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
@ -80,22 +76,16 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
setupProviderAppointmentFilter() {
|
|
|
|
|
appointmentsFilterOptions.clear();
|
|
|
|
|
appointmentsFilterOptions.add(
|
|
|
|
|
FilterListModel(id: 0, title: "All Appointments", isSelected: true));
|
|
|
|
|
appointmentsFilterOptions
|
|
|
|
|
.add(FilterListModel(id: 6, title: "Upcoming", isSelected: false));
|
|
|
|
|
appointmentsFilterOptions
|
|
|
|
|
.add(FilterListModel(id: 3, title: "Arrived", isSelected: false));
|
|
|
|
|
appointmentsFilterOptions
|
|
|
|
|
.add(FilterListModel(id: 7, title: "In Progress", isSelected: false));
|
|
|
|
|
appointmentsFilterOptions
|
|
|
|
|
.add(FilterListModel(id: 8, title: "Completed", isSelected: false));
|
|
|
|
|
appointmentsFilterOptions.add(FilterListModel(id: 0, title: "All Appointments", isSelected: true));
|
|
|
|
|
appointmentsFilterOptions.add(FilterListModel(id: 6, title: "Upcoming", isSelected: false));
|
|
|
|
|
appointmentsFilterOptions.add(FilterListModel(id: 3, title: "Arrived", isSelected: false));
|
|
|
|
|
appointmentsFilterOptions.add(FilterListModel(id: 7, title: "In Progress", isSelected: false));
|
|
|
|
|
appointmentsFilterOptions.add(FilterListModel(id: 8, title: "Completed", isSelected: false));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> onItemsSelectedInService() async {
|
|
|
|
|
if (currentServiceSelection != null) {
|
|
|
|
|
int index = servicesInCurrentAppointment.indexWhere((element) =>
|
|
|
|
|
element.serviceId == currentServiceSelection!.serviceId!);
|
|
|
|
|
int index = servicesInCurrentAppointment.indexWhere((element) => element.serviceId == currentServiceSelection!.serviceId!);
|
|
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
double totalPrice = 0.0;
|
|
|
|
|
@ -116,14 +106,12 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
bool isSuccess = false;
|
|
|
|
|
List<int> appointmentIdsList = [];
|
|
|
|
|
try {
|
|
|
|
|
GenericRespModel genericRespModel =
|
|
|
|
|
await scheduleRepo.createServiceAppointment(
|
|
|
|
|
GenericRespModel genericRespModel = await scheduleRepo.createServiceAppointment(
|
|
|
|
|
schedules: serviceAppointmentScheduleList,
|
|
|
|
|
serviceProviderID: selectedBranchModel!.serviceProviderId ?? 0,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (genericRespModel.messageStatus == 2 ||
|
|
|
|
|
genericRespModel.data == null) {
|
|
|
|
|
if (genericRespModel.messageStatus == 2 || genericRespModel.data == null) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.showToast("${genericRespModel.message.toString()}");
|
|
|
|
|
return;
|
|
|
|
|
@ -141,17 +129,13 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.read<DashboardVmCustomer>().onNavbarTapped(1);
|
|
|
|
|
applyFilterOnAppointmentsVM(
|
|
|
|
|
appointmentStatusEnum: AppointmentStatusEnum.booked);
|
|
|
|
|
applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.booked);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
resetAfterBookingAppointment();
|
|
|
|
|
if (isSuccess) {
|
|
|
|
|
if (amountToPayForAppointment > 0) {
|
|
|
|
|
context
|
|
|
|
|
.read<PaymentVM>()
|
|
|
|
|
.updateAppointmentIdsForPayment(ids: appointmentIdsList);
|
|
|
|
|
navigateWithName(context, AppRoutes.paymentMethodsView,
|
|
|
|
|
arguments: PaymentTypes.appointment);
|
|
|
|
|
context.read<PaymentVM>().updateAppointmentIdsForPayment(ids: appointmentIdsList);
|
|
|
|
|
navigateWithName(context, AppRoutes.paymentMethodsView, arguments: PaymentTypes.appointment);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast("Your appointment has been booked successfully!");
|
|
|
|
|
getMyAppointments();
|
|
|
|
|
@ -163,36 +147,28 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> onConfirmAppointmentPressed(
|
|
|
|
|
{required BuildContext context, required appointmentId}) async {
|
|
|
|
|
context
|
|
|
|
|
.read<PaymentVM>()
|
|
|
|
|
.updateAppointmentIdsForPayment(ids: [appointmentId]);
|
|
|
|
|
navigateWithName(context, AppRoutes.paymentMethodsView,
|
|
|
|
|
arguments: PaymentTypes.appointment);
|
|
|
|
|
Future<void> onConfirmAppointmentPressed({required BuildContext context, required appointmentId}) async {
|
|
|
|
|
context.read<PaymentVM>().updateAppointmentIdsForPayment(ids: [appointmentId]);
|
|
|
|
|
navigateWithName(context, AppRoutes.paymentMethodsView, arguments: PaymentTypes.appointment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> onCancelAppointmentPressed({required BuildContext context,
|
|
|
|
|
required AppointmentListModel appointmentListModel}) async {
|
|
|
|
|
Future<void> onCancelAppointmentPressed({required BuildContext context, required AppointmentListModel appointmentListModel}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
GenericRespModel genericRespModel =
|
|
|
|
|
await scheduleRepo.cancelOrRescheduleServiceAppointment(
|
|
|
|
|
GenericRespModel genericRespModel = await scheduleRepo.cancelOrRescheduleServiceAppointment(
|
|
|
|
|
serviceAppointmentID: appointmentListModel.id ?? 0,
|
|
|
|
|
serviceSlotID: appointmentListModel.serviceSlotID ?? 0,
|
|
|
|
|
appointmentScheduleAction: 2, // 1 for Reschedule and 2 for Cancel
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (genericRespModel.messageStatus == 2 ||
|
|
|
|
|
genericRespModel.data == null) {
|
|
|
|
|
if (genericRespModel.messageStatus == 2 || genericRespModel.data == null) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.showToast("${genericRespModel.message.toString()}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (genericRespModel.data == 1) {
|
|
|
|
|
context.read<DashboardVmCustomer>().onNavbarTapped(1);
|
|
|
|
|
applyFilterOnAppointmentsVM(
|
|
|
|
|
appointmentStatusEnum: AppointmentStatusEnum.cancelled);
|
|
|
|
|
applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.cancelled);
|
|
|
|
|
Utils.showToast("${genericRespModel.message.toString()}");
|
|
|
|
|
await getMyAppointments();
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
@ -223,8 +199,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SelectionModel branchSelectedCategoryId =
|
|
|
|
|
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
SelectionModel branchSelectedCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
|
|
|
|
|
void updateProviderCategoryId(SelectionModel id) {
|
|
|
|
|
branchSelectedCategoryId = id;
|
|
|
|
|
@ -243,30 +218,23 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
void updateBranchServiceId(SelectionModel id) async {
|
|
|
|
|
branchSelectedServiceId = id;
|
|
|
|
|
currentServiceSelection = branchServices.firstWhere(
|
|
|
|
|
(element) => element.serviceProviderServiceId == id.selectedId);
|
|
|
|
|
currentServiceSelection = branchServices.firstWhere((element) => element.serviceProviderServiceId == id.selectedId);
|
|
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void removeServiceInCurrentAppointment(int index) {
|
|
|
|
|
int serviceId = servicesInCurrentAppointment
|
|
|
|
|
.elementAt(index)
|
|
|
|
|
.serviceProviderServiceId ??
|
|
|
|
|
-1;
|
|
|
|
|
allSelectedItemsInAppointments.removeWhere(
|
|
|
|
|
(element) => element.serviceProviderServiceId == serviceId);
|
|
|
|
|
int serviceId = servicesInCurrentAppointment.elementAt(index).serviceProviderServiceId ?? -1;
|
|
|
|
|
allSelectedItemsInAppointments.removeWhere((element) => element.serviceProviderServiceId == serviceId);
|
|
|
|
|
servicesInCurrentAppointment.removeAt(index);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resetCategorySelectionBottomSheet() {
|
|
|
|
|
selectedSubServicesCounter = 0;
|
|
|
|
|
branchSelectedCategoryId =
|
|
|
|
|
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
branchSelectedCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
isHomeTapped = false;
|
|
|
|
|
branchSelectedServiceId =
|
|
|
|
|
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
branchSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
currentServiceSelection = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -281,32 +249,24 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
populateAppointmentsFilterList() async {
|
|
|
|
|
appointmentsFilterOptions.clear();
|
|
|
|
|
|
|
|
|
|
myAppointmentsEnum = await commonRepo.getEnumTypeValues(
|
|
|
|
|
enumTypeID: 13); //TODO: 13 is to get Appointments Filter Enums
|
|
|
|
|
myAppointmentsEnum = await commonRepo.getEnumTypeValues(enumTypeID: 13); //TODO: 13 is to get Appointments Filter Enums
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < myAppointmentsEnum.length; i++) {
|
|
|
|
|
appointmentsFilterOptions.add(FilterListModel(
|
|
|
|
|
title: myAppointmentsEnum[i].enumValueStr,
|
|
|
|
|
isSelected: false,
|
|
|
|
|
id: myAppointmentsEnum[i].enumValue));
|
|
|
|
|
appointmentsFilterOptions.add(FilterListModel(title: myAppointmentsEnum[i].enumValueStr, isSelected: false, id: myAppointmentsEnum[i].enumValue));
|
|
|
|
|
}
|
|
|
|
|
appointmentsFilterOptions.insert(
|
|
|
|
|
0, FilterListModel(title: "All Appointments", isSelected: true, id: 0));
|
|
|
|
|
appointmentsFilterOptions.insert(0, FilterListModel(title: "All Appointments", isSelected: true, id: 0));
|
|
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
applyFilterOnAppointmentsVM(
|
|
|
|
|
{required AppointmentStatusEnum appointmentStatusEnum,
|
|
|
|
|
bool isNeedCustomerFilter = false}) {
|
|
|
|
|
applyFilterOnAppointmentsVM({required AppointmentStatusEnum appointmentStatusEnum, bool isNeedCustomerFilter = false}) {
|
|
|
|
|
if (appointmentsFilterOptions.isEmpty) return;
|
|
|
|
|
for (var value in appointmentsFilterOptions) {
|
|
|
|
|
value.isSelected = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
appointmentsFilterOptions.forEach((element) {
|
|
|
|
|
if (element.id ==
|
|
|
|
|
appointmentStatusEnum.getIdFromAppointmentStatusEnum()) {
|
|
|
|
|
if (element.id == appointmentStatusEnum.getIdFromAppointmentStatusEnum()) {
|
|
|
|
|
element.isSelected = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
@ -321,11 +281,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
myFilteredAppointments = myAppointments
|
|
|
|
|
.where((element) =>
|
|
|
|
|
element.appointmentStatusID! ==
|
|
|
|
|
appointmentStatusEnum.getIdFromAppointmentStatusEnum())
|
|
|
|
|
.toList();
|
|
|
|
|
myFilteredAppointments = myAppointments.where((element) => element.appointmentStatusID! == appointmentStatusEnum.getIdFromAppointmentStatusEnum()).toList();
|
|
|
|
|
if (isNeedCustomerFilter) findAppointmentsBasedOnCustomers();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
@ -341,9 +297,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
// Create a list of CustomerData instances
|
|
|
|
|
myFilteredAppointments2 = uniqueCustomerIDs.map((id) {
|
|
|
|
|
List<AppointmentListModel> list = myFilteredAppointments
|
|
|
|
|
.where((item) => item.customerID == id)
|
|
|
|
|
.toList();
|
|
|
|
|
List<AppointmentListModel> list = myFilteredAppointments.where((item) => item.customerID == id).toList();
|
|
|
|
|
AppointmentListModel model = list.first;
|
|
|
|
|
model.customerAppointmentList = list;
|
|
|
|
|
return model;
|
|
|
|
|
@ -368,10 +322,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
myAppointments = await commonRepo.getMyAppointments();
|
|
|
|
|
myFilteredAppointments = myAppointments;
|
|
|
|
|
myUpComingAppointments = myAppointments
|
|
|
|
|
.where((element) =>
|
|
|
|
|
element.appointmentStatusEnum == AppointmentStatusEnum.booked)
|
|
|
|
|
.toList();
|
|
|
|
|
myUpComingAppointments = myAppointments.where((element) => element.appointmentStatusEnum == AppointmentStatusEnum.confirmed).toList();
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
// applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.allAppointments);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
@ -379,9 +330,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
AppointmentSlots? appointmentSlots;
|
|
|
|
|
|
|
|
|
|
Future<void> getAppointmentSlotsInfo({required Map<String, dynamic> map,
|
|
|
|
|
required BuildContext context,
|
|
|
|
|
bool isNeedToRebuild = false}) async {
|
|
|
|
|
Future<void> getAppointmentSlotsInfo({required Map<String, dynamic> map, required BuildContext context, bool isNeedToRebuild = false}) async {
|
|
|
|
|
if (isNeedToRebuild) setState(ViewState.busy);
|
|
|
|
|
try {
|
|
|
|
|
MResponse genericRespModel = await scheduleRepo.getAppointmentSlots(map);
|
|
|
|
|
@ -395,8 +344,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> getProviderMyAppointments(Map<String, dynamic> map,
|
|
|
|
|
{bool isNeedToRebuild = false}) async {
|
|
|
|
|
Future<void> getProviderMyAppointments(Map<String, dynamic> map, {bool isNeedToRebuild = false}) async {
|
|
|
|
|
if (isNeedToRebuild) setState(ViewState.busy);
|
|
|
|
|
|
|
|
|
|
myAppointments = await scheduleRepo.getMyAppointments(map);
|
|
|
|
|
@ -406,9 +354,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
// element.appointmentStatusEnum == AppointmentStatusEnum.booked)
|
|
|
|
|
// .toList();
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
applyFilterOnAppointmentsVM(
|
|
|
|
|
appointmentStatusEnum: AppointmentStatusEnum.allAppointments,
|
|
|
|
|
isNeedCustomerFilter: true);
|
|
|
|
|
applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.allAppointments, isNeedCustomerFilter: true);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -418,10 +364,10 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateAppointmentStatus(Map<String, dynamic> map,{bool isNeedToRebuild = false}) async {
|
|
|
|
|
updateAppointmentStatus(Map<String, dynamic> map, {bool isNeedToRebuild = false}) async {
|
|
|
|
|
if (isNeedToRebuild) setState(ViewState.busy);
|
|
|
|
|
try {
|
|
|
|
|
MResponse genericRespModel = await scheduleRepo.updateAppointmentStatus(map);
|
|
|
|
|
MResponse genericRespModel = await scheduleRepo.updateAppointmentStatus(map);
|
|
|
|
|
|
|
|
|
|
if (genericRespModel.messageStatus == 1) {
|
|
|
|
|
Utils.showToast("appointment status updated");
|
|
|
|
|
@ -433,10 +379,10 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateAppointmentPaymentStatus(Map<String, dynamic> map,{bool isNeedToRebuild = false}) async {
|
|
|
|
|
updateAppointmentPaymentStatus(Map<String, dynamic> map, {bool isNeedToRebuild = false}) async {
|
|
|
|
|
if (isNeedToRebuild) setState(ViewState.busy);
|
|
|
|
|
try {
|
|
|
|
|
MResponse genericRespModel = await scheduleRepo.updateAppointmentPaymentStatus(map);
|
|
|
|
|
MResponse genericRespModel = await scheduleRepo.updateAppointmentPaymentStatus(map);
|
|
|
|
|
|
|
|
|
|
if (genericRespModel.messageStatus == 1) {
|
|
|
|
|
Utils.showToast("payment status updated");
|
|
|
|
|
@ -448,55 +394,32 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateSelectedAppointmentDate(
|
|
|
|
|
{required int dateIndex, required int scheduleIndex}) {
|
|
|
|
|
for (var element in serviceAppointmentScheduleList[scheduleIndex]
|
|
|
|
|
.customTimeDateSlotList!) {
|
|
|
|
|
updateSelectedAppointmentDate({required int dateIndex, required int scheduleIndex}) {
|
|
|
|
|
for (var element in serviceAppointmentScheduleList[scheduleIndex].customTimeDateSlotList!) {
|
|
|
|
|
element.date!.isSelected = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex]
|
|
|
|
|
.customTimeDateSlotList![dateIndex]
|
|
|
|
|
.date!
|
|
|
|
|
.isSelected = true;
|
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex].customTimeDateSlotList![dateIndex].date!.isSelected = true;
|
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex].selectedDateIndex = dateIndex;
|
|
|
|
|
final date = TimeSlotModel(
|
|
|
|
|
date: serviceAppointmentScheduleList[scheduleIndex]
|
|
|
|
|
.customTimeDateSlotList![dateIndex]
|
|
|
|
|
.date!
|
|
|
|
|
.date,
|
|
|
|
|
slotId: serviceAppointmentScheduleList[scheduleIndex]
|
|
|
|
|
.customTimeDateSlotList![dateIndex]
|
|
|
|
|
.date!
|
|
|
|
|
.slotId,
|
|
|
|
|
date: serviceAppointmentScheduleList[scheduleIndex].customTimeDateSlotList![dateIndex].date!.date,
|
|
|
|
|
slotId: serviceAppointmentScheduleList[scheduleIndex].customTimeDateSlotList![dateIndex].date!.slotId,
|
|
|
|
|
isSelected: true,
|
|
|
|
|
slot: "",
|
|
|
|
|
);
|
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex]
|
|
|
|
|
.selectedCustomTimeDateSlotModel = CustomTimeDateSlotModel(date: date);
|
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex].selectedCustomTimeDateSlotModel = CustomTimeDateSlotModel(date: date);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateSelectedAppointmentSlotByDate(
|
|
|
|
|
{required int scheduleIndex, required int slotIndex}) {
|
|
|
|
|
for (var element in serviceAppointmentScheduleList[scheduleIndex]
|
|
|
|
|
.customTimeDateSlotList!) {
|
|
|
|
|
updateSelectedAppointmentSlotByDate({required int scheduleIndex, required int slotIndex}) {
|
|
|
|
|
for (var element in serviceAppointmentScheduleList[scheduleIndex].customTimeDateSlotList!) {
|
|
|
|
|
for (var element in element.availableSlots!) {
|
|
|
|
|
element.isSelected = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int index =
|
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex].selectedDateIndex!;
|
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex]
|
|
|
|
|
.customTimeDateSlotList![index]
|
|
|
|
|
.availableSlots![slotIndex]
|
|
|
|
|
.isSelected = true;
|
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex]
|
|
|
|
|
.selectedCustomTimeDateSlotModel!
|
|
|
|
|
.availableSlots =
|
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex]
|
|
|
|
|
.customTimeDateSlotList![index]
|
|
|
|
|
.availableSlots!;
|
|
|
|
|
int index = serviceAppointmentScheduleList[scheduleIndex].selectedDateIndex!;
|
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex].customTimeDateSlotList![index].availableSlots![slotIndex].isSelected = true;
|
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex].selectedCustomTimeDateSlotModel!.availableSlots = serviceAppointmentScheduleList[scheduleIndex].customTimeDateSlotList![index].availableSlots!;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -510,9 +433,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
int selectedSubServicesCounter = 0;
|
|
|
|
|
|
|
|
|
|
onItemUpdateOrSelected(int index, bool selected, int itemId) {
|
|
|
|
|
int serviceIndex = servicesInCurrentAppointment.indexWhere(
|
|
|
|
|
(element) =>
|
|
|
|
|
element.serviceId == currentServiceSelection!.serviceId!);
|
|
|
|
|
int serviceIndex = servicesInCurrentAppointment.indexWhere((element) => element.serviceId == currentServiceSelection!.serviceId!);
|
|
|
|
|
// print("servicesInCurrentAppointment: ${servicesInCurrentAppointment.length}");
|
|
|
|
|
// if (serviceIndex == -1) {
|
|
|
|
|
// return;
|
|
|
|
|
@ -527,28 +448,19 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
allSelectedItemsInAppointments.add(serviceItemsFromApi[index]);
|
|
|
|
|
for (var element in allSelectedItemsInAppointments) {
|
|
|
|
|
if (!ifItemAlreadySelected(element.id!)) {
|
|
|
|
|
servicesInCurrentAppointment[serviceIndex]
|
|
|
|
|
.serviceItems!
|
|
|
|
|
.add(serviceItemsFromApi[index]);
|
|
|
|
|
servicesInCurrentAppointment[serviceIndex].serviceItems!.add(serviceItemsFromApi[index]);
|
|
|
|
|
servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice =
|
|
|
|
|
servicesInCurrentAppointment[serviceIndex]
|
|
|
|
|
.currentTotalServicePrice +
|
|
|
|
|
double.parse((serviceItemsFromApi[index].price) ?? "0.0");
|
|
|
|
|
servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice + double.parse((serviceItemsFromApi[index].price) ?? "0.0");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!selected) {
|
|
|
|
|
selectedSubServicesCounter = selectedSubServicesCounter - 1;
|
|
|
|
|
currentServiceSelection!.serviceItems!
|
|
|
|
|
.removeWhere((element) => element.id == itemId);
|
|
|
|
|
allSelectedItemsInAppointments
|
|
|
|
|
.removeWhere((element) => element.id == itemId);
|
|
|
|
|
currentServiceSelection!.serviceItems!.removeWhere((element) => element.id == itemId);
|
|
|
|
|
allSelectedItemsInAppointments.removeWhere((element) => element.id == itemId);
|
|
|
|
|
servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice =
|
|
|
|
|
servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice -
|
|
|
|
|
double.parse((serviceItemsFromApi[index].price) ?? "0.0");
|
|
|
|
|
servicesInCurrentAppointment[serviceIndex]
|
|
|
|
|
.serviceItems!
|
|
|
|
|
.removeWhere((element) => element.id == itemId);
|
|
|
|
|
servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice - double.parse((serviceItemsFromApi[index].price) ?? "0.0");
|
|
|
|
|
servicesInCurrentAppointment[serviceIndex].serviceItems!.removeWhere((element) => element.id == itemId);
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
@ -604,8 +516,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
String pickHomeLocationError = "";
|
|
|
|
|
String selectSubServicesError = "";
|
|
|
|
|
|
|
|
|
|
SelectionModel branchSelectedServiceId =
|
|
|
|
|
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
SelectionModel branchSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
|
|
|
|
|
bool isCategoryAlreadyPresent(int id) {
|
|
|
|
|
final contain = branchCategories.where((element) => element.id == id);
|
|
|
|
|
@ -618,16 +529,14 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
void getBranchCategories() async {
|
|
|
|
|
for (var value in selectedBranchModel!.branchServices!) {
|
|
|
|
|
if (!isCategoryAlreadyPresent(value.categoryId!)) {
|
|
|
|
|
branchCategories
|
|
|
|
|
.add(DropValue(value.categoryId!, value.categoryName!, ""));
|
|
|
|
|
branchCategories.add(DropValue(value.categoryId!, value.categoryName!, ""));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getBranchServices({required int categoryId}) async {
|
|
|
|
|
branchSelectedServiceId =
|
|
|
|
|
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
branchSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
isHomeTapped = false;
|
|
|
|
|
pickedHomeLocation = "";
|
|
|
|
|
pickHomeLocationError = "";
|
|
|
|
|
@ -640,9 +549,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<ServiceModel> getFilteredBranchServices({required int categoryId}) {
|
|
|
|
|
List<ServiceModel> filteredServices = selectedBranchModel!.branchServices!
|
|
|
|
|
.where((element) => element.categoryId == categoryId)
|
|
|
|
|
.toList();
|
|
|
|
|
List<ServiceModel> filteredServices = selectedBranchModel!.branchServices!.where((element) => element.categoryId == categoryId).toList();
|
|
|
|
|
return filteredServices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -684,8 +591,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
return totalPrice.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void openTheAddServiceBottomSheet(BuildContext context,
|
|
|
|
|
AppointmentsVM appointmentsVM) {
|
|
|
|
|
void openTheAddServiceBottomSheet(BuildContext context, AppointmentsVM appointmentsVM) {
|
|
|
|
|
showModalBottomSheet(
|
|
|
|
|
context: context,
|
|
|
|
|
isScrollControlled: true,
|
|
|
|
|
@ -696,8 +602,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void priceBreakDownClicked(BuildContext context,
|
|
|
|
|
ServiceModel selectedService) {
|
|
|
|
|
void priceBreakDownClicked(BuildContext context, ServiceModel selectedService) {
|
|
|
|
|
showModalBottomSheet(
|
|
|
|
|
context: context,
|
|
|
|
|
isScrollControlled: true,
|
|
|
|
|
@ -713,27 +618,19 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
Column(
|
|
|
|
|
children: List.generate(
|
|
|
|
|
selectedService.serviceItems!.length,
|
|
|
|
|
(index) =>
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
"${selectedService.serviceItems![index].name}"
|
|
|
|
|
.toText(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
color: MyColors.lightTextColor,
|
|
|
|
|
isBold: true),
|
|
|
|
|
"${selectedService.serviceItems![index]
|
|
|
|
|
.price} SAR"
|
|
|
|
|
.toText(fontSize: 12, isBold: true),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
(index) => Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
"${selectedService.serviceItems![index].name}".toText(fontSize: 12, color: MyColors.lightTextColor, isBold: true),
|
|
|
|
|
"${selectedService.serviceItems![index].price} SAR".toText(fontSize: 12, isBold: true),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
"${selectedService.currentTotalServicePrice} SAR"
|
|
|
|
|
.toText(fontSize: 16, isBold: true),
|
|
|
|
|
"${selectedService.currentTotalServicePrice} SAR".toText(fontSize: 16, isBold: true),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
if (selectedService.isHomeSelected) ...[
|
|
|
|
|
@ -742,20 +639,15 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
"${totalKms}km ".toText(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
color: MyColors.lightTextColor,
|
|
|
|
|
isBold: true),
|
|
|
|
|
"${selectedService.rangePricePerKm} x $totalKms"
|
|
|
|
|
.toText(fontSize: 12, isBold: true),
|
|
|
|
|
"${totalKms}km ".toText(fontSize: 12, color: MyColors.lightTextColor, isBold: true),
|
|
|
|
|
"${selectedService.rangePricePerKm} x $totalKms".toText(fontSize: 12, isBold: true),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
8.height,
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
"${selectedService.rangePricePerKm ?? 0 * totalKms} SAR"
|
|
|
|
|
.toText(fontSize: 16, isBold: true),
|
|
|
|
|
"${selectedService.rangePricePerKm ?? 0 * totalKms} SAR".toText(fontSize: 16, isBold: true),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
@ -768,18 +660,11 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
(selectedService.isHomeSelected
|
|
|
|
|
? "${(selectedService.currentTotalServicePrice) +
|
|
|
|
|
(double.parse((selectedService.rangePricePerKm ??
|
|
|
|
|
"0.0")) * totalKms)}"
|
|
|
|
|
: "${selectedService.currentTotalServicePrice}")
|
|
|
|
|
? "${(selectedService.currentTotalServicePrice) + (double.parse((selectedService.rangePricePerKm ?? "0.0")) * totalKms)}"
|
|
|
|
|
: "${selectedService.currentTotalServicePrice}")
|
|
|
|
|
.toText(fontSize: 29, isBold: true),
|
|
|
|
|
2.width,
|
|
|
|
|
"SAR"
|
|
|
|
|
.toText(
|
|
|
|
|
color: MyColors.lightTextColor,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
isBold: true)
|
|
|
|
|
.paddingOnly(bottom: 5),
|
|
|
|
|
"SAR".toText(color: MyColors.lightTextColor, fontSize: 16, isBold: true).paddingOnly(bottom: 5),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
@ -799,8 +684,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
isValidated = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (schedule.selectedCustomTimeDateSlotModel!.date == null ||
|
|
|
|
|
!schedule.selectedCustomTimeDateSlotModel!.date!.isSelected) {
|
|
|
|
|
if (schedule.selectedCustomTimeDateSlotModel!.date == null || !schedule.selectedCustomTimeDateSlotModel!.date!.isSelected) {
|
|
|
|
|
isValidated = false;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
@ -808,9 +692,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
isValidated = false;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
TimeSlotModel slot = schedule
|
|
|
|
|
.selectedCustomTimeDateSlotModel!.availableSlots!
|
|
|
|
|
.firstWhere((element) => element.isSelected);
|
|
|
|
|
TimeSlotModel slot = schedule.selectedCustomTimeDateSlotModel!.availableSlots!.firstWhere((element) => element.isSelected);
|
|
|
|
|
if (slot.date.isNotEmpty) {
|
|
|
|
|
isValidated = true;
|
|
|
|
|
break;
|
|
|
|
|
@ -819,8 +701,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isValidated) {
|
|
|
|
|
Utils.showToast(
|
|
|
|
|
"You must select appointment time for each schedule's appointment.");
|
|
|
|
|
Utils.showToast("You must select appointment time for each schedule's appointment.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
navigateWithName(context, AppRoutes.reviewAppointmentView);
|
|
|
|
|
@ -839,36 +720,30 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serviceAppointmentScheduleList =
|
|
|
|
|
await scheduleRepo.mergeServiceIntoAvailableSchedules(
|
|
|
|
|
serviceAppointmentScheduleList = await scheduleRepo.mergeServiceIntoAvailableSchedules(
|
|
|
|
|
serviceItemIdsForHome: serviceItemIdsForHome,
|
|
|
|
|
serviceItemIdsForWorkshop: serviceItemIdsForWorkshop,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (serviceAppointmentScheduleList.isEmpty) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.showToast(
|
|
|
|
|
"There are no available appointments for selected Items.");
|
|
|
|
|
Utils.showToast("There are no available appointments for selected Items.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
totalAmount = 0.0;
|
|
|
|
|
amountToPayForAppointment = 0.0;
|
|
|
|
|
for (var schedule in serviceAppointmentScheduleList) {
|
|
|
|
|
amountToPayForAppointment =
|
|
|
|
|
amountToPayForAppointment + (schedule.amountToPay ?? 0.0);
|
|
|
|
|
amountToPayForAppointment = amountToPayForAppointment + (schedule.amountToPay ?? 0.0);
|
|
|
|
|
totalAmount = totalAmount + (schedule.amountTotal ?? 0.0);
|
|
|
|
|
}
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
|
|
|
|
|
navigateWithName(context, AppRoutes.bookAppointmenSchedulesView,
|
|
|
|
|
arguments: ScreenArgumentsForAppointmentDetailPage(
|
|
|
|
|
routeFlag: 1, appointmentId: 0)); // 1 For Creating an Appointment
|
|
|
|
|
navigateWithName(context, AppRoutes.bookAppointmenSchedulesView, arguments: ScreenArgumentsForAppointmentDetailPage(routeFlag: 1, appointmentId: 0)); // 1 For Creating an Appointment
|
|
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> onRescheduleAppointmentPressed({required BuildContext context,
|
|
|
|
|
required AppointmentListModel appointmentListModel}) async {
|
|
|
|
|
Future<void> onRescheduleAppointmentPressed({required BuildContext context, required AppointmentListModel appointmentListModel}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
|
|
|
|
|
List<String> serviceItemIdsForHome = [];
|
|
|
|
|
@ -885,16 +760,14 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serviceAppointmentScheduleList =
|
|
|
|
|
await scheduleRepo.mergeServiceIntoAvailableSchedules(
|
|
|
|
|
serviceAppointmentScheduleList = await scheduleRepo.mergeServiceIntoAvailableSchedules(
|
|
|
|
|
serviceItemIdsForHome: serviceItemIdsForHome,
|
|
|
|
|
serviceItemIdsForWorkshop: serviceItemIdsForWorkshop,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (serviceAppointmentScheduleList.isEmpty) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.showToast(
|
|
|
|
|
"There are no available appointments for selected Items.");
|
|
|
|
|
Utils.showToast("There are no available appointments for selected Items.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
@ -902,36 +775,29 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
navigateWithName(
|
|
|
|
|
context,
|
|
|
|
|
AppRoutes.bookAppointmenSchedulesView,
|
|
|
|
|
arguments: ScreenArgumentsForAppointmentDetailPage(
|
|
|
|
|
routeFlag: 2, appointmentId: appointmentListModel.id ?? 0),
|
|
|
|
|
arguments: ScreenArgumentsForAppointmentDetailPage(routeFlag: 2, appointmentId: appointmentListModel.id ?? 0),
|
|
|
|
|
); // 2 For Rescheduling an Appointment
|
|
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> onRescheduleAppointmentConfirmPressed(
|
|
|
|
|
{required BuildContext context,
|
|
|
|
|
required int appointmentId,
|
|
|
|
|
required int selectedSlotId}) async {
|
|
|
|
|
Future<void> onRescheduleAppointmentConfirmPressed({required BuildContext context, required int appointmentId, required int selectedSlotId}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
GenericRespModel genericRespModel =
|
|
|
|
|
await scheduleRepo.cancelOrRescheduleServiceAppointment(
|
|
|
|
|
GenericRespModel genericRespModel = await scheduleRepo.cancelOrRescheduleServiceAppointment(
|
|
|
|
|
serviceAppointmentID: appointmentId,
|
|
|
|
|
serviceSlotID: selectedSlotId,
|
|
|
|
|
appointmentScheduleAction: 1, // 1 for Reschedule and 2 for Cancel
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (genericRespModel.messageStatus == 2 ||
|
|
|
|
|
genericRespModel.data == null) {
|
|
|
|
|
if (genericRespModel.messageStatus == 2 || genericRespModel.data == null) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.showToast("${genericRespModel.message.toString()}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (genericRespModel.data == 1) {
|
|
|
|
|
context.read<DashboardVmCustomer>().onNavbarTapped(1);
|
|
|
|
|
applyFilterOnAppointmentsVM(
|
|
|
|
|
appointmentStatusEnum: AppointmentStatusEnum.cancelled);
|
|
|
|
|
applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.cancelled);
|
|
|
|
|
Utils.showToast("${genericRespModel.message.toString()}");
|
|
|
|
|
getMyAppointments();
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
|