|
|
|
@ -1,6 +1,8 @@
|
|
|
|
import 'package:car_customer_app/repositories/provider_repo.dart';
|
|
|
|
import 'package:car_customer_app/repositories/provider_repo.dart';
|
|
|
|
import 'package:car_customer_app/repositories/schedule_repo.dart';
|
|
|
|
import 'package:car_customer_app/repositories/schedule_repo.dart';
|
|
|
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:mc_common_app/classes/consts.dart';
|
|
|
|
import 'package:mc_common_app/classes/consts.dart';
|
|
|
|
|
|
|
|
import 'package:mc_common_app/config/routes.dart';
|
|
|
|
import 'package:mc_common_app/models/appointments_models/appointment_list_model.dart';
|
|
|
|
import 'package:mc_common_app/models/appointments_models/appointment_list_model.dart';
|
|
|
|
import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart';
|
|
|
|
import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart';
|
|
|
|
import 'package:mc_common_app/models/provider_branches_models/provider_profile_model.dart';
|
|
|
|
import 'package:mc_common_app/models/provider_branches_models/provider_profile_model.dart';
|
|
|
|
@ -11,6 +13,8 @@ import 'package:mc_common_app/models/widgets_models.dart';
|
|
|
|
import 'package:mc_common_app/repositories/common_repo.dart';
|
|
|
|
import 'package:mc_common_app/repositories/common_repo.dart';
|
|
|
|
import 'package:mc_common_app/services/common_services.dart';
|
|
|
|
import 'package:mc_common_app/services/common_services.dart';
|
|
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
|
|
|
|
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
|
|
|
|
|
|
import 'package:mc_common_app/utils/utils.dart';
|
|
|
|
import 'package:mc_common_app/view_models/base_view_model.dart';
|
|
|
|
import 'package:mc_common_app/view_models/base_view_model.dart';
|
|
|
|
import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
|
|
|
|
import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
|
|
|
|
|
|
|
|
|
|
|
|
@ -47,24 +51,61 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> mergeServiceIntoAvailableSchedules() async {
|
|
|
|
Future<void> mergeServiceIntoAvailableSchedules() async {
|
|
|
|
List<String> serviceItemIds = [];
|
|
|
|
List<String> serviceItemIds = [];
|
|
|
|
serviceItems.forEach((serviceItem) {
|
|
|
|
currentServiceSelection!.serviceItems!.forEach((serviceItem) {
|
|
|
|
if (serviceItem.isUpdateOrSelected!) {
|
|
|
|
if (serviceItem.isUpdateOrSelected!) {
|
|
|
|
serviceItemIds.add(serviceItem.id!.toString());
|
|
|
|
serviceItemIds.add(serviceItem.id!.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var scheduleList = await scheduleRepo.mergeServiceIntoAvailableSchedules(serviceItemIds: serviceItemIds);
|
|
|
|
|
|
|
|
serviceAppointmentScheduleList.addAll(scheduleList);
|
|
|
|
servicesInCurrentAppointment.add(currentServiceSelection!);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
serviceAppointmentScheduleList = await scheduleRepo.mergeServiceIntoAvailableSchedules(
|
|
|
|
|
|
|
|
serviceItemIds: serviceItemIds,
|
|
|
|
|
|
|
|
appointmentType: isHomeTapped ? 2 : 1, // AppointmentType 1 for workshop and 2 for Home based schedule.
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
servicesInSchedule.clear();
|
|
|
|
servicesInSchedule.clear();
|
|
|
|
serviceAppointmentScheduleList.forEach((schedule) {
|
|
|
|
|
|
|
|
schedule.serviceItemList!.forEach((item) {
|
|
|
|
if (serviceAppointmentScheduleList.isEmpty) {
|
|
|
|
if (!ifItemAlreadyThere(item.serviceProviderServiceId!)) {
|
|
|
|
Utils.showToast("There are no available appointments for selected Items.");
|
|
|
|
servicesInSchedule.add(DropValue(item.serviceProviderServiceId!, item.description!, ""));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
serviceAppointmentScheduleList.forEach(
|
|
|
|
|
|
|
|
(schedule) {
|
|
|
|
|
|
|
|
amountToPayForAppointment = amountToPayForAppointment + (schedule.amountToPay ?? 0.0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
schedule.serviceItemList!.forEach((item) {
|
|
|
|
|
|
|
|
if (!ifItemAlreadyThere(item.serviceProviderServiceId!)) {
|
|
|
|
|
|
|
|
servicesInSchedule.add(DropValue(item.serviceProviderServiceId!, item.description!, ""));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
notifyListeners();
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> onItemsSelectedInService() async {
|
|
|
|
|
|
|
|
if (currentServiceSelection != null) {
|
|
|
|
|
|
|
|
servicesInCurrentAppointment.add(currentServiceSelection!);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> onBookAppointmentPressed(BuildContext context) async {
|
|
|
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
serviceAppointmentScheduleList.forEach((schedule) async {
|
|
|
|
|
|
|
|
List<String> serviceItemIds = [];
|
|
|
|
|
|
|
|
schedule.serviceItemList!.forEach((serviceItem) {
|
|
|
|
|
|
|
|
serviceItemIds.add(serviceItem.id.toString());
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
await scheduleRepo.createServiceAppointment(serviceItemIds: serviceItemIds, serviceSlotID: schedule.selectedCustomTimeDateSlotModel!.date!.slotId);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
Utils.showToast("${e.toString()}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ifItemAlreadyThere(int id) {
|
|
|
|
bool ifItemAlreadyThere(int id) {
|
|
|
|
int index = servicesInSchedule.indexWhere((element) => element.id == id);
|
|
|
|
int index = servicesInSchedule.indexWhere((element) => element.id == id);
|
|
|
|
if (index == -1) {
|
|
|
|
if (index == -1) {
|
|
|
|
@ -99,6 +140,8 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
BranchDetailModel? selectedBranchModel;
|
|
|
|
BranchDetailModel? selectedBranchModel;
|
|
|
|
|
|
|
|
|
|
|
|
List<ServiceModel> branchServices = [];
|
|
|
|
List<ServiceModel> branchServices = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ServiceModel> servicesInCurrentAppointment = [];
|
|
|
|
ServiceModel? currentServiceSelection;
|
|
|
|
ServiceModel? currentServiceSelection;
|
|
|
|
|
|
|
|
|
|
|
|
void updateBranchServiceId(SelectionModel id) async {
|
|
|
|
void updateBranchServiceId(SelectionModel id) async {
|
|
|
|
@ -150,8 +193,70 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
notifyListeners();
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<ItemData> serviceItems = [];
|
|
|
|
updateSelectedAppointmentDate({required int dateIndex, required int scheduleIndex}) {
|
|
|
|
List<ItemData> selectedServiceItems = [];
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex].customTimeDateSlotList!.forEach((element) {
|
|
|
|
|
|
|
|
element.date!.isSelected = false;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
isSelected: true,
|
|
|
|
|
|
|
|
slot: "",
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex].selectedCustomTimeDateSlotModel = CustomTimeDateSlotModel(date: date);
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateSelectedAppointmentSlotByDate({required int scheduleIndex, required int slotIndex}) {
|
|
|
|
|
|
|
|
serviceAppointmentScheduleList[scheduleIndex].customTimeDateSlotList!.forEach((element) {
|
|
|
|
|
|
|
|
element.availableSlots!.forEach((element) => 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!;
|
|
|
|
|
|
|
|
print("here: ${serviceAppointmentScheduleList[scheduleIndex].customTimeDateSlotList![index].availableSlots![slotIndex].slotId}");
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double amountToPayForAppointment = 0.0;
|
|
|
|
|
|
|
|
double totalAmount = 0.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void onReviewButtonPressed(BuildContext context) {
|
|
|
|
|
|
|
|
bool isValidated = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < serviceAppointmentScheduleList.length; i++) {
|
|
|
|
|
|
|
|
final schedule = serviceAppointmentScheduleList[i];
|
|
|
|
|
|
|
|
if (schedule.selectedCustomTimeDateSlotModel == null) {
|
|
|
|
|
|
|
|
isValidated = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (schedule.selectedCustomTimeDateSlotModel!.date == null || !schedule.selectedCustomTimeDateSlotModel!.date!.isSelected) {
|
|
|
|
|
|
|
|
isValidated = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (schedule.selectedCustomTimeDateSlotModel!.availableSlots == null) {
|
|
|
|
|
|
|
|
isValidated = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
TimeSlotModel slot = schedule.selectedCustomTimeDateSlotModel!.availableSlots!.firstWhere((element) => element.isSelected);
|
|
|
|
|
|
|
|
if (slot.date.isNotEmpty) {
|
|
|
|
|
|
|
|
isValidated = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isValidated) {
|
|
|
|
|
|
|
|
Utils.showToast("You must select appointment time for each schedule's appointment.");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
navigateWithName(context, AppRoutes.reviewAppointmentView);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ItemData> serviceItemsFromApi = [];
|
|
|
|
ProviderProfileModel? providerProfileModel;
|
|
|
|
ProviderProfileModel? providerProfileModel;
|
|
|
|
|
|
|
|
|
|
|
|
int selectedSubServicesCounter = 0;
|
|
|
|
int selectedSubServicesCounter = 0;
|
|
|
|
@ -162,12 +267,12 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onItemUpdateOrSelected(int index, bool selected, int itemId) {
|
|
|
|
onItemUpdateOrSelected(int index, bool selected, int itemId) {
|
|
|
|
serviceItems[index].isUpdateOrSelected = selected;
|
|
|
|
serviceItemsFromApi[index].isUpdateOrSelected = selected;
|
|
|
|
if (selected) {
|
|
|
|
if (selected) {
|
|
|
|
selectedSubServicesCounter = selectedSubServicesCounter + 1;
|
|
|
|
selectedSubServicesCounter = selectedSubServicesCounter + 1;
|
|
|
|
updateSelectedSubServicesCounter(selectedSubServicesCounter);
|
|
|
|
updateSelectedSubServicesCounter(selectedSubServicesCounter);
|
|
|
|
selectSubServicesError = "";
|
|
|
|
selectSubServicesError = "";
|
|
|
|
currentServiceSelection!.serviceItems!.add(serviceItems[index]);
|
|
|
|
currentServiceSelection!.serviceItems!.add(serviceItemsFromApi[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!selected) {
|
|
|
|
if (!selected) {
|
|
|
|
selectedSubServicesCounter = selectedSubServicesCounter - 1;
|
|
|
|
selectedSubServicesCounter = selectedSubServicesCounter - 1;
|
|
|
|
@ -208,10 +313,10 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<List<ItemData>> getServiceItems(int serviceId) async {
|
|
|
|
Future<List<ItemData>> getServiceItems(int serviceId) async {
|
|
|
|
serviceItems.clear();
|
|
|
|
serviceItemsFromApi.clear();
|
|
|
|
serviceItems = await providerRepo.getServiceItems(serviceId);
|
|
|
|
serviceItemsFromApi = await providerRepo.getServiceItems(serviceId);
|
|
|
|
setState(ViewState.idle);
|
|
|
|
setState(ViewState.idle);
|
|
|
|
return serviceItems;
|
|
|
|
return serviceItemsFromApi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getBranchAndServices(int providerId) async {
|
|
|
|
getBranchAndServices(int providerId) async {
|
|
|
|
@ -263,7 +368,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
|
|
void updatePickHomeLocationError(String value) {
|
|
|
|
void updatePickHomeLocationError(String value) {
|
|
|
|
pickHomeLocationError = value;
|
|
|
|
pickHomeLocationError = value;
|
|
|
|
notifyListeners();
|
|
|
|
// notifyListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool isServiceSelectionValidated() {
|
|
|
|
bool isServiceSelectionValidated() {
|
|
|
|
@ -280,8 +385,8 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool onSubServicesNextPressed() {
|
|
|
|
bool validateItemsSelection() {
|
|
|
|
for (var value in serviceItems) {
|
|
|
|
for (var value in serviceItemsFromApi) {
|
|
|
|
if (value.isUpdateOrSelected!) {
|
|
|
|
if (value.isUpdateOrSelected!) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|