@ -138,7 +138,6 @@ class AppointmentsVM extends BaseVM {
} else {
isSuccess = false ;
Utils . showToast ( element [ ' message ' ] ) ;
return ;
}
} ) ;
@ -230,7 +229,7 @@ class AppointmentsVM extends BaseVM {
Utils . showToast ( genericRespModel . message . toString ( ) ) ;
return ;
}
if ( genericRespModel . messageStatus = = 1 ) {
if ( genericRespModel . messageStatus = = 1 & & AppState ( ) . currentAppType = = AppType . customer ) {
context . read < DashboardVmCustomer > ( ) . onNavbarTapped ( 1 ) ;
applyFilterOnAppointmentsVM ( appointmentStatusEnum: AppointmentStatusEnum . cancelled ) ;
Utils . showToast ( genericRespModel . message . toString ( ) ) ;
@ -240,6 +239,7 @@ class AppointmentsVM extends BaseVM {
navigateReplaceWithNameUntilRoute ( context , AppRoutes . dashboard ) ;
}
} catch ( e ) {
logger . e ( e . toString ( ) ) ;
Utils . showToast ( e . toString ( ) ) ;
}
}
@ -282,19 +282,58 @@ class AppointmentsVM extends BaseVM {
currentLocationInfoModel = value ;
pickHomeLocationError = " " ;
if ( currentServiceSelection ! = null & & value ! = null ) {
currentServiceSelection ! . homeLocation = value . address ;
currentServiceSelection ! . servicelocationInfo = value ;
}
if ( value ! = null ) {
for ( var service in servicesInCurrentAppointment ) {
service . servicelocationInfo . address = value . address ;
service . servicelocationInfo . latitude = value . latitude ;
service . servicelocationInfo . longitude = value . longitude ;
service . servicelocationInfo . distanceToBranch = value . distanceToBranch ;
service . servicelocationInfo . homeChargesInCurrentService = double . parse ( service . rangePricePerKm ? ? " 0.0 " ) ;
}
}
notifyListeners ( ) ;
}
void updateBranchServiceId ( SelectionModel id ) async {
branchSelectedServiceId = id ;
currentServiceSelection = branchServices . firstWhere ( ( element ) = > element . serviceProviderServiceId = = id . selectedId ) ;
if ( currentServiceSelection = = null ) {
return ;
}
servicesInCurrentAppointment . forEach ( ( i ) {
log ( " hlo1: ${ i . serviceDescription } ${ i . servicelocationInfo . homeChargesInCurrentService } " ) ;
} ) ;
if ( ! ( currentServiceSelection ! . isAllowAppointmentHome ? ? false ) ) {
updateIsHomeTapped ( false ) ;
return ;
}
if ( currentLocationInfoModel ! = null ) {
currentLocationInfoModel ! . homeChargesInCurrentService = double . parse ( currentServiceSelection ! . rangePricePerKm ? ? " 0.0 " ) ;
currentServiceSelection ! . servicelocationInfo = CurrentLocationInfoModel (
address: currentLocationInfoModel ! . address ,
latitude: currentLocationInfoModel ! . latitude ,
longitude: currentLocationInfoModel ! . longitude ,
distanceToBranch: currentLocationInfoModel ! . distanceToBranch ,
homeChargesInCurrentService: double . parse ( currentServiceSelection ! . rangePricePerKm ? ? " 0.0 " ) ,
) ;
/ / for ( var service in servicesInCurrentAppointment ) {
/ / service . servicelocationInfo . address = currentLocationInfoModel ! . address ;
/ / service . servicelocationInfo . latitude = currentLocationInfoModel ! . latitude ;
/ / service . servicelocationInfo . longitude = currentLocationInfoModel ! . longitude ;
/ / service . servicelocationInfo . distanceToBranch = currentLocationInfoModel ! . distanceToBranch ;
/ / }
}
log ( " currentServiceSelection isAllowAppointmentHome: ${ currentServiceSelection ! . isAllowAppointmentHome } " ) ;
log ( " currentServiceSelection serviceDescription: ${ currentServiceSelection ! . serviceDescription } " ) ;
servicesInCurrentAppointment . forEach ( ( i ) {
log ( " hlo2: ${ i . serviceDescription } ${ i . servicelocationInfo . homeChargesInCurrentService } " ) ;
} ) ;
notifyListeners ( ) ;
}
@ -565,7 +604,6 @@ class AppointmentsVM extends BaseVM {
double amountToPayForAppointment = 0.0 ;
double totalAmount = 0.0 ;
double totalLocationCharges = 0.0 ;
List < ItemData > serviceItemsFromApi = [ ] ;
@ -697,7 +735,8 @@ class AppointmentsVM extends BaseVM {
isScrollControlled: true ,
enableDrag: true ,
builder: ( BuildContext context ) {
double totalKms = double . parse ( selectedService . distanceToHomeInKms . toStringAsFixed ( 2 ) ) ;
double totalKms = double . parse ( selectedService . servicelocationInfo . distanceToBranch . toStringAsFixed ( 2 ) ) ;
double pricePerKm = double . parse ( selectedService . servicelocationInfo . homeChargesInCurrentService . toStringAsFixed ( 2 ) ) ;
return InfoBottomSheet (
title: LocaleKeys . chargesBreakdown . tr ( ) . toText ( fontSize: 24 , isBold: true ) ,
description: Column (
@ -729,14 +768,14 @@ class AppointmentsVM extends BaseVM {
mainAxisAlignment: MainAxisAlignment . spaceBetween ,
children: [
" ${ totalKms } km " . toText ( fontSize: 12 , color: MyColors . lightTextColor , isBold: true ) ,
" $ {selectedService . rangePricePerKm } x $ totalKms " . toText ( fontSize: 12 , isBold: true ) ,
" $ pricePerKm x $ totalKms " . toText ( fontSize: 12 , isBold: true ) ,
] ,
) ,
8. height ,
Row (
mainAxisAlignment: MainAxisAlignment . end ,
children: [
" ${ ( ( double . p arse( selectedService . rangeP ricePerKm! ) ) * totalKms ) . toStringAsFixed ( 2 ) } ${ LocaleKeys . sar . tr ( ) } " . toText ( fontSize: 16 , isBold: true ) ,
" ${ ( ( p ricePerKm) * totalKms ) . toStringAsFixed ( 2 ) } ${ LocaleKeys . sar . tr ( ) } " . toText ( fontSize: 16 , isBold: true ) ,
] ,
) ,
] ,
@ -748,9 +787,7 @@ class AppointmentsVM extends BaseVM {
Row (
crossAxisAlignment: CrossAxisAlignment . end ,
children: [
( selectedService . isHomeSelected
? ( ( selectedService . currentTotalServicePrice ) + ( double . parse ( ( selectedService . rangePricePerKm ? ? " 0.0 " ) ) * totalKms ) ) . toStringAsFixed ( 2 )
: " ${ selectedService . currentTotalServicePrice } " )
( selectedService . isHomeSelected ? ( ( selectedService . currentTotalServicePrice ) + ( pricePerKm * totalKms ) ) . toStringAsFixed ( 2 ) : " ${ selectedService . currentTotalServicePrice } " )
. toText ( fontSize: 29 , isBold: true ) ,
2. width ,
LocaleKeys . sar . tr ( ) . toText ( color: MyColors . lightTextColor , fontSize: 16 , isBold: true ) . paddingOnly ( bottom: 5 ) ,
@ -798,7 +835,7 @@ class AppointmentsVM extends BaseVM {
void onServicesNextPressed ( BuildContext context ) async {
if ( allSelectedItemsInAppointments . isEmpty ) {
Utils . showToast ( " Please select at least one service. " ) ;
Utils . showToast ( LocaleKeys . pleaseSelectService . tr ( ) ) ;
return ;
}
Utils . showLoading ( context ) ;
@ -806,8 +843,6 @@ class AppointmentsVM extends BaseVM {
List < String > serviceItemIdsForHome = [ ] ;
List < String > serviceItemIdsForWorkshop = [ ] ;
for ( var serviceItem in allSelectedItemsInAppointments ) {
log ( " homeselcted for : ${ serviceItem . isHomeSelected } " ) ;
if ( serviceItem . isHomeSelected ! ) {
serviceItemIdsForHome . add ( serviceItem . id ! . toString ( ) ) ;
} else {
@ -826,7 +861,6 @@ 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 ) ;
@ -835,8 +869,12 @@ class AppointmentsVM extends BaseVM {
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 ! ) ) ;
service . servicelocationInfo = servicesInCurrentAppointment [ index ] . servicelocationInfo ;
schedule . locationInfoModel = servicesInCurrentAppointment [ index ] . servicelocationInfo ;
totalAmount =
totalAmount + ( ( servicesInCurrentAppointment [ index ] . servicelocationInfo . distanceToBranch ) * servicesInCurrentAppointment [ index ] . servicelocationInfo . homeChargesInCurrentService ) ;
schedule . totalLocationCharges = schedule . totalLocationCharges ! +
( servicesInCurrentAppointment [ index ] . servicelocationInfo . distanceToBranch * servicesInCurrentAppointment [ index ] . servicelocationInfo . homeChargesInCurrentService ) ;
}
}
}
@ -1748,19 +1786,3 @@ 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 ,
} ) ;
}