@ -38,9 +38,11 @@ import 'package:mc_common_app/view_models/dashboard_view_model_customer.dart';
import ' package:mc_common_app/view_models/payment_view_model.dart ' ;
import ' package:mc_common_app/views/appointments/book_appointment_schedules_view.dart ' ;
import ' package:mc_common_app/views/appointments/widgets/appointment_service_pick_bottom_sheet.dart ' ;
import ' package:mc_common_app/widgets/button/show_fill_button.dart ' ;
import ' package:mc_common_app/widgets/common_widgets/info_bottom_sheet.dart ' ;
import ' package:mc_common_app/widgets/dropdown/dropdow_field.dart ' ;
import ' package:mc_common_app/widgets/extensions/extensions_widget.dart ' ;
import ' package:mc_common_app/widgets/txt_field.dart ' ;
import ' package:provider/provider.dart ' ;
import ' package:easy_localization/easy_localization.dart ' ;
@ -81,6 +83,7 @@ class AppointmentsVM extends BaseVM {
bool ifItemAlreadySelected ( int id ) {
int indexFound = allSelectedItemsInAppointments . indexWhere ( ( element ) = > element . id = = id ) ;
log ( " already selected at: $ indexFound " ) ;
if ( indexFound ! = - 1 ) {
return true ;
}
@ -101,6 +104,7 @@ class AppointmentsVM extends BaseVM {
}
resetCategorySelectionBottomSheet ( ) ;
notifyListeners ( ) ;
}
}
@ -248,16 +252,16 @@ class AppointmentsVM extends BaseVM {
notifyListeners ( ) ;
}
String pickedHomeLocation = " " ;
void updatePickedHomeLocation ( String value ) {
pickedHomeLocation = value ;
pickHomeLocationError = " " ;
if ( currentServiceSelection ! = null ) {
currentServiceSelection ! . homeLocation = value ;
}
notifyListeners ( ) ;
}
/ / String pickedHomeLocation = " " ;
/ /
/ / void updatePickedHomeLocation ( String value ) {
/ / pickedHomeLocation = value ;
/ / pickHomeLocationError = " " ;
/ / if ( currentServiceSelection ! = null ) {
/ / currentServiceSelection ! . homeLocation = value ;
/ / }
/ / notifyListeners ( ) ;
/ / }
SelectionModel branchSelectedCategoryId = SelectionModel ( selectedOption: " " , selectedId: - 1 , errorValue: " " ) ;
@ -272,10 +276,23 @@ class AppointmentsVM extends BaseVM {
List < ServiceModel > servicesInCurrentAppointment = [ ] ;
ServiceModel ? currentServiceSelection ;
CurrentLocationInfoModel ? currentLocationInfoModel ;
void updateCurrentLocationInfoModel ( CurrentLocationInfoModel ? value ) {
currentLocationInfoModel = value ;
pickHomeLocationError = " " ;
if ( currentServiceSelection ! = null & & value ! = null ) {
currentServiceSelection ! . homeLocation = value . address ;
}
notifyListeners ( ) ;
}
void updateBranchServiceId ( SelectionModel id ) async {
branchSelectedServiceId = id ;
currentServiceSelection = branchServices . firstWhere ( ( element ) = > element . serviceProviderServiceId = = id . selectedId ) ;
if ( currentLocationInfoModel ! = null ) {
currentLocationInfoModel ! . homeChargesInCurrentService = double . parse ( currentServiceSelection ! . rangePricePerKm ? ? " 0.0 " ) ;
}
log ( " currentServiceSelection isAllowAppointmentHome: ${ currentServiceSelection ! . isAllowAppointmentHome } " ) ;
log ( " currentServiceSelection serviceDescription: ${ currentServiceSelection ! . serviceDescription } " ) ;
notifyListeners ( ) ;
@ -308,6 +325,7 @@ class AppointmentsVM extends BaseVM {
}
servicesInCurrentAppointment . clear ( ) ;
servicesInCurrentAppointment = [ ] ;
currentLocationInfoModel = null ;
log ( " here servicesInCurrentAppointment: ${ servicesInCurrentAppointment . length } " ) ;
}
@ -547,6 +565,7 @@ class AppointmentsVM extends BaseVM {
double amountToPayForAppointment = 0.0 ;
double totalAmount = 0.0 ;
double totalLocationCharges = 0.0 ;
List < ItemData > serviceItemsFromApi = [ ] ;
@ -557,42 +576,35 @@ class AppointmentsVM extends BaseVM {
void onItemUpdateOrSelected ( int index , bool selected , int itemId ) {
int serviceIndex = servicesInCurrentAppointment . indexWhere ( ( element ) = > element . serviceId = = currentServiceSelection ! . serviceId ! ) ;
/ / log ( " currentServiceSelection!.allSelectedItemsInAppointments: ${ allSelectedItemsInAppointments . length } " ) ;
/ / log ( " currentServiceSelection!.serviceItems: ${ currentServiceSelection ! . serviceItems ! . length } " ) ;
/ / log ( " index: $ index " ) ;
/ / log ( " selected: $ selected " ) ;
/ / log ( " itemId: $ itemId " ) ;
/ / log ( " servicesInCurrentAppointment: ${ servicesInCurrentAppointment . length } " ) ;
serviceItemsFromApi [ index ] . isUpdateOrSelected = selected ;
serviceItemsFromApi [ index ] . isHomeSelected = isHomeTapped ;
log ( " serviceI temsFromApi[i ndex].isHomeSelected : $ { serviceI temsFromApi[ i ndex] . isHomeSelected } " ) ;
log ( " serviceIndex: $ serviceIndex " ) ;
if ( selected ) {
selectedSubServicesCounter = selectedSubServicesCounter + 1 ;
selectSubServicesError = " " ;
currentServiceSelection ! . serviceItems ! . add ( serviceItemsFromApi [ index ] ) ;
allSelectedItemsInAppointments . add ( serviceItemsFromApi [ index ] ) ;
/ / for ( var element in allSelectedItemsInAppointments ) {
if ( ! ifItemAlreadySelected ( serviceItemsFromApi [ index ] . id ! ) ) {
currentServiceSelection ! . serviceItems ! . add ( serviceItemsFromApi [ index ] ) ;
allSelectedItemsInAppointments . add ( serviceItemsFromApi [ index ] ) ;
log ( " Here with: ${ serviceItemsFromApi [ index ] . description } " ) ;
if ( serviceIndex ! = - 1 ) {
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 " ) ;
}
}
/ / }
} else {
/ / log ( " currentServiceSelection!.serviceItems: ${ currentServiceSelection ! . serviceItems ! . length } " ) ;
selectedSubServicesCounter = selectedSubServicesCounter - 1 ;
currentServiceSelection ! . serviceItems ! . removeWhere ( ( element ) = > element . id = = itemId ) ;
/ / log ( " currentServiceSelection!.serviceItems: ${ currentServiceSelection ! . serviceItems ! . length } " ) ;
allSelectedItemsInAppointments . removeWhere ( ( element ) = > element . id = = itemId ) ;
if ( serviceIndex ! = - 1 ) {
servicesInCurrentAppointment [ serviceIndex ] . currentTotalServicePrice =
servicesInCurrentAppointment [ serviceIndex ] . currentTotalServicePrice - double . parse ( ( serviceItemsFromApi [ index ] . price ) ? ? " 0.0 " ) ;
servicesInCurrentAppointment [ serviceIndex ] . serviceItems ! . removeWhere ( ( element ) = > element . id = = itemId ) ;
if ( servicesInCurrentAppointment [ serviceIndex ] . currentTotalServicePrice < 0.0 ) {
servicesInCurrentAppointment [ serviceIndex ] . currentTotalServicePrice = servicesInCurrentAppointment [ serviceIndex ] . currentTotalServicePrice * - 1 ;
}
/ / servicesInCurrentAppointment [ serviceIndex ] . serviceItems ! . removeWhere ( ( element ) = > element . id = = itemId ) ;
}
}
@ -614,9 +626,11 @@ class AppointmentsVM extends BaseVM {
setState ( ViewState . busy ) ;
serviceItemsFromApi . clear ( ) ;
serviceItemsFromApi = await branchRepo . getServiceItems ( serviceId ) ;
selectedSubServicesCounter = 0 ;
for ( var item in serviceItemsFromApi ) {
if ( ifItemAlreadySelected ( item . id ! ) ) {
item . isUpdateOrSelected = true ;
selectedSubServicesCounter + + ;
}
}
setState ( ViewState . idle ) ;
@ -639,7 +653,7 @@ class AppointmentsVM extends BaseVM {
}
if ( isHomeTapped ) {
if ( pickedHomeLocation = = " " ) {
if ( currentLocationInfoModel = = null | | currentLocationInfoModel ! . address = = " " ) {
updatePickHomeLocationError ( GlobalConsts . homeLocationEmptyError ) ;
return false ;
}
@ -683,8 +697,7 @@ class AppointmentsVM extends BaseVM {
isScrollControlled: true ,
enableDrag: true ,
builder: ( BuildContext context ) {
/ / TODO: It should be calculated from API
double totalKms = 15.3 ;
double totalKms = double . parse ( selectedService . distanceToHomeInKms . toStringAsFixed ( 2 ) ) ;
return InfoBottomSheet (
title: LocaleKeys . chargesBreakdown . tr ( ) . toText ( fontSize: 24 , isBold: true ) ,
description: Column (
@ -723,7 +736,7 @@ class AppointmentsVM extends BaseVM {
Row (
mainAxisAlignment: MainAxisAlignment . end ,
children: [
" ${ ( double . parse ( selectedService . rangePricePerKm ! ) ) * totalKms } ${ LocaleKeys . sar . tr ( ) } " . toText ( fontSize: 16 , isBold: true ) ,
" ${ ( ( double . parse ( selectedService . rangePricePerKm ! ) ) * totalKms ) . toStringAsFixed ( 2 ) } ${ LocaleKeys . sar . tr ( ) } " . toText ( fontSize: 16 , isBold: true ) ,
] ,
) ,
] ,
@ -736,7 +749,7 @@ class AppointmentsVM extends BaseVM {
crossAxisAlignment: CrossAxisAlignment . end ,
children: [
( selectedService . isHomeSelected
? " ${ ( selectedService . currentTotalServicePrice ) + ( ( double . parse ( ( selectedService . rangePricePerKm ? ? " 0.0 " ) ) * totalKms ) ) } "
? ( ( selectedService . currentTotalServicePrice ) + ( double . parse ( ( selectedService . rangePricePerKm ? ? " 0.0 " ) ) * totalKms ) ) . toStringAsFixed ( 2 )
: " ${ selectedService . currentTotalServicePrice } " )
. toText ( fontSize: 29 , isBold: true ) ,
2. width ,
@ -813,10 +826,20 @@ class AppointmentsVM extends BaseVM {
return ;
}
totalAmount = 0.0 ;
totalLocationCharges = 0.0 ;
amountToPayForAppointment = 0.0 ;
for ( var schedule in serviceAppointmentScheduleList ) {
amountToPayForAppointment = amountToPayForAppointment + ( schedule . amountToPay ? ? 0.0 ) ;
totalAmount = totalAmount + ( schedule . amountTotal ? ? 0.0 ) ;
for ( var service in schedule . servicesListInAppointment ! ) {
int index = servicesInCurrentAppointment . indexWhere ( ( element ) = > element . serviceProviderServiceId = = service . serviceProviderServiceId ) ;
if ( index ! = - 1 ) {
if ( servicesInCurrentAppointment [ index ] . isHomeSelected ) {
totalAmount = totalAmount + ( ( servicesInCurrentAppointment [ index ] . distanceToHomeInKms ) * double . parse ( servicesInCurrentAppointment [ index ] . rangePricePerKm ! ) ) ;
totalLocationCharges = totalLocationCharges + ( servicesInCurrentAppointment [ index ] . distanceToHomeInKms * double . parse ( servicesInCurrentAppointment [ index ] . rangePricePerKm ! ) ) ;
}
}
}
}
Utils . hideLoading ( context ) ;
@ -890,7 +913,90 @@ class AppointmentsVM extends BaseVM {
}
}
/ / BRANCHES RELATED
/ / REPORT A COMPLAINT
String complaintDescription = " " ;
String complaintDescriptionError = " " ;
void updateComplaintDescription ( String value ) {
complaintDescription = value ;
if ( value . isNotEmpty ) {
complaintDescriptionError = " " ;
}
}
Future buildComplaintBottomSheet ( { required int customerID , required int complainType , required String customerName , required BuildContext context } ) {
return showModalBottomSheet (
context: context ,
isScrollControlled: true ,
enableDrag: true ,
builder: ( BuildContext context ) {
return InfoBottomSheet (
title: LocaleKeys . reportComplaint . tr ( ) . toText ( fontSize: 28 , isBold: true , letterSpacing: - 1.44 ) ,
description: Padding (
padding: EdgeInsets . only ( bottom: MediaQuery . of ( context ) . viewInsets . bottom ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
if ( customerName . isNotEmpty ) . . . [
( " ${ LocaleKeys . customerName . tr ( ) } : $ customerName " ) . toText ( fontSize: 15 , color: MyColors . lightTextColor ) ,
] ,
10. height ,
TxtField (
maxLines: 5 ,
value: complaintDescription ,
errorValue: complaintDescriptionError ,
keyboardType: TextInputType . text ,
hint: LocaleKeys . description . tr ( ) ,
onChanged: ( v ) = > updateComplaintDescription ( v ) ,
) ,
25. height ,
ShowFillButton (
title: LocaleKeys . submit . tr ( ) ,
onPressed: ( ) async {
if ( complaintDescription . isEmpty ) {
Utils . showToast ( LocaleKeys . descriptionCannotBeEmpty . tr ( ) ) ;
return ;
}
final status = await reportComplaintAgainstCustomer (
customerID: customerID ,
comment: complaintDescription ,
complaintType: complainType , / / 1 for Appointment and 2 for Requests
context: context ,
) ;
if ( status ) {
updateComplaintDescription ( " " ) ;
pop ( context ) ;
}
} ,
maxWidth: double . infinity ,
) ,
19. height ,
] ,
) ,
) ,
) ;
} ,
) ;
}
Future < bool > reportComplaintAgainstCustomer ( { required int customerID , required String comment , required int complaintType , required BuildContext context } ) async {
Utils . showLoading ( context ) ;
try {
GenericRespModel genericRespModel = await commonRepo . createComplainFromProvider ( customerId: customerID , comment: comment , complainType: complaintType ) ;
Utils . showToast ( genericRespModel . message . toString ( ) ) ;
Utils . hideLoading ( context ) ;
return genericRespModel . messageStatus = = 1 ;
} catch ( e , s ) {
logger . e ( s ) ;
Utils . hideLoading ( context ) ;
Utils . showToast ( e . toString ( ) ) ;
return false ;
}
}
/ / BRANCHES RELATED
List < BranchDetailModel > nearbyBranches = [ ] ;
List < BranchDetailModel > myRecentBranches = [ ] ;
@ -960,7 +1066,6 @@ class AppointmentsVM extends BaseVM {
Future < void > getBranchServices ( { required int categoryId } ) async {
branchSelectedServiceId = SelectionModel ( selectedOption: " " , selectedId: - 1 , errorValue: " " ) ;
isHomeTapped = false ;
pickedHomeLocation = " " ;
pickHomeLocationError = " " ;
if ( categoryId ! = - 1 ) {
isFetchingServices = true ;
@ -1643,3 +1748,19 @@ class AppointmentsVM extends BaseVM {
/ / }
}
}
class CurrentLocationInfoModel {
final String address ;
final double latitude ;
final double longitude ;
final double distanceFromCurrent ;
double homeChargesInCurrentService ;
CurrentLocationInfoModel ( {
required this . address ,
required this . latitude ,
required this . longitude ,
required this . distanceFromCurrent ,
required this . homeChargesInCurrentService ,
} ) ;
}