|
|
|
|
@ -1,21 +1,27 @@
|
|
|
|
|
import 'dart:developer';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:mc_common_app/classes/consts.dart';
|
|
|
|
|
import 'package:mc_common_app/config/routes.dart';
|
|
|
|
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
|
|
|
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
|
|
|
|
import 'package:mc_common_app/models/appointments_models/appointment_list_model.dart';
|
|
|
|
|
import 'package:mc_common_app/models/appointments_models/appointment_slots.dart';
|
|
|
|
|
import 'package:mc_common_app/models/appointments_models/service_schedule_model.dart';
|
|
|
|
|
import 'package:mc_common_app/models/general_models/enums_model.dart';
|
|
|
|
|
import 'package:mc_common_app/models/general_models/generic_resp_model.dart';
|
|
|
|
|
import 'package:mc_common_app/models/general_models/m_response.dart';
|
|
|
|
|
import 'package:mc_common_app/models/general_models/widgets_models.dart';
|
|
|
|
|
import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart';
|
|
|
|
|
import 'package:mc_common_app/models/provider_branches_models/profile/categroy.dart';
|
|
|
|
|
import 'package:mc_common_app/models/provider_branches_models/profile/services.dart';
|
|
|
|
|
import 'package:mc_common_app/models/provider_branches_models/provider_model.dart';
|
|
|
|
|
import 'package:mc_common_app/models/provider_branches_models/provider_profile_model.dart';
|
|
|
|
|
import 'package:mc_common_app/models/services_models/item_model.dart';
|
|
|
|
|
import 'package:mc_common_app/models/services_models/service_model.dart';
|
|
|
|
|
import 'package:mc_common_app/repositories/appointment_repo.dart';
|
|
|
|
|
import 'package:mc_common_app/repositories/branch_repo.dart';
|
|
|
|
|
import 'package:mc_common_app/repositories/common_repo.dart';
|
|
|
|
|
import 'package:mc_common_app/repositories/provider_repo.dart';
|
|
|
|
|
import 'package:mc_common_app/services/common_services.dart';
|
|
|
|
|
import 'package:mc_common_app/theme/colors.dart';
|
|
|
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
|
|
|
@ -31,15 +37,13 @@ import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
import '../models/appointments_models/appointment_slots.dart';
|
|
|
|
|
|
|
|
|
|
class AppointmentsVM extends BaseVM {
|
|
|
|
|
final CommonRepo commonRepo;
|
|
|
|
|
final CommonAppServices commonServices;
|
|
|
|
|
final ProviderRepo providerRepo;
|
|
|
|
|
final AppointmentRepo scheduleRepo;
|
|
|
|
|
final BranchRepo branchRepo;
|
|
|
|
|
final AppointmentRepo appointmentRepo;
|
|
|
|
|
|
|
|
|
|
AppointmentsVM({required this.commonServices, required this.scheduleRepo, required this.providerRepo, required this.commonRepo});
|
|
|
|
|
AppointmentsVM({required this.commonServices, required this.appointmentRepo, required this.commonRepo, required this.branchRepo});
|
|
|
|
|
|
|
|
|
|
bool isUpcommingEnabled = true;
|
|
|
|
|
bool isFetchingLists = false;
|
|
|
|
|
@ -75,15 +79,15 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
List<ItemData> allSelectedItemsInAppointments = [];
|
|
|
|
|
|
|
|
|
|
setupProviderAppointmentFilter() {
|
|
|
|
|
appointmentsFilterOptions.clear();
|
|
|
|
|
appointmentsFilterOptions.add(FilterListModel(id: 0, title: "All Appointments", isSelected: true));
|
|
|
|
|
appointmentsFilterOptions.add(FilterListModel(id: 2, title: "Confirmed", isSelected: false));
|
|
|
|
|
appointmentsFilterOptions.add(FilterListModel(id: 3, title: "Arrived", isSelected: false));
|
|
|
|
|
appointmentsFilterOptions.add(FilterListModel(id: 7, title: "Work In Progress", isSelected: false));
|
|
|
|
|
appointmentsFilterOptions.add(FilterListModel(id: 8, title: "Completed", isSelected: false));
|
|
|
|
|
appointmentsFilterOptions.add(FilterListModel(id: 4, title: "Canceled", isSelected: false));
|
|
|
|
|
}
|
|
|
|
|
// setupProviderAppointmentFilter() {
|
|
|
|
|
// appointmentsFilterOptions.clear();
|
|
|
|
|
// appointmentsFilterOptions.add(FilterListModel(id: 0, title: "All Appointments", isSelected: true));
|
|
|
|
|
// appointmentsFilterOptions.add(FilterListModel(id: 2, title: "Confirmed", isSelected: false));
|
|
|
|
|
// appointmentsFilterOptions.add(FilterListModel(id: 3, title: "Arrived", isSelected: false));
|
|
|
|
|
// appointmentsFilterOptions.add(FilterListModel(id: 7, title: "Work In Progress", isSelected: false));
|
|
|
|
|
// appointmentsFilterOptions.add(FilterListModel(id: 8, title: "Completed", isSelected: false));
|
|
|
|
|
// appointmentsFilterOptions.add(FilterListModel(id: 4, title: "Canceled", isSelected: false));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Future<void> onItemsSelectedInService() async {
|
|
|
|
|
if (currentServiceSelection != null) {
|
|
|
|
|
@ -113,7 +117,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
bool isSuccess = false;
|
|
|
|
|
List<int> appointmentIdsList = [];
|
|
|
|
|
try {
|
|
|
|
|
GenericRespModel genericRespModel = await scheduleRepo.createServiceAppointment(
|
|
|
|
|
GenericRespModel genericRespModel = await appointmentRepo.createServiceAppointment(
|
|
|
|
|
schedules: serviceAppointmentScheduleList,
|
|
|
|
|
serviceProviderID: selectedBranchModel!.serviceProviderId ?? 0,
|
|
|
|
|
);
|
|
|
|
|
@ -165,7 +169,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
Future<void> onCancelAppointmentPressed({required BuildContext context, required AppointmentListModel appointmentListModel}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
GenericRespModel genericRespModel = await scheduleRepo.cancelOrRescheduleServiceAppointment(
|
|
|
|
|
GenericRespModel genericRespModel = await appointmentRepo.cancelOrRescheduleServiceAppointment(
|
|
|
|
|
serviceAppointmentID: appointmentListModel.id ?? 0,
|
|
|
|
|
serviceSlotID: appointmentListModel.serviceSlotID ?? 0,
|
|
|
|
|
appointmentScheduleAction: 2, // 1 for Reschedule and 2 for Cancel
|
|
|
|
|
@ -217,11 +221,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<FilterListModel> providersFilterOptions = [];
|
|
|
|
|
List<BranchDetailModel> nearbyBranches = [];
|
|
|
|
|
BranchDetailModel? selectedBranchModel;
|
|
|
|
|
|
|
|
|
|
List<ServiceModel> branchServices = [];
|
|
|
|
|
List<FilterListModel> branchesFilterOptions = [];
|
|
|
|
|
|
|
|
|
|
List<ServiceModel> servicesInCurrentAppointment = [];
|
|
|
|
|
ServiceModel? currentServiceSelection;
|
|
|
|
|
@ -256,10 +256,10 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
List<EnumsModel> myAppointmentsEnum = [];
|
|
|
|
|
|
|
|
|
|
populateAppointmentsFilterList() async {
|
|
|
|
|
Future<void> populateAppointmentsFilterList() async {
|
|
|
|
|
if (appointmentsFilterOptions.isNotEmpty) return;
|
|
|
|
|
|
|
|
|
|
myAppointmentsEnum = await commonRepo.getEnumTypeValues(enumTypeID: 13); //TODO: 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));
|
|
|
|
|
@ -274,16 +274,17 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
applyFilterOnAppointmentsVM({required AppointmentStatusEnum appointmentStatusEnum, bool isNeedCustomerFilter = false}) {
|
|
|
|
|
// isNeedCustomerFilter IS ONLY FOR THE PROVIDER APP
|
|
|
|
|
if (appointmentsFilterOptions.isEmpty) return;
|
|
|
|
|
for (var value in appointmentsFilterOptions) {
|
|
|
|
|
value.isSelected = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
appointmentsFilterOptions.forEach((element) {
|
|
|
|
|
for (var element in appointmentsFilterOptions) {
|
|
|
|
|
if (element.id == appointmentStatusEnum.getIdFromAppointmentStatusEnum()) {
|
|
|
|
|
element.isSelected = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// appointmentsFilterOptions[
|
|
|
|
|
// appointmentStatusEnum.getIdFromAppointmentStatusEnum()]
|
|
|
|
|
// .isSelected = true;
|
|
|
|
|
@ -302,7 +303,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
findAppointmentsBasedOnCustomers() {
|
|
|
|
|
// Use a Set to ensure uniqueness of customerIDs
|
|
|
|
|
Set<int> uniqueCustomerIDs = Set<int>();
|
|
|
|
|
Set<int> uniqueCustomerIDs = <int>{};
|
|
|
|
|
|
|
|
|
|
// Extract unique customerIDs
|
|
|
|
|
for (var item in myFilteredAppointments) {
|
|
|
|
|
@ -334,11 +335,11 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
Future<void> getMyAppointments({bool isNeedToRebuild = false}) async {
|
|
|
|
|
if (isNeedToRebuild) setState(ViewState.busy);
|
|
|
|
|
|
|
|
|
|
myAppointments = await commonRepo.getMyAppointments();
|
|
|
|
|
myFilteredAppointments = myAppointments;
|
|
|
|
|
myAppointments = await appointmentRepo.getMyAppointmentsForCustomersByFilters();
|
|
|
|
|
// myFilteredAppointments = myAppointments;
|
|
|
|
|
myUpComingAppointments = myAppointments.where((element) => element.appointmentStatusEnum == AppointmentStatusEnum.confirmed).toList();
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
// applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.allAppointments);
|
|
|
|
|
applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.allAppointments);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -347,7 +348,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
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);
|
|
|
|
|
MResponse genericRespModel = await appointmentRepo.getAppointmentSlots(map);
|
|
|
|
|
if (genericRespModel.messageStatus == 1) {
|
|
|
|
|
appointmentSlots = AppointmentSlots.fromJson(genericRespModel.data);
|
|
|
|
|
} else {
|
|
|
|
|
@ -358,10 +359,10 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> getProviderMyAppointments(Map<String, dynamic> map, {bool isNeedToRebuild = false}) async {
|
|
|
|
|
Future<void> getMyAppointmentsForProvider(Map<String, dynamic> map, {bool isNeedToRebuild = false}) async {
|
|
|
|
|
if (isNeedToRebuild) setState(ViewState.busy);
|
|
|
|
|
|
|
|
|
|
myAppointments = await scheduleRepo.getMyAppointments(map);
|
|
|
|
|
myAppointments = await appointmentRepo.getMyAppointmentsForProvider(map);
|
|
|
|
|
myFilteredAppointments = myAppointments;
|
|
|
|
|
myUpComingAppointments = myAppointments.where((element) => element.appointmentStatusEnum == AppointmentStatusEnum.booked).toList();
|
|
|
|
|
|
|
|
|
|
@ -369,16 +370,10 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateSelectedBranch(BranchDetailModel branchDetailModel) {
|
|
|
|
|
selectedBranchModel = branchDetailModel;
|
|
|
|
|
getBranchCategories();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateAppointmentStatus(Map<String, dynamic> map, {bool isNeedToRebuild = false}) async {
|
|
|
|
|
if (isNeedToRebuild) setState(ViewState.busy);
|
|
|
|
|
try {
|
|
|
|
|
MResponse genericRespModel = await scheduleRepo.updateAppointmentStatus(map);
|
|
|
|
|
MResponse genericRespModel = await appointmentRepo.updateAppointmentStatus(map);
|
|
|
|
|
|
|
|
|
|
if (genericRespModel.messageStatus == 1) {
|
|
|
|
|
Utils.showToast("appointment status updated");
|
|
|
|
|
@ -393,7 +388,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
updateAppointmentPaymentStatus(Map<String, dynamic> map, {bool isNeedToRebuild = false}) async {
|
|
|
|
|
if (isNeedToRebuild) setState(ViewState.busy);
|
|
|
|
|
try {
|
|
|
|
|
MResponse genericRespModel = await scheduleRepo.updateAppointmentPaymentStatus(map);
|
|
|
|
|
MResponse genericRespModel = await appointmentRepo.updateAppointmentPaymentStatus(map);
|
|
|
|
|
|
|
|
|
|
if (genericRespModel.messageStatus == 1) {
|
|
|
|
|
Utils.showToast("payment status updated");
|
|
|
|
|
@ -407,7 +402,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
Future<MResponse> createMergeAppointment(Map<String, dynamic> map, {bool isNeedToRebuild = false}) async {
|
|
|
|
|
if (isNeedToRebuild) setState(ViewState.busy);
|
|
|
|
|
MResponse genericRespModel = await scheduleRepo.createMergeAppointment(map);
|
|
|
|
|
MResponse genericRespModel = await appointmentRepo.createMergeAppointment(map);
|
|
|
|
|
|
|
|
|
|
return genericRespModel;
|
|
|
|
|
}
|
|
|
|
|
@ -501,39 +496,20 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
populateBranchesFilterList() {
|
|
|
|
|
providersFilterOptions.clear(); // TODO: THIS SHOULD BE DYNAMIC AND FILTERS SHOULD COME FORM API
|
|
|
|
|
providersFilterOptions = [
|
|
|
|
|
FilterListModel(title: "All Providers", isSelected: true, id: 0),
|
|
|
|
|
FilterListModel(title: "Maintenance", isSelected: false, id: 1),
|
|
|
|
|
FilterListModel(title: "Oil Service", isSelected: false, id: 2),
|
|
|
|
|
FilterListModel(title: "Accessories", isSelected: false, id: 3),
|
|
|
|
|
FilterListModel(title: "Tire Service", isSelected: false, id: 4),
|
|
|
|
|
FilterListModel(title: "Dent and Paint", isSelected: false, id: 5),
|
|
|
|
|
];
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
applyFilterOnProviders({required int index}) {
|
|
|
|
|
if (providersFilterOptions.isEmpty) return;
|
|
|
|
|
for (var value in providersFilterOptions) {
|
|
|
|
|
Future<void> applyFilterOnBranches({required int index}) async {
|
|
|
|
|
if (branchesFilterOptions.isEmpty) return;
|
|
|
|
|
for (var value in branchesFilterOptions) {
|
|
|
|
|
value.isSelected = false;
|
|
|
|
|
}
|
|
|
|
|
providersFilterOptions[index].isSelected = true;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
branchesFilterOptions[index].isSelected = true;
|
|
|
|
|
|
|
|
|
|
getAllNearBranches({bool isNeedToRebuild = false}) async {
|
|
|
|
|
//TODO: needs to lat,long into API
|
|
|
|
|
nearbyBranches.clear();
|
|
|
|
|
if (isNeedToRebuild) setState(ViewState.busy);
|
|
|
|
|
nearbyBranches = await providerRepo.getAllNearBranchAndServices();
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
await getBranchesBasedOnCategoryFilters(categoryId: branchesFilterOptions[index].id);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<List<ItemData>> getServiceItems(int serviceId) async {
|
|
|
|
|
serviceItemsFromApi.clear();
|
|
|
|
|
serviceItemsFromApi = await providerRepo.getServiceItems(serviceId);
|
|
|
|
|
serviceItemsFromApi = await branchRepo.getServiceItems(serviceId);
|
|
|
|
|
for (var item in serviceItemsFromApi) {
|
|
|
|
|
if (ifItemAlreadySelected(item.id!)) {
|
|
|
|
|
item.isUpdateOrSelected = true;
|
|
|
|
|
@ -543,52 +519,11 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
return serviceItemsFromApi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getBranchAndServices(int providerId) async {
|
|
|
|
|
providerProfileModel = null;
|
|
|
|
|
providerProfileModel = await providerRepo.getBranchAndServices(providerId);
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String pickHomeLocationError = "";
|
|
|
|
|
String selectSubServicesError = "";
|
|
|
|
|
|
|
|
|
|
SelectionModel branchSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
|
|
|
|
|
bool isCategoryAlreadyPresent(int id) {
|
|
|
|
|
final contain = branchCategories.where((element) => element.id == id);
|
|
|
|
|
if (contain.isEmpty) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getBranchCategories() async {
|
|
|
|
|
for (var value in selectedBranchModel!.branchServices!) {
|
|
|
|
|
if (!isCategoryAlreadyPresent(value.categoryId!)) {
|
|
|
|
|
branchCategories.add(DropValue(value.categoryId!, value.categoryName!, ""));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getBranchServices({required int categoryId}) async {
|
|
|
|
|
branchSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
isHomeTapped = false;
|
|
|
|
|
pickedHomeLocation = "";
|
|
|
|
|
pickHomeLocationError = "";
|
|
|
|
|
if (categoryId != -1) {
|
|
|
|
|
isFetchingServices = true;
|
|
|
|
|
branchServices = getFilteredBranchServices(categoryId: categoryId);
|
|
|
|
|
isFetchingServices = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<ServiceModel> getFilteredBranchServices({required int categoryId}) {
|
|
|
|
|
List<ServiceModel> filteredServices = selectedBranchModel!.branchServices!.where((element) => element.categoryId == categoryId).toList();
|
|
|
|
|
return filteredServices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updatePickHomeLocationError(String value) {
|
|
|
|
|
pickHomeLocationError = value;
|
|
|
|
|
// notifyListeners();
|
|
|
|
|
@ -756,7 +691,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serviceAppointmentScheduleList = await scheduleRepo.mergeServiceIntoAvailableSchedules(
|
|
|
|
|
serviceAppointmentScheduleList = await appointmentRepo.mergeServiceIntoAvailableSchedules(
|
|
|
|
|
serviceItemIdsForHome: serviceItemIdsForHome,
|
|
|
|
|
serviceItemIdsForWorkshop: serviceItemIdsForWorkshop,
|
|
|
|
|
);
|
|
|
|
|
@ -796,7 +731,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serviceAppointmentScheduleList = await scheduleRepo.mergeServiceIntoAvailableSchedules(
|
|
|
|
|
serviceAppointmentScheduleList = await appointmentRepo.mergeServiceIntoAvailableSchedules(
|
|
|
|
|
serviceItemIdsForHome: serviceItemIdsForHome,
|
|
|
|
|
serviceItemIdsForWorkshop: serviceItemIdsForWorkshop,
|
|
|
|
|
);
|
|
|
|
|
@ -820,7 +755,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
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 appointmentRepo.cancelOrRescheduleServiceAppointment(
|
|
|
|
|
serviceAppointmentID: appointmentId,
|
|
|
|
|
serviceSlotID: selectedSlotId,
|
|
|
|
|
appointmentScheduleAction: 1, // 1 for Reschedule and 2 for Cancel
|
|
|
|
|
@ -843,4 +778,628 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
Utils.showToast("${e.toString()}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BRANCHES RELATED
|
|
|
|
|
|
|
|
|
|
List<BranchDetailModel> nearbyBranches = [];
|
|
|
|
|
BranchDetailModel? selectedBranchModel;
|
|
|
|
|
|
|
|
|
|
List<ServiceModel> branchServices = [];
|
|
|
|
|
|
|
|
|
|
// populateBranchesFilterList() {
|
|
|
|
|
// branchesFilterOptions.clear(); // TODO: THIS SHOULD BE DYNAMIC AND FILTERS SHOULD COME FORM API
|
|
|
|
|
// branchesFilterOptions = [
|
|
|
|
|
// FilterListModel(title: "All Branches", isSelected: true, id: 0),
|
|
|
|
|
// FilterListModel(title: "Maintenance", isSelected: false, id: 1),
|
|
|
|
|
// FilterListModel(title: "Oil Service", isSelected: false, id: 2),
|
|
|
|
|
// FilterListModel(title: "Accessories", isSelected: false, id: 3),
|
|
|
|
|
// FilterListModel(title: "Tire Service", isSelected: false, id: 4),
|
|
|
|
|
// FilterListModel(title: "Dent and Paint", isSelected: false, id: 5),
|
|
|
|
|
// ];
|
|
|
|
|
// notifyListeners();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Future<void> populateBranchesFilterList() async {
|
|
|
|
|
if (branchesFilterOptions.isNotEmpty) return;
|
|
|
|
|
branchesFilterOptions.clear();
|
|
|
|
|
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.insert(0, FilterListModel(id: 0, isSelected: true, title: "All Branches"));
|
|
|
|
|
notifyListeners();
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> getAllNearBranches({bool isNeedToRebuild = false, bool isFromRefresh = false}) async {
|
|
|
|
|
nearbyBranches.clear();
|
|
|
|
|
if (isNeedToRebuild) setState(ViewState.busy);
|
|
|
|
|
|
|
|
|
|
if (isFromRefresh) {
|
|
|
|
|
var selectedBranch = branchesFilterOptions.firstWhere((element) => element.isSelected);
|
|
|
|
|
nearbyBranches = await branchRepo.getBranchesByFilters(categoryIdsList: [selectedBranch.id]);
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
nearbyBranches = await branchRepo.getAllNearBranchAndServices();
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getBranchCategories() async {
|
|
|
|
|
for (var value in selectedBranchModel!.branchServices!) {
|
|
|
|
|
if (!isCategoryAlreadyPresent(value.categoryId!)) {
|
|
|
|
|
branchCategories.add(DropValue(value.categoryId!, value.categoryName!, ""));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getBranchServices({required int categoryId}) async {
|
|
|
|
|
branchSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
isHomeTapped = false;
|
|
|
|
|
pickedHomeLocation = "";
|
|
|
|
|
pickHomeLocationError = "";
|
|
|
|
|
if (categoryId != -1) {
|
|
|
|
|
isFetchingServices = true;
|
|
|
|
|
branchServices = getFilteredBranchServices(categoryId: categoryId);
|
|
|
|
|
isFetchingServices = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<ServiceModel> getFilteredBranchServices({required int categoryId}) {
|
|
|
|
|
List<ServiceModel> filteredServices = selectedBranchModel!.branchServices!.where((element) => element.categoryId == categoryId).toList();
|
|
|
|
|
return filteredServices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getBranchAndServices(int providerId) async {
|
|
|
|
|
providerProfileModel = null;
|
|
|
|
|
providerProfileModel = await branchRepo.getBranchAndServicesByProviderId(providerId);
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isCategoryAlreadyPresent(int id) {
|
|
|
|
|
final contain = branchCategories.where((element) => element.id == id);
|
|
|
|
|
if (contain.isEmpty) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateSelectedBranch(BranchDetailModel branchDetailModel) {
|
|
|
|
|
selectedBranchModel = branchDetailModel;
|
|
|
|
|
getBranchCategories();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int branchFiltersCounter = 0;
|
|
|
|
|
|
|
|
|
|
updateBranchFiltersCounter(int value) {
|
|
|
|
|
branchFiltersCounter = value;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double branchFilterCurrentDistance = 25.0;
|
|
|
|
|
|
|
|
|
|
updateBranchFilterCurrentDistance(double value) {
|
|
|
|
|
branchFilterCurrentDistance = value;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Provider Filter
|
|
|
|
|
List<DropValue> branchFilterProviderSearchHistory = [];
|
|
|
|
|
|
|
|
|
|
void removeBranchFilterProviderSearchHistory({bool isClear = false, required int index}) {
|
|
|
|
|
if (isClear) {
|
|
|
|
|
branchFilterProviderSearchHistory.clear();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
branchFilterProviderSearchHistory.removeAt(index);
|
|
|
|
|
if (branchFilterProviderSearchHistory.isEmpty) {
|
|
|
|
|
updateBranchFiltersCounter(branchFiltersCounter - 1);
|
|
|
|
|
// branchFilterSelectedProviderId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addBranchFilterProviderSearchHistory({required DropValue value}) {
|
|
|
|
|
if (branchFilterProviderSearchHistory.isEmpty) {
|
|
|
|
|
updateBranchFiltersCounter(branchFiltersCounter + 1);
|
|
|
|
|
}
|
|
|
|
|
branchFilterProviderSearchHistory.add(value);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SelectionModel branchFilterSelectedProviderId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
|
addBranchFilterProviderSearchHistory(value: providerDrop);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
branchFilterSelectedProviderId = id;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Category Filter
|
|
|
|
|
List<DropValue> branchFilterCategorySearchHistory = [];
|
|
|
|
|
|
|
|
|
|
void removeBranchFilterCategorySearchHistory({bool isClear = false, required int index}) {
|
|
|
|
|
if (isClear) {
|
|
|
|
|
branchFilterCategorySearchHistory.clear();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
branchFilterCategorySearchHistory.removeAt(index);
|
|
|
|
|
if (branchFilterCategorySearchHistory.isEmpty) {
|
|
|
|
|
updateBranchFiltersCounter(branchFiltersCounter - 1);
|
|
|
|
|
// branchFilterSelectedCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addBranchFilterCategorySearchHistory({required DropValue value}) {
|
|
|
|
|
if (branchFilterCategorySearchHistory.isEmpty) {
|
|
|
|
|
updateBranchFiltersCounter(branchFiltersCounter + 1);
|
|
|
|
|
}
|
|
|
|
|
branchFilterCategorySearchHistory.add(value);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SelectionModel branchFilterSelectedCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
|
addBranchFilterCategorySearchHistory(value: categoryDrop);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
branchFilterSelectedCategoryId = id;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Services Filter
|
|
|
|
|
List<DropValue> branchFilterServicesSearchHistory = [];
|
|
|
|
|
|
|
|
|
|
void removeBranchFilterServicesSearchHistory({bool isClear = false, required int index}) {
|
|
|
|
|
if (isClear) {
|
|
|
|
|
branchFilterServicesSearchHistory.clear();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
branchFilterServicesSearchHistory.removeAt(index);
|
|
|
|
|
if (branchFilterServicesSearchHistory.isEmpty) {
|
|
|
|
|
updateBranchFiltersCounter(branchFiltersCounter - 1);
|
|
|
|
|
// branchFilterSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addBranchFilterServicesSearchHistory({required DropValue value}) {
|
|
|
|
|
if (branchFilterServicesSearchHistory.isEmpty) {
|
|
|
|
|
updateBranchFiltersCounter(branchFiltersCounter + 1);
|
|
|
|
|
}
|
|
|
|
|
branchFilterServicesSearchHistory.add(value);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SelectionModel branchFilterSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
|
addBranchFilterServicesSearchHistory(value: serviceDrop);
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
branchFilterSelectedServiceId = id;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ifAlreadyExist({required List<DropValue> list, required DropValue value}) {
|
|
|
|
|
int index = list.indexWhere((element) {
|
|
|
|
|
return element.id == value.id;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Rating filter
|
|
|
|
|
|
|
|
|
|
double branchFilterByRating = 4.0;
|
|
|
|
|
|
|
|
|
|
updateBranchFilterByRating(double value) {
|
|
|
|
|
branchFilterByRating = value;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DropValue> categoryDropList = [];
|
|
|
|
|
List<DropValue> servicesDropList = [];
|
|
|
|
|
List<DropValue> providersDropList = [];
|
|
|
|
|
|
|
|
|
|
Future<void> fetchAllProviders() async {
|
|
|
|
|
if (providersDropList.isNotEmpty) return;
|
|
|
|
|
|
|
|
|
|
providersDropList.clear();
|
|
|
|
|
setOnlyState(ViewState.busy);
|
|
|
|
|
List<ProviderBasicDataModel> providers = await branchRepo.getAllProvidersWitheBasicData();
|
|
|
|
|
for (var element in providers) {
|
|
|
|
|
providersDropList.add(
|
|
|
|
|
DropValue(element.id ?? 0, element.providerName ?? "N/A", ""),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> fetchAllCategories(String countryCode) async {
|
|
|
|
|
if (categoryDropList.isNotEmpty) return;
|
|
|
|
|
categoryDropList.clear();
|
|
|
|
|
setOnlyState(ViewState.busy);
|
|
|
|
|
Category category = await branchRepo.fetchBranchCategory();
|
|
|
|
|
category.data?.forEach((element) {
|
|
|
|
|
categoryDropList.add(
|
|
|
|
|
DropValue(
|
|
|
|
|
element.id ?? 0,
|
|
|
|
|
((element.categoryName!.isEmpty
|
|
|
|
|
? "N/A"
|
|
|
|
|
: countryCode == "SA"
|
|
|
|
|
? element.categoryNameN
|
|
|
|
|
: element.categoryName) ??
|
|
|
|
|
"N/A"),
|
|
|
|
|
""),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> fetchAllServices() async {
|
|
|
|
|
if (servicesDropList.isNotEmpty) return;
|
|
|
|
|
servicesDropList.clear();
|
|
|
|
|
setState(ViewState.busy);
|
|
|
|
|
Services services = await branchRepo.fetchServicesByCategoryId(serviceCategoryId: -1); // to get all services
|
|
|
|
|
|
|
|
|
|
for (var element in services.data!) {
|
|
|
|
|
servicesDropList.add(
|
|
|
|
|
DropValue(
|
|
|
|
|
element.id ?? 0,
|
|
|
|
|
element.description ?? "N/A",
|
|
|
|
|
"",
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> populateDataForBranchesFilter() async {
|
|
|
|
|
await fetchAllProviders(); // saudi arabia
|
|
|
|
|
await fetchAllCategories("SA"); // saudi arabia
|
|
|
|
|
await fetchAllServices(); // saudi arabia
|
|
|
|
|
updateBranchFilterCurrentDistance(25.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearBranchFilters() {
|
|
|
|
|
branchFilterServicesSearchHistory.clear();
|
|
|
|
|
branchFilterCategorySearchHistory.clear();
|
|
|
|
|
branchFilterProviderSearchHistory.clear();
|
|
|
|
|
branchFilterByRating = 4.0;
|
|
|
|
|
branchFilterCurrentDistance = 25.0;
|
|
|
|
|
branchFiltersCounter = 0;
|
|
|
|
|
clearBranchFilterSelections();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearBranchFilterSelections() {
|
|
|
|
|
branchFilterSelectedProviderId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
branchFilterSelectedCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
branchFilterSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> getBranchesBasedOnFilters() async {
|
|
|
|
|
nearbyBranches.clear();
|
|
|
|
|
setState(ViewState.busy);
|
|
|
|
|
List<int> providersIdsList = [];
|
|
|
|
|
if (branchFilterProviderSearchHistory.isNotEmpty) {
|
|
|
|
|
for (var element in branchFilterProviderSearchHistory) {
|
|
|
|
|
providersIdsList.add(element.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<int> categoryIdsList = [];
|
|
|
|
|
if (branchFilterCategorySearchHistory.isNotEmpty) {
|
|
|
|
|
for (var element in branchFilterCategorySearchHistory) {
|
|
|
|
|
categoryIdsList.add(element.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<int> servicesIdsList = [];
|
|
|
|
|
if (branchFilterServicesSearchHistory.isNotEmpty) {
|
|
|
|
|
for (var element in branchFilterServicesSearchHistory) {
|
|
|
|
|
servicesIdsList.add(element.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nearbyBranches = await branchRepo.getBranchesByFilters(
|
|
|
|
|
providerIdsList: providersIdsList.isNotEmpty ? providersIdsList : null,
|
|
|
|
|
categoryIdsList: categoryIdsList.isNotEmpty ? categoryIdsList : null,
|
|
|
|
|
serviceIdsList: servicesIdsList.isNotEmpty ? servicesIdsList : null,
|
|
|
|
|
distanceKm: branchFilterCurrentDistance.toInt(),
|
|
|
|
|
rating: branchFilterByRating.toInt(),
|
|
|
|
|
latitude: 24.694969,
|
|
|
|
|
longitude: 46.724129,
|
|
|
|
|
);
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> getBranchesBasedOnCategoryFilters({required int categoryId}) async {
|
|
|
|
|
if (categoryId == 0) {
|
|
|
|
|
await getAllNearBranches();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setState(ViewState.busy);
|
|
|
|
|
nearbyBranches.clear();
|
|
|
|
|
nearbyBranches = await branchRepo.getBranchesByFilters(categoryIdsList: [categoryId]);
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Appointments Filter Screen
|
|
|
|
|
|
|
|
|
|
List<DropValue> branchesDropList = [];
|
|
|
|
|
|
|
|
|
|
Future<void> fetchAllBranchesBySelectedProviderId({required List<int> providersIdsList}) async {
|
|
|
|
|
branchesDropList.clear();
|
|
|
|
|
setOnlyState(ViewState.busy);
|
|
|
|
|
List<BranchDetailModel> providers = await branchRepo.getBranchesByFilters(providerIdsList: providersIdsList);
|
|
|
|
|
for (var element in providers) {
|
|
|
|
|
branchesDropList.add(DropValue(element.id ?? 0, element.branchName ?? "N/A", ""));
|
|
|
|
|
}
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
|
|
|
|
|
log("branchesDropList: ${branchesDropList.length}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> populateDataForAppointmentsFilter() async {
|
|
|
|
|
await fetchAllProviders(); // saudi arabia
|
|
|
|
|
await fetchAllCategories("SA"); // saudi arabia
|
|
|
|
|
await fetchAllServices(); // saudi arabia
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int appointmentFiltersCounter = 0;
|
|
|
|
|
|
|
|
|
|
updateAppointmentFiltersCounter(int value) {
|
|
|
|
|
appointmentFiltersCounter = value;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Provider Filter For Appointments
|
|
|
|
|
List<DropValue> appointmentFilterProviderSearchHistory = [];
|
|
|
|
|
|
|
|
|
|
void removeAppointmentFilterProviderSearchHistory({bool isClear = false, required int index}) {
|
|
|
|
|
if (isClear) {
|
|
|
|
|
appointmentFilterProviderSearchHistory.clear();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
appointmentFilterProviderSearchHistory.removeAt(index);
|
|
|
|
|
if (appointmentFilterProviderSearchHistory.isNotEmpty) {
|
|
|
|
|
List<int> providerIdsSelected = [];
|
|
|
|
|
for (var element in appointmentFilterProviderSearchHistory) {
|
|
|
|
|
providerIdsSelected.add(element.id);
|
|
|
|
|
}
|
|
|
|
|
fetchAllBranchesBySelectedProviderId(providersIdsList: providerIdsSelected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (appointmentFilterProviderSearchHistory.isEmpty) {
|
|
|
|
|
updateAppointmentFiltersCounter(appointmentFiltersCounter - 1);
|
|
|
|
|
// appointmentFilterSelectedProviderId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addAppointmentFilterProviderSearchHistory({required DropValue value}) {
|
|
|
|
|
if (appointmentFilterProviderSearchHistory.isEmpty) {
|
|
|
|
|
updateAppointmentFiltersCounter(appointmentFiltersCounter + 1);
|
|
|
|
|
}
|
|
|
|
|
List<int> providerIdsSelected = [];
|
|
|
|
|
for (var element in appointmentFilterProviderSearchHistory) {
|
|
|
|
|
providerIdsSelected.add(element.id);
|
|
|
|
|
}
|
|
|
|
|
fetchAllBranchesBySelectedProviderId(providersIdsList: providerIdsSelected);
|
|
|
|
|
appointmentFilterProviderSearchHistory.add(value);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SelectionModel appointmentFilterSelectedProviderId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
|
addAppointmentFilterProviderSearchHistory(value: providerDrop);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// appointmentFilterSelectedProviderId = id;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Branches Filter For Appointments
|
|
|
|
|
|
|
|
|
|
List<DropValue> appointmentFilterBranchSearchHistory = [];
|
|
|
|
|
|
|
|
|
|
void removeAppointmentFilterBranchSearchHistory({bool isClear = false, required int index}) {
|
|
|
|
|
if (isClear) {
|
|
|
|
|
appointmentFilterBranchSearchHistory.clear();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
appointmentFilterBranchSearchHistory.removeAt(index);
|
|
|
|
|
if (appointmentFilterBranchSearchHistory.isEmpty) {
|
|
|
|
|
updateAppointmentFiltersCounter(appointmentFiltersCounter - 1);
|
|
|
|
|
// appointmentFilterSelectedBranchId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addAppointmentFilterBranchSearchHistory({required DropValue value}) {
|
|
|
|
|
if (appointmentFilterBranchSearchHistory.isEmpty) {
|
|
|
|
|
updateAppointmentFiltersCounter(appointmentFiltersCounter + 1);
|
|
|
|
|
}
|
|
|
|
|
appointmentFilterBranchSearchHistory.add(value);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SelectionModel appointmentFilterSelectedBranchId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
|
addAppointmentFilterBranchSearchHistory(value: branchesDrop);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// appointmentFilterSelectedBranchId = id;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Category Filter For Appointments
|
|
|
|
|
|
|
|
|
|
List<DropValue> appointmentFilterCategorySearchHistory = [];
|
|
|
|
|
|
|
|
|
|
void removeAppointmentFilterCategorySearchHistory({bool isClear = false, required int index}) {
|
|
|
|
|
if (isClear) {
|
|
|
|
|
appointmentFilterCategorySearchHistory.clear();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
appointmentFilterCategorySearchHistory.removeAt(index);
|
|
|
|
|
if (appointmentFilterCategorySearchHistory.isEmpty) {
|
|
|
|
|
updateAppointmentFiltersCounter(appointmentFiltersCounter - 1);
|
|
|
|
|
// appointmentFilterSelectedCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addAppointmentFilterCategorySearchHistory({required DropValue value}) {
|
|
|
|
|
if (appointmentFilterCategorySearchHistory.isEmpty) {
|
|
|
|
|
updateAppointmentFiltersCounter(appointmentFiltersCounter + 1);
|
|
|
|
|
}
|
|
|
|
|
appointmentFilterCategorySearchHistory.add(value);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SelectionModel appointmentFilterSelectedCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
|
addAppointmentFilterCategorySearchHistory(value: categoryDrop);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// appointmentFilterSelectedCategoryId = id;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DropValue> appointmentFilterServicesSearchHistory = [];
|
|
|
|
|
|
|
|
|
|
void removeAppointmentFilterServicesSearchHistory({bool isClear = false, required int index}) {
|
|
|
|
|
if (isClear) {
|
|
|
|
|
appointmentFilterServicesSearchHistory.clear();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
appointmentFilterServicesSearchHistory.removeAt(index);
|
|
|
|
|
if (appointmentFilterServicesSearchHistory.isEmpty) {
|
|
|
|
|
updateAppointmentFiltersCounter(appointmentFiltersCounter - 1);
|
|
|
|
|
// appointmentFilterSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addAppointmentFilterServicesSearchHistory({required DropValue value}) {
|
|
|
|
|
if (appointmentFilterServicesSearchHistory.isEmpty) {
|
|
|
|
|
updateAppointmentFiltersCounter(appointmentFiltersCounter + 1);
|
|
|
|
|
}
|
|
|
|
|
appointmentFilterServicesSearchHistory.add(value);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SelectionModel appointmentFilterSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
|
addAppointmentFilterServicesSearchHistory(value: servicesDrop);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// appointmentFilterSelectedServiceId = id;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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: "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearAppointmentFilters() {
|
|
|
|
|
appointmentFilterServicesSearchHistory.clear();
|
|
|
|
|
appointmentFilterCategorySearchHistory.clear();
|
|
|
|
|
appointmentFilterProviderSearchHistory.clear();
|
|
|
|
|
appointmentFilterBranchSearchHistory.clear();
|
|
|
|
|
appointmentFiltersCounter = 0;
|
|
|
|
|
clearAppointmentFilterSelections();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> getAppointmentsBasedOnFilters() async {
|
|
|
|
|
nearbyBranches.clear();
|
|
|
|
|
setState(ViewState.busy);
|
|
|
|
|
List<int> providersIdsList = [];
|
|
|
|
|
if (appointmentFilterProviderSearchHistory.isNotEmpty) {
|
|
|
|
|
for (var element in appointmentFilterProviderSearchHistory) {
|
|
|
|
|
providersIdsList.add(element.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<int> categoryIdsList = [];
|
|
|
|
|
if (appointmentFilterCategorySearchHistory.isNotEmpty) {
|
|
|
|
|
for (var element in appointmentFilterCategorySearchHistory) {
|
|
|
|
|
categoryIdsList.add(element.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<int> servicesIdsList = [];
|
|
|
|
|
if (appointmentFilterServicesSearchHistory.isNotEmpty) {
|
|
|
|
|
for (var element in appointmentFilterServicesSearchHistory) {
|
|
|
|
|
servicesIdsList.add(element.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<int> branchesIdsList = [];
|
|
|
|
|
if (appointmentFilterBranchSearchHistory.isNotEmpty) {
|
|
|
|
|
for (var element in appointmentFilterBranchSearchHistory) {
|
|
|
|
|
branchesIdsList.add(element.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|