appointment fix

master_new_changes
Aamir.Muhammad 2 years ago
parent cd97cbda78
commit b7d3e4ab72

@ -45,10 +45,7 @@ class AppointmentsVM extends BaseVM {
final BranchRepo branchRepo;
final AppointmentRepo appointmentRepo;
AppointmentsVM({required this.commonServices,
required this.appointmentRepo,
required this.commonRepo,
required this.branchRepo});
AppointmentsVM({required this.commonServices, required this.appointmentRepo, required this.commonRepo, required this.branchRepo});
bool isUpcommingEnabled = true;
bool isFetchingLists = false;
@ -76,8 +73,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;
}
@ -98,8 +94,7 @@ class AppointmentsVM extends BaseVM {
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,11 +111,8 @@ class AppointmentsVM extends BaseVM {
}
Future<void> onPayNowPressedForAppointment({required BuildContext context, required int appointmentID}) async {
context
.read<PaymentVM>()
.updateAppointmentIdsForPayment(ids: [appointmentID]);
navigateWithName(context, AppRoutes.paymentMethodsView,
arguments: PaymentTypes.partialAppointment);
context.read<PaymentVM>().updateAppointmentIdsForPayment(ids: [appointmentID]);
navigateWithName(context, AppRoutes.paymentMethodsView, arguments: PaymentTypes.partialAppointment);
}
Future<void> onBookAppointmentPressed(BuildContext context) async {
@ -128,8 +120,7 @@ class AppointmentsVM extends BaseVM {
bool isSuccess = false;
List<int> appointmentIdsList = [];
try {
GenericRespModel genericRespModel =
await appointmentRepo.createServiceAppointment(
GenericRespModel genericRespModel = await appointmentRepo.createServiceAppointment(
schedules: serviceAppointmentScheduleList,
serviceProviderID: selectedBranchModel!.serviceProviderId ?? 0,
);
@ -155,17 +146,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(LocaleKeys.appointmentBookedSuccessfully.tr());
getMyAppointments();
@ -178,34 +165,27 @@ 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);
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 appointmentRepo.cancelOrRescheduleServiceAppointment(
GenericRespModel genericRespModel = await appointmentRepo.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.messageStatus == 1) {
context.read<DashboardVmCustomer>().onNavbarTapped(1);
applyFilterOnAppointmentsVM(
appointmentStatusEnum: AppointmentStatusEnum.cancelled);
applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.cancelled);
Utils.showToast("${genericRespModel.message.toString()}");
await getMyAppointments();
Utils.hideLoading(context);
@ -236,8 +216,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;
@ -252,30 +231,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;
}
@ -290,29 +262,21 @@ class AppointmentsVM extends BaseVM {
Future<void> populateAppointmentsFilterList() async {
if (appointmentsFilterOptions.isNotEmpty) return;
myAppointmentsEnum = await commonRepo.getEnumTypeValues(
enumTypeID: 13); // 13 is to get Appointments Filter Enums
myAppointmentsEnum = await commonRepo.getEnumTypeValues(enumTypeID: 13); // 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));
// TODO: THIS SHOULD REMOVED AND ADDED IN THE ENUMS API
appointmentsFilterOptions.add(
FilterListModel(title: "Work In Progress", isSelected: false, id: 7));
appointmentsFilterOptions.add(
FilterListModel(title: "Visit Completed", isSelected: false, id: 8));
appointmentsFilterOptions.add(FilterListModel(title: "Work In Progress", isSelected: false, id: 7));
appointmentsFilterOptions.add(FilterListModel(title: "Visit Completed", isSelected: false, id: 8));
notifyListeners();
}
applyFilterOnAppointmentsVM({required AppointmentStatusEnum appointmentStatusEnum,
bool isNeedCustomerFilter = false}) {
applyFilterOnAppointmentsVM({required AppointmentStatusEnum appointmentStatusEnum, bool isNeedCustomerFilter = false}) {
// isNeedCustomerFilter IS ONLY FOR THE PROVIDER APP
if (appointmentsFilterOptions.isEmpty) return;
for (var value in appointmentsFilterOptions) {
@ -320,8 +284,7 @@ class AppointmentsVM extends BaseVM {
}
for (var element in appointmentsFilterOptions) {
if (element.id ==
appointmentStatusEnum.getIdFromAppointmentStatusEnum()) {
if (element.id == appointmentStatusEnum.getIdFromAppointmentStatusEnum()) {
element.isSelected = true;
}
}
@ -332,15 +295,13 @@ class AppointmentsVM extends BaseVM {
if (appointmentStatusEnum.getIdFromAppointmentStatusEnum() == 0) {
myFilteredAppointments = myAppointments;
if (isNeedCustomerFilter) findAppointmentsBasedOnCustomers();
notifyListeners();
return;
}
myFilteredAppointments = myAppointments
.where((element) =>
element.appointmentStatusID! ==
appointmentStatusEnum.getIdFromAppointmentStatusEnum())
.toList();
myFilteredAppointments = myAppointments.where((element) => element.appointmentStatusID! == appointmentStatusEnum.getIdFromAppointmentStatusEnum()).toList();
if (isNeedCustomerFilter) findAppointmentsBasedOnCustomers();
notifyListeners();
}
findAppointmentsBasedOnCustomers() {
@ -354,9 +315,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;
@ -376,35 +335,42 @@ class AppointmentsVM extends BaseVM {
// }).toList();
}
Future<void> getMyAppointments() async {
setState(ViewState.busy);
// Future<void> getMyAppointments() async {
// setState(ViewState.busy);
//
// myAppointments =
// await appointmentRepo.getMyAppointmentsForCustomersByFilters();
// myFilteredAppointments = myAppointments;
// myUpComingAppointments = myAppointments
// .where((element) =>
// element.appointmentStatusEnum == AppointmentStatusEnum.booked)
// .toList();
// applyFilterOnAppointmentsVM(
// appointmentStatusEnum: AppointmentStatusEnum.allAppointments);
// if (myUpComingAppointments.isEmpty) {
// isShowEmptyMessage = true;
// }
// setState(ViewState.idle);
// notifyListeners();
// }
myAppointments =
await appointmentRepo.getMyAppointmentsForCustomersByFilters();
myFilteredAppointments = myAppointments;
myUpComingAppointments = myAppointments
.where((element) =>
element.appointmentStatusEnum == AppointmentStatusEnum.confirmed)
.toList();
Future<void> getMyAppointments({bool isNeedToRebuild = false}) async {
if (isNeedToRebuild) setState(ViewState.busy);
applyFilterOnAppointmentsVM(
appointmentStatusEnum: AppointmentStatusEnum.allAppointments);
if (myUpComingAppointments.isEmpty) {
isShowEmptyMessage = true;
}
myAppointments = await appointmentRepo.getMyAppointmentsForCustomersByFilters();
// myFilteredAppointments = myAppointments;
myUpComingAppointments = myAppointments.where((element) => element.appointmentStatusEnum == AppointmentStatusEnum.booked).toList();
setState(ViewState.idle);
applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.allAppointments);
notifyListeners();
}
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 appointmentRepo.getAppointmentSlots(map);
MResponse genericRespModel = await appointmentRepo.getAppointmentSlots(map);
if (genericRespModel.messageStatus == 1) {
appointmentSlots = AppointmentSlots.fromJson(genericRespModel.data);
} else {
@ -415,26 +381,21 @@ class AppointmentsVM extends BaseVM {
}
}
Future<void> getMyAppointmentsForProvider(Map<String, dynamic> map,) async {
Future<void> getMyAppointmentsForProvider(
Map<String, dynamic> map,
) async {
setState(ViewState.busy);
myAppointments = await appointmentRepo.getMyAppointmentsForProvider(map);
myFilteredAppointments = myAppointments;
myUpComingAppointments = await myAppointments
.where((element) =>
element.appointmentStatusEnum == AppointmentStatusEnum.confirmed)
.toList();
applyFilterOnAppointmentsVM(
appointmentStatusEnum: AppointmentStatusEnum.allAppointments,
isNeedCustomerFilter: true);
myUpComingAppointments = await myAppointments.where((element) => element.appointmentStatusEnum == AppointmentStatusEnum.confirmed).toList();
applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.allAppointments, isNeedCustomerFilter: true);
setState(ViewState.idle);
}
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 appointmentRepo.updateAppointmentStatus(map);
MResponse genericRespModel = await appointmentRepo.updateAppointmentStatus(map);
if (genericRespModel.messageStatus == 1) {
Utils.showToast(LocaleKeys.appointmentStatusUpdated.tr());
@ -446,12 +407,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 appointmentRepo.updateAppointmentPaymentStatus(map);
MResponse genericRespModel = await appointmentRepo.updateAppointmentPaymentStatus(map);
if (genericRespModel.messageStatus == 1) {
Utils.showToast(LocaleKeys.paymentStatusUpdated.tr());
@ -463,11 +422,9 @@ class AppointmentsVM extends BaseVM {
}
}
Future<MResponse> createMergeAppointment(Map<String, dynamic> map,
{bool isNeedToRebuild = false}) async {
Future<MResponse> createMergeAppointment(Map<String, dynamic> map, {bool isNeedToRebuild = false}) async {
if (isNeedToRebuild) setState(ViewState.busy);
MResponse genericRespModel =
await appointmentRepo.createMergeAppointment(map);
MResponse genericRespModel = await appointmentRepo.createMergeAppointment(map);
return genericRespModel;
}
@ -475,16 +432,10 @@ class AppointmentsVM extends BaseVM {
bool inNeedToEnableMergeButton = false;
updateCheckBoxInMergeRequest(int currentIndex) {
myFilteredAppointments2[selectedAppointmentIndex]
.customerAppointmentList![currentIndex]
.isSelected = !(myFilteredAppointments2[selectedAppointmentIndex]
.customerAppointmentList?[currentIndex]
.isSelected ??
false);
int count = countSelected(myFilteredAppointments2[selectedAppointmentIndex]
.customerAppointmentList ??
[]);
myFilteredAppointments2[selectedAppointmentIndex].customerAppointmentList![currentIndex].isSelected =
!(myFilteredAppointments2[selectedAppointmentIndex].customerAppointmentList?[currentIndex].isSelected ?? false);
int count = countSelected(myFilteredAppointments2[selectedAppointmentIndex].customerAppointmentList ?? []);
if (count > 1)
inNeedToEnableMergeButton = true;
else
@ -493,59 +444,35 @@ class AppointmentsVM extends BaseVM {
}
int countSelected(List<AppointmentListModel> appointments) {
return appointments
.where((appointment) => appointment.isSelected == true)
.toList()
.length;
return appointments.where((appointment) => appointment.isSelected == true).toList().length;
}
updateSelectedAppointmentDate({required int dateIndex, required int scheduleIndex}) {
for (var element in serviceAppointmentScheduleList[scheduleIndex]
.customTimeDateSlotList!) {
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!) {
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();
}
@ -559,8 +486,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;
@ -575,28 +501,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();
}
@ -608,8 +525,7 @@ class AppointmentsVM extends BaseVM {
}
branchesFilterOptions[index].isSelected = true;
await getBranchesBasedOnCategoryFilters(
categoryId: branchesFilterOptions[index].id);
await getBranchesBasedOnCategoryFilters(categoryId: branchesFilterOptions[index].id);
notifyListeners();
}
@ -628,8 +544,7 @@ class AppointmentsVM extends BaseVM {
String pickHomeLocationError = "";
String selectSubServicesError = "";
SelectionModel branchSelectedServiceId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
SelectionModel branchSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
void updatePickHomeLocationError(String value) {
pickHomeLocationError = value;
@ -688,9 +603,7 @@ class AppointmentsVM extends BaseVM {
builder: (BuildContext context) {
double totalKms = 15.3;
return InfoBottomSheet(
title: LocaleKeys.chargesBreakdown
.tr()
.toText(fontSize: 24, isBold: true),
title: LocaleKeys.chargesBreakdown.tr().toText(fontSize: 24, isBold: true),
description: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@ -698,16 +611,11 @@ class AppointmentsVM extends BaseVM {
Column(
children: List.generate(
selectedService.serviceItems!.length,
(index) =>
Row(
(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),
"${selectedService.serviceItems![index].name}".toText(fontSize: 12, color: MyColors.lightTextColor, isBold: true),
"${selectedService.serviceItems![index].price} SAR".toText(fontSize: 12, isBold: true),
],
),
),
@ -715,32 +623,24 @@ class AppointmentsVM extends BaseVM {
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
"${selectedService.currentTotalServicePrice} SAR"
.toText(fontSize: 16, isBold: true),
"${selectedService.currentTotalServicePrice} SAR".toText(fontSize: 16, isBold: true),
],
),
if (selectedService.isHomeSelected) ...[
20.height,
LocaleKeys.homeLocation
.tr()
.toText(fontSize: 16, isBold: true),
LocaleKeys.homeLocation.tr().toText(fontSize: 16, isBold: true),
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),
],
),
],
@ -748,9 +648,7 @@ class AppointmentsVM extends BaseVM {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
LocaleKeys.totalAmount
.tr()
.toText(fontSize: 16, isBold: true),
LocaleKeys.totalAmount.tr().toText(fontSize: 16, isBold: true),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
@ -759,13 +657,7 @@ class AppointmentsVM extends BaseVM {
: "${selectedService.currentTotalServicePrice}")
.toText(fontSize: 29, isBold: true),
2.width,
LocaleKeys.sar
.tr()
.toText(
color: MyColors.lightTextColor,
fontSize: 16,
isBold: true)
.paddingOnly(bottom: 5),
LocaleKeys.sar.tr().toText(color: MyColors.lightTextColor, fontSize: 16, isBold: true).paddingOnly(bottom: 5),
],
)
],
@ -785,8 +677,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 {
@ -794,9 +685,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;
@ -824,8 +713,7 @@ class AppointmentsVM extends BaseVM {
}
}
serviceAppointmentScheduleList =
await appointmentRepo.mergeServiceIntoAvailableSchedules(
serviceAppointmentScheduleList = await appointmentRepo.mergeServiceIntoAvailableSchedules(
serviceItemIdsForHome: serviceItemIdsForHome,
serviceItemIdsForWorkshop: serviceItemIdsForWorkshop,
);
@ -838,21 +726,17 @@ class AppointmentsVM extends BaseVM {
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 = [];
@ -869,8 +753,7 @@ class AppointmentsVM extends BaseVM {
}
}
serviceAppointmentScheduleList =
await appointmentRepo.mergeServiceIntoAvailableSchedules(
serviceAppointmentScheduleList = await appointmentRepo.mergeServiceIntoAvailableSchedules(
serviceItemIdsForHome: serviceItemIdsForHome,
serviceItemIdsForWorkshop: serviceItemIdsForWorkshop,
);
@ -885,35 +768,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 appointmentRepo.cancelOrRescheduleServiceAppointment(
GenericRespModel genericRespModel = await appointmentRepo.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.messageStatus == 1) {
context.read<DashboardVmCustomer>().onNavbarTapped(1);
applyFilterOnAppointmentsVM(
appointmentStatusEnum: AppointmentStatusEnum.cancelled);
applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.cancelled);
Utils.showToast("${genericRespModel.message.toString()}");
getMyAppointments();
Utils.hideLoading(context);
@ -950,13 +827,9 @@ class AppointmentsVM extends BaseVM {
setOnlyState(ViewState.busy);
Category category = await branchRepo.fetchBranchCategory();
category.data?.forEach((element) {
branchesFilterOptions.add(FilterListModel(
id: element.id ?? 0,
isSelected: false,
title: element.categoryName ?? "N/A"));
branchesFilterOptions.add(FilterListModel(id: element.id ?? 0, isSelected: false, title: element.categoryName ?? "N/A"));
});
branchesFilterOptions.insert(
0, FilterListModel(id: 0, isSelected: true, title: "All Branches"));
branchesFilterOptions.insert(0, FilterListModel(id: 0, isSelected: true, title: "All Branches"));
notifyListeners();
setState(ViewState.idle);
}
@ -966,10 +839,8 @@ class AppointmentsVM extends BaseVM {
if (isNeedToRebuild) setState(ViewState.busy);
if (isFromRefresh) {
var selectedBranch =
branchesFilterOptions.firstWhere((element) => element.isSelected);
nearbyBranches = await branchRepo
.getBranchesByFilters(categoryIdsList: [selectedBranch.id]);
var selectedBranch = branchesFilterOptions.firstWhere((element) => element.isSelected);
nearbyBranches = await branchRepo.getBranchesByFilters(categoryIdsList: [selectedBranch.id]);
setState(ViewState.idle);
return;
}
@ -980,16 +851,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 = "";
@ -1002,16 +871,13 @@ 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;
}
getBranchAndServices(int providerId) async {
providerProfileModel = null;
providerProfileModel =
await branchRepo.getBranchAndServicesByProviderId(providerId);
providerProfileModel = await branchRepo.getBranchAndServicesByProviderId(providerId);
setState(ViewState.idle);
}
@ -1068,16 +934,12 @@ class AppointmentsVM extends BaseVM {
notifyListeners();
}
SelectionModel branchFilterSelectedProviderId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
SelectionModel branchFilterSelectedProviderId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
void updateBranchFilterSelectedProviderId(SelectionModel id,
{bool isForSearch = false}) async {
void updateBranchFilterSelectedProviderId(SelectionModel id, {bool isForSearch = false}) async {
if (isForSearch) {
DropValue providerDrop = providersDropList
.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(
list: branchFilterProviderSearchHistory, value: providerDrop)) {
DropValue providerDrop = providersDropList.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(list: branchFilterProviderSearchHistory, value: providerDrop)) {
addBranchFilterProviderSearchHistory(value: providerDrop);
}
}
@ -1111,16 +973,12 @@ class AppointmentsVM extends BaseVM {
notifyListeners();
}
SelectionModel branchFilterSelectedCategoryId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
SelectionModel branchFilterSelectedCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
void updateBranchFilterSelectedCategoryId(SelectionModel id,
{bool isForSearch = false}) async {
void updateBranchFilterSelectedCategoryId(SelectionModel id, {bool isForSearch = false}) async {
if (isForSearch) {
DropValue categoryDrop =
categoryDropList.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(
list: branchFilterCategorySearchHistory, value: categoryDrop)) {
DropValue categoryDrop = categoryDropList.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(list: branchFilterCategorySearchHistory, value: categoryDrop)) {
addBranchFilterCategorySearchHistory(value: categoryDrop);
}
}
@ -1154,16 +1012,12 @@ class AppointmentsVM extends BaseVM {
notifyListeners();
}
SelectionModel branchFilterSelectedServiceId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
SelectionModel branchFilterSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
void updateBranchFilterSelectedServiceId(SelectionModel id,
{bool isForSearch = false}) async {
void updateBranchFilterSelectedServiceId(SelectionModel id, {bool isForSearch = false}) async {
if (isForSearch) {
DropValue serviceDrop =
servicesDropList.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(
list: branchFilterServicesSearchHistory, value: serviceDrop)) {
DropValue serviceDrop = servicesDropList.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(list: branchFilterServicesSearchHistory, value: serviceDrop)) {
addBranchFilterServicesSearchHistory(value: serviceDrop);
}
notifyListeners();
@ -1204,8 +1058,7 @@ class AppointmentsVM extends BaseVM {
providersDropList.clear();
setOnlyState(ViewState.busy);
List<ProviderBasicDataModel> providers =
await branchRepo.getAllProvidersWitheBasicData();
List<ProviderBasicDataModel> providers = await branchRepo.getAllProvidersWitheBasicData();
for (var element in providers) {
providersDropList.add(
DropValue(element.id ?? 0, element.providerName ?? "N/A", ""),
@ -1239,8 +1092,7 @@ class AppointmentsVM extends BaseVM {
if (servicesDropList.isNotEmpty) return;
servicesDropList.clear();
setState(ViewState.busy);
Services services = await branchRepo.fetchServicesByCategoryId(
serviceCategoryId: -1); // to get all services
Services services = await branchRepo.fetchServicesByCategoryId(serviceCategoryId: -1); // to get all services
for (var element in services.data!) {
servicesDropList.add(
@ -1273,12 +1125,9 @@ class AppointmentsVM extends BaseVM {
}
void clearBranchFilterSelections() {
branchFilterSelectedProviderId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
branchFilterSelectedCategoryId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
branchFilterSelectedServiceId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
branchFilterSelectedProviderId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
branchFilterSelectedCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
branchFilterSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
}
Future<void> getBranchesBasedOnFilters() async {
@ -1322,8 +1171,7 @@ class AppointmentsVM extends BaseVM {
}
setState(ViewState.busy);
nearbyBranches.clear();
nearbyBranches =
await branchRepo.getBranchesByFilters(categoryIdsList: [categoryId]);
nearbyBranches = await branchRepo.getBranchesByFilters(categoryIdsList: [categoryId]);
setState(ViewState.idle);
}
@ -1334,11 +1182,9 @@ class AppointmentsVM extends BaseVM {
Future<void> fetchAllBranchesBySelectedProviderId({required List<int> providersIdsList}) async {
branchesDropList.clear();
setOnlyState(ViewState.busy);
List<BranchDetailModel> providers = await branchRepo.getBranchesByFilters(
providerIdsList: providersIdsList);
List<BranchDetailModel> providers = await branchRepo.getBranchesByFilters(providerIdsList: providersIdsList);
for (var element in providers) {
branchesDropList
.add(DropValue(element.id ?? 0, element.branchName ?? "N/A", ""));
branchesDropList.add(DropValue(element.id ?? 0, element.branchName ?? "N/A", ""));
}
setState(ViewState.idle);
@ -1373,8 +1219,7 @@ class AppointmentsVM extends BaseVM {
for (var element in appointmentFilterProviderSearchHistory) {
providerIdsSelected.add(element.id);
}
fetchAllBranchesBySelectedProviderId(
providersIdsList: providerIdsSelected);
fetchAllBranchesBySelectedProviderId(providersIdsList: providerIdsSelected);
}
if (appointmentFilterProviderSearchHistory.isEmpty) {
@ -1397,16 +1242,12 @@ class AppointmentsVM extends BaseVM {
notifyListeners();
}
SelectionModel appointmentFilterSelectedProviderId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
SelectionModel appointmentFilterSelectedProviderId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
void updateAppointmentFilterSelectedProviderId(SelectionModel id,
{bool isForSearch = false}) async {
void updateAppointmentFilterSelectedProviderId(SelectionModel id, {bool isForSearch = false}) async {
if (isForSearch) {
DropValue providerDrop = providersDropList
.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(
list: appointmentFilterProviderSearchHistory, value: providerDrop)) {
DropValue providerDrop = providersDropList.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(list: appointmentFilterProviderSearchHistory, value: providerDrop)) {
addAppointmentFilterProviderSearchHistory(value: providerDrop);
}
}
@ -1440,16 +1281,12 @@ class AppointmentsVM extends BaseVM {
notifyListeners();
}
SelectionModel appointmentFilterSelectedBranchId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
SelectionModel appointmentFilterSelectedBranchId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
void updateAppointmentFilterSelectedBranchId(SelectionModel id,
{bool isForSearch = false}) async {
void updateAppointmentFilterSelectedBranchId(SelectionModel id, {bool isForSearch = false}) async {
if (isForSearch) {
DropValue branchesDrop =
branchesDropList.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(
list: appointmentFilterBranchSearchHistory, value: branchesDrop)) {
DropValue branchesDrop = branchesDropList.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(list: appointmentFilterBranchSearchHistory, value: branchesDrop)) {
addAppointmentFilterBranchSearchHistory(value: branchesDrop);
}
}
@ -1483,16 +1320,12 @@ class AppointmentsVM extends BaseVM {
notifyListeners();
}
SelectionModel appointmentFilterSelectedCategoryId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
SelectionModel appointmentFilterSelectedCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
void updateAppointmentFilterSelectedCategoryId(SelectionModel id,
{bool isForSearch = false}) async {
void updateAppointmentFilterSelectedCategoryId(SelectionModel id, {bool isForSearch = false}) async {
if (isForSearch) {
DropValue categoryDrop =
categoryDropList.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(
list: appointmentFilterCategorySearchHistory, value: categoryDrop)) {
DropValue categoryDrop = categoryDropList.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(list: appointmentFilterCategorySearchHistory, value: categoryDrop)) {
addAppointmentFilterCategorySearchHistory(value: categoryDrop);
}
}
@ -1524,16 +1357,12 @@ class AppointmentsVM extends BaseVM {
notifyListeners();
}
SelectionModel appointmentFilterSelectedServiceId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
SelectionModel appointmentFilterSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
void updateAppointmentFilterSelectedServiceId(SelectionModel id,
{bool isForSearch = false}) async {
void updateAppointmentFilterSelectedServiceId(SelectionModel id, {bool isForSearch = false}) async {
if (isForSearch) {
DropValue servicesDrop =
servicesDropList.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(
list: appointmentFilterServicesSearchHistory, value: servicesDrop)) {
DropValue servicesDrop = servicesDropList.firstWhere((element) => element.id == id.selectedId);
if (!ifAlreadyExist(list: appointmentFilterServicesSearchHistory, value: servicesDrop)) {
addAppointmentFilterServicesSearchHistory(value: servicesDrop);
}
}
@ -1542,14 +1371,10 @@ class AppointmentsVM extends BaseVM {
}
void clearAppointmentFilterSelections() {
appointmentFilterSelectedProviderId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
appointmentFilterSelectedCategoryId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
appointmentFilterSelectedServiceId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
appointmentFilterSelectedBranchId =
SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
appointmentFilterSelectedProviderId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
appointmentFilterSelectedCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
appointmentFilterSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
appointmentFilterSelectedBranchId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
}
void clearAppointmentFilters() {
@ -1590,15 +1415,13 @@ class AppointmentsVM extends BaseVM {
}
}
myAppointments =
await appointmentRepo.getMyAppointmentsForCustomersByFilters(
myAppointments = await appointmentRepo.getMyAppointmentsForCustomersByFilters(
providerIdsList: providersIdsList.isNotEmpty ? providersIdsList : null,
categoryIdsList: categoryIdsList.isNotEmpty ? categoryIdsList : null,
serviceIdsList: servicesIdsList.isNotEmpty ? servicesIdsList : null,
branchIdsList: branchesIdsList.isNotEmpty ? branchesIdsList : null,
);
applyFilterOnAppointmentsVM(
appointmentStatusEnum: AppointmentStatusEnum.allAppointments);
applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.allAppointments);
setState(ViewState.idle);
}
}

Loading…
Cancel
Save