@ -1,4 +1,5 @@
import ' dart:convert ' ;
import ' dart:developer ' ;
import ' dart:io ' ;
import ' package:easy_localization/easy_localization.dart ' ;
@ -6,8 +7,10 @@ import 'package:flutter/cupertino.dart';
import ' package:flutter/material.dart ' ;
import ' package:mc_common_app/classes/app_state.dart ' ;
import ' package:mc_common_app/classes/consts.dart ' ;
import ' package:mc_common_app/extensions/int_extensions.dart ' ;
import ' package:mc_common_app/extensions/string_extensions.dart ' ;
import ' package:mc_common_app/generated/locale_keys.g.dart ' ;
import ' package:mc_common_app/models/appointments_models/appointment_basic_detail_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/widgets_models.dart ' ;
@ -24,12 +27,17 @@ import 'package:mc_common_app/models/user_models/country.dart';
import ' package:mc_common_app/repositories/branch_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/theme/colors.dart ' ;
import ' package:mc_common_app/utils/dialogs_and_bottomsheets.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/ad_view_model.dart ' ;
import ' package:mc_common_app/view_models/base_view_model.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 ' ;
class ServiceVM extends BaseVM {
final BranchRepo branchRepo ;
@ -201,7 +209,6 @@ class ServiceVM extends BaseVM {
}
branchServicesFilterOptions [ serviceStatusEnum . getIdFromServiceStatusEnum ( ) - 1 ] . isSelected = true ; / / - 1 to match with the index
}
/ / Future < String ? > selectFile ( BuildContext context , int index ) async {
@ -264,11 +271,7 @@ class ServiceVM extends BaseVM {
context ,
allowMultiple: false ,
) ;
if ( files ! = null & & files . any ( ( element ) = >
element . path
. split ( ' . ' )
. last
. toLowerCase ( ) ! = ' pdf ' ) ) {
if ( files ! = null & & files . any ( ( element ) = > element . path . split ( ' . ' ) . last . toLowerCase ( ) ! = ' pdf ' ) ) {
Utils . showToast ( " Only PDF Files are allowed " ) ;
return ;
}
@ -282,8 +285,8 @@ class ServiceVM extends BaseVM {
documentID = = 1
? commerceCertificates . addAll ( imageModels )
: documentID = = 2
? commercialCertificates . addAll ( imageModels )
: vatCertificates . addAll ( imageModels ) ;
? commercialCertificates . addAll ( imageModels )
: vatCertificates . addAll ( imageModels ) ;
document ! . data ! [ index ] . document = Utils . convertFileToBase64 ( files . first ) ;
document ! . data ! [ index ] . fileExt = Utils . checkFileExt ( files . first . path ) ;
document ! . data ! [ index ] . documentUrl = files . first . path ;
@ -459,10 +462,10 @@ class ServiceVM extends BaseVM {
DropValue (
element . id ? ? 0 ,
( ( element . categoryName ! . isEmpty
? " N/A "
: countryCode = = " SA "
? element . categoryNameN
: element . categoryName ) ? ?
? " N/A "
: countryCode = = " SA "
? element . categoryNameN
: element . categoryName ) ? ?
" N/A " ) ,
" " ,
) ,
@ -528,6 +531,92 @@ class ServiceVM extends BaseVM {
return await branchRepo . updateService ( map ) ;
}
Future < List < AppointmentBasicDetailsModel > > getAppointmentsByServiceID ( { required BuildContext context , required int branchId , required int serviceId } ) async {
try {
Utils . showLoading ( context ) ;
List < AppointmentBasicDetailsModel > appointmentList = await branchRepo . getAppointmentsByCategoryOrService ( branchId: branchId , serviceId: serviceId ) ;
/ / log ( " list: ${ mResponse . } " ) ;
Utils . hideLoading ( context ) ;
return appointmentList ;
} catch ( e ) {
Utils . hideLoading ( context ) ;
log ( e . toString ( ) ) ;
Utils . showToast ( e . toString ( ) ? ? " " ) ;
return [ ] ;
}
}
Future < bool > updateServiceStatus ( { required BuildContext context , required ServiceStatusEnum serviceStatusEnum , required int branchId , required List < int > providerServiceIds } ) async {
try {
Utils . showLoading ( context ) ;
GenericRespModel genericRespModel = await branchRepo . updateServiceStatus ( branchId: branchId , serviceIds: providerServiceIds , serviceStatusEnum: serviceStatusEnum ) ;
Utils . hideLoading ( context ) ;
Utils . showToast ( genericRespModel . message ? ? " " ) ;
return genericRespModel . messageStatus = = 1 ;
} catch ( e ) {
Utils . hideLoading ( context ) ;
log ( e . toString ( ) ) ;
Utils . showToast ( e . toString ( ) ) ;
return false ;
}
}
Future buildDealNotCompletedBottomSheetOptions ( { required BuildContext mainContext , required List < AppointmentBasicDetailsModel > appointments , required String branchName } ) async {
return actionConfirmationBottomSheet (
isOnlyOneButton: true ,
context: mainContext ,
title: LocaleKeys . notice . tr ( ) . toText ( fontSize: 26 , isBold: true , letterSpacing: - 1.44 ) ,
subtitle: LocaleKeys . youCannotDeactivateThisServiceRightNow . tr ( ) ,
checkBoxConfirmationWidget: ListView . builder (
shrinkWrap: true ,
itemCount: appointments . length ,
itemBuilder: ( BuildContext context , int index ) {
AppointmentBasicDetailsModel appointmentBasicDetailsModel = appointments [ index ] ;
return Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
if ( appointmentBasicDetailsModel . appointmentStatusText ! = null & & appointmentBasicDetailsModel . appointmentStatusText ! . isNotEmpty ) . . . [
Utils . statusContainerChip ( text: appointmentBasicDetailsModel . appointmentStatusText ! , chipColor: MyColors . black ) ,
] ,
6. height ,
" ${ appointmentBasicDetailsModel . customerID } " . toText ( fontSize: 16 , letterSpacing: - 0.64 ) ,
showItem ( " ${ LocaleKeys . branchName . tr ( ) } : " , " ${ appointmentBasicDetailsModel . slotDate } " ) ,
showItem ( " ${ LocaleKeys . date . tr ( ) } : " , " ${ appointmentBasicDetailsModel . slotDate } " ) ,
showItem ( " ${ LocaleKeys . time . tr ( ) } : " , " ${ appointmentBasicDetailsModel . startTime } - ${ appointmentBasicDetailsModel . startTime } " ) ,
] ,
) . toContainer ( isShadowEnabled: true ) ;
} ) ,
actionButtonYes: Expanded (
child: ShowFillButton (
maxHeight: 55 ,
title: LocaleKeys . done . tr ( ) ,
fontSize: 15 ,
onPressed: ( ) = > Navigator . pop ( mainContext ) ,
) ,
) ,
actionButtonNo: Expanded (
child: ShowFillButton (
maxHeight: 55 ,
title: LocaleKeys . done . tr ( ) ,
fontSize: 15 ,
onPressed: ( ) = > Navigator . pop ( mainContext ) ,
) ,
) ,
) ;
}
Widget showItem ( String title , String value ) {
return Row (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
title . toText ( color: MyColors . lightTextColor , letterSpacing: - 0.48 ) ,
3. width ,
Flexible ( child: value . toText ( isBold: true , overflow: TextOverflow . ellipsis ) ) ,
] ,
) ;
}
void updateSelectedBranchType ( int status ) {
selectedBranchStatus = status ;
notifyListeners ( ) ;
@ -657,9 +746,7 @@ class ServiceVM extends BaseVM {
File file = File ( imageModel . filePath ! ) ;
List < int > imageBytes = await file . readAsBytes ( ) ;
String image = base64Encode ( imageBytes ) ;
String fileName = file . path
. split ( ' / ' )
. last ;
String fileName = file . path . split ( ' / ' ) . last ;
branchPostingImages = BranchPostingImages (
imageName: fileName ,
imageStr: image ,