This commit is contained in:
Hamza-Ayed
2024-10-10 16:22:30 +03:00
parent ebb57a699b
commit 9b0caf3bed
21 changed files with 1142 additions and 630 deletions

View File

@@ -10,6 +10,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_contacts/contact.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:get/get.dart';
import 'package:share/share.dart';
import '../../../main.dart';
import '../../../print.dart';
@@ -19,6 +20,42 @@ import '../../notification/notification_captain_controller.dart';
class InviteController extends GetxController {
final TextEditingController invitePhoneController = TextEditingController();
List driverInvitationData = [];
List driverInvitationDataToPassengers = [];
String? couponCode;
String? driverCouponCode;
int selectedTab = 0;
PassengerStats passengerStats = PassengerStats();
void updateSelectedTab(int index) {
selectedTab = index;
update();
}
Future<void> shareCouponCode() async {
// TODO: Implement sharing functionality
// You can use share_plus package to share the coupon code
}
Future<void> shareDriverCode() async {
if (driverCouponCode != null) {
final String shareText = '''
Join SEFER as a driver using my referral code!
Use code: $driverCouponCode
Download the SEFER Driver app now and earn rewards!
''';
await Share.share(shareText);
}
}
Future<void> sharePassengerCode() async {
if (couponCode != null) {
final String shareText = '''
Get a discount on your first SEFER ride!
Use my referral code: $couponCode
Download the SEFER app now and enjoy your ride!
''';
await Share.share(shareText);
}
}
@override
void onInit() {
@@ -39,6 +76,20 @@ class InviteController extends GetxController {
} catch (e) {}
}
void fetchDriverStatsPassengers() async {
try {
var response = await CRUD()
.get(link: AppLink.getDriverInvitationToPassengers, payload: {
"driverId": box.read(BoxName.driverID),
});
if (response != 'failure') {
var data = jsonDecode(response);
driverInvitationDataToPassengers = data['message'];
update();
}
} catch (e) {}
}
void selectPhone(String phone) {
if (box.read(BoxName.countryCode) == 'Egypt') {
invitePhoneController.text = phone;
@@ -136,6 +187,57 @@ class InviteController extends GetxController {
);
}
void onSelectPassengerInvitation(int index) async {
MyDialog().getDialog(
driverInvitationDataToPassengers[index]['countOfInvitDriver'] < 6
? '${'When'.tr} ${driverInvitationDataToPassengers[index]['passengerName']} ${"complete, you can claim your gift".tr} '
: 'You deserve the gift'.tr,
'${driverInvitationDataToPassengers[index]['passengerName']} ${driverInvitationDataToPassengers[index]['countOfInvitDriver']} / 6 ${'Trip'.tr}',
() async {
if (driverInvitationDataToPassengers[index]['countOfInvitDriver'] < 6) {
Get.back();
} else {
// Claim the gift if 100 trips are completed
if (driverInvitationDataToPassengers[index]['isGiftToken']
.toString() ==
'0') {
Get.back();
// Add wallet to the inviter
await Get.find<CaptainWalletController>()
.addDriverWallet('paymentMethod', '50');
// add for invitor too
await Get.find<CaptainWalletController>().addDriverWalletToInvitor(
'paymentMethod',
driverInvitationData[index]['driverInviterId'],
'50');
// Update invitation as claimed
await CRUD().post(
link: AppLink.updatePassengerGift,
payload: {'id': driverInvitationDataToPassengers[index]['id']},
);
// Notify the inviter
NotificationCaptainController().addNotificationCaptain(
driverInvitationDataToPassengers[index]['passengerInviterId']
.toString(),
"You have got a gift for invitation".tr,
'${"You have 50".tr} ${'LE'}',
false,
);
} else {
Get.back();
MyDialog().getDialog(
"You have got a gift".tr,
"Share the app with another new passenger".tr,
() {
Get.back();
},
);
}
}
},
);
}
savePhoneToServer() async {
for (var i = 0; i < contactMaps.length; i++) {
var phones = contactMaps[i]['phones'];
@@ -174,7 +276,7 @@ class InviteController extends GetxController {
var response = await CRUD().post(link: AppLink.addInviteDriver, payload: {
"driverId": box.read(BoxName.driverID),
"inviterDriverPhone": phoneNumber
"inviterDriverPhone": '+2$phoneNumber'
});
if (response != 'failure') {
@@ -203,4 +305,58 @@ class InviteController extends GetxController {
// Get.snackbar('Error', 'An error occurred'.tr);
// }
}
void sendInviteToPassenger() async {
if (invitePhoneController.text.isEmpty) {
Get.snackbar('Error', 'Please enter an phone address'.tr);
return;
}
// try {
String phoneNumber = formatPhoneNumber(invitePhoneController.text);
var response =
await CRUD().post(link: AppLink.addInvitationPassenger, payload: {
"driverId": box.read(BoxName.driverID),
"inviterPassengerPhone": '+2$phoneNumber'
});
if (response != 'failure') {
var d = jsonDecode(response);
Get.snackbar('Success', 'Invite sent successfully'.tr);
String message = '${'*SEFER APP CODE*'.tr}\n\n'
'${"Use this code in registration".tr}\n'
'${"To get a gift for both".tr}\n\n'
'${"The period of this code is 1 hour".tr}\n\n'
'${'before'.tr} *${d['message']['expirationTime'].toString()}*\n\n'
'_*${d['message']['inviteCode'].toString()}*_\n\n'
'${"Install our app:".tr}\n'
'*Android:* https://play.google.com/store/apps/details?id=com.mobileapp.store.ride\n\n\n'
'*iOS:* https://apps.apple.com/us/app/sefer/id6458734951';
launchCommunication('whatsapp', '+2$phoneNumber', message);
invitePhoneController.clear();
} else {
Get.snackbar('Error'.tr, "Invite code already used".tr,
backgroundColor: AppColor.redColor,
duration: const Duration(seconds: 4));
}
// } catch (e) {
// Get.snackbar('Error', 'An error occurred'.tr);
// }
}
}
class PassengerStats {
final int totalInvites;
final int activeUsers;
final double totalEarnings;
PassengerStats({
this.totalInvites = 0,
this.activeUsers = 0,
this.totalEarnings = 0.0,
});
}

View File

@@ -88,6 +88,31 @@ class LoginDriverController extends GetxController {
BoxName.nameDriver,
'${jsonDecoeded['data'][0]['first_name']}'
' ${jsonDecoeded['data'][0]['last_name']}');
if ((jsonDecoeded['data'][0]['model'].toString().contains('دراجه') ||
jsonDecoeded['data'][0]['make'].toString().contains('دراجه '))) {
if (jsonDecoeded['data'][0]['gender'].toString() == 'Male') {
box.write(BoxName.carTypeOfDriver, 'Scooter');
} else {
box.write(BoxName.carTypeOfDriver, 'Pink Bike');
}
} else if (int.parse(jsonDecoeded['data'][0]['year'].toString()) >
2017) {
if (jsonDecoeded['data'][0]['gender'].toString() != 'Male') {
box.write(BoxName.carTypeOfDriver, 'Lady');
} else {
box.write(BoxName.carTypeOfDriver, 'Comfort');
}
} else if (int.parse(jsonDecoeded['data'][0]['year'].toString()) >
2002 &&
int.parse(jsonDecoeded['data'][0]['year'].toString()) < 2017) {
box.write(BoxName.carTypeOfDriver, 'Speed');
} else if (int.parse(jsonDecoeded['data'][0]['year'].toString()) <
2002) {
box.write(BoxName.carTypeOfDriver, 'Awfar Car');
}
Log.print(
' box.write(BoxName.carTypeOfDriver: ${box.read(BoxName.carTypeOfDriver)}');
var token = await CRUD().get(
link: AppLink.getDriverToken,

View File

@@ -158,8 +158,16 @@ class FirebaseMessagesController extends GetxController {
// Get.to(const VipOrderPage());
} else if (message.notification!.title! == 'message From passenger'.tr) {
passengerDialog(message.notification!.body!);
if (Platform.isAndroid) {
NotificationController()
.showNotification('message From passenger'.tr, ''.tr, 'ding', '');
}
} else if (message.notification!.title == 'Cancel') {
cancelTripDialog1();
if (Platform.isAndroid) {
NotificationController()
.showNotification('Cancel'.tr, ''.tr, 'cancel', '');
}
} else if (message.notification!.title! == 'token change') {
// NotificationController1()
// .showNotification('token change'.tr, 'token change', 'cancel');
@@ -167,7 +175,7 @@ class FirebaseMessagesController extends GetxController {
GoogleSignInHelper.signOut();
} else if (message.notification!.title! == 'face detect') {
if (Platform.isAndroid) {
NotificationController1()
NotificationController()
.showNotification('face detect'.tr, ''.tr, 'tone2', '');
}
String result0 = await faceDetector();

View File

@@ -70,6 +70,23 @@ class AI extends GetxController {
}
}
Future updatePassengersInvitation() async {
if (formKey.currentState!.validate()) {
var res = await CRUD().post(
link: AppLink.updatePassengersInvitation,
payload: {"inviteCode": invitationCodeController.text});
if (res != 'failure') {
isInviteDriverFound = true;
update();
Get.snackbar("Code approved".tr, '',
backgroundColor: AppColor.greenColor);
} else {
Get.snackbar("Code not approved".tr, '',
backgroundColor: AppColor.redColor);
}
}
}
final today = DateTime.now();
Future<void> addDriverAndCarEgypt() async {

View File

@@ -28,25 +28,13 @@ Future<void> getPermissionOverlay() async {
}
}
// Future<void> getPermissionLocation() async {
// // final PermissionStatus status = await Permission.location.status;
// // if (!status.isGranted) {
// // Log.print('status.isGranted: ${status.isGranted}');
// // // box.write(BoxName.locationPermission, 'true');
// // await Permission.location.request();
// // Get.find<LoginDriverController>().update();
// // MyDialog().getDialog(
// // 'Enable Location Permission'.tr, // {en:ar}
// // 'Allowing location access will help us display orders near you. Please enable it now.'
// // .tr, // {en:ar}
// // () async {
// // Get.back();
// // box.write(BoxName.locationPermission, 'true');
// // await Permission.location.request();
// // },
// // );
// // }
// }
Future<void> closeOverlayIfFound() async {
bool isOverlayActive = await FlutterOverlayWindow.isActive();
if (isOverlayActive) {
await FlutterOverlayWindow.closeOverlay();
}
}
final location = Location();
Future<void> getLocationPermission() async {
bool serviceEnabled;

View File

@@ -462,6 +462,7 @@ class MapDriverController extends GetxController {
mapController!.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
bearing: Get.find<LocationController>().heading,
target: myLocation,
zoom: 17, // Adjust zoom level as needed
),
@@ -527,6 +528,25 @@ class MapDriverController extends GetxController {
? (distanceBetweenDriverAndPassengerWhenConfirm * .08) + (5 * 1)
: (distanceBetweenDriverAndPassengerWhenConfirm * .06) +
(5 * .06); //for Eygpt other like jordan .06 per minute
await CRUD().post(link: AppLink.updateRides, payload: {
'id': rideId,
'rideTimeStart': DateTime.now().toString(),
'status': 'CancelAfterWait',
});
CRUD().post(
link: "${AppLink.seferAlexandriaServer}/rides/update.php",
payload: {
'id': rideId,
'rideTimeStart': DateTime.now().toString(),
'status': 'CancelAfterWait',
});
CRUD()
.post(link: "${AppLink.seferGizaServer}/rides/update.php", payload: {
'id': rideId,
'rideTimeStart': DateTime.now().toString(),
'status': 'CancelAfterWait',
});
var paymentTokenWait =
await generateTokenDriver(costOfWaiting5Minute.toString());
var res = await CRUD().post(link: AppLink.addDrivePayment, payload: {

View File

@@ -165,6 +165,32 @@ class MyTranslation extends Translations {
'Rejected Orders Count': "عدد الطلبات المرفوضة",
'This is the total number of rejected orders per day after accepting the orders':
'هذا هو العدد الإجمالي للطلبات المرفوضة يوميًا بعد قبول الطلبات',
"Invite": "دعوة",
"Drivers": "السائقين",
"Passengers": "الركاب",
"Your Driver Referral Code": "رمز الإحالة الخاص بالسائق",
"DRIVER123": "سائق123",
"Share this code with other drivers. Both of you will receive rewards!":
"شارك هذا الرمز مع السائقين الآخرين. سيحصل كل منكما على مكافآت!",
"Share Code": "مشاركة الرمز",
"Invite another driver and both get a gift after he completes 100 trips!":
"ادع سائقًا آخر وسيحصل كلاكما على هدية بعد أن يكمل 100 رحلة!",
"Enter phone": "أدخل رقم الهاتف",
"Send Invite": "إرسال دعوة",
"Show Invitations": "عرض الدعوات",
"No invitation found yet!": "لم يتم العثور على دعوات حتى الآن!",
"Trip": "رحلة",
"Your Passenger Referral Code": "رمز الإحالة الخاص بالراكب",
"SEFER123": "سفر123",
"Share this code with passengers and earn rewards when they use it!":
"شارك هذا الرمز مع الركاب واكسب مكافآت عند استخدامه!",
"Your Rewards": "مكافآتك",
"Total Invites": "إجمالي الدعوات",
"Active Users": "المستخدمون النشطون",
"Total Earnings": "إجمالي الأرباح",
"Choose from contact": "اختر من جهات الاتصال",
"Cancel": "إلغاء",
"No invitation found": "لم يتم العثور على دعوة",
'You are not near the passenger location':
"أنت لست بالقرب من موقع الراكب",
'If you need assistance, contact us':

View File

@@ -44,7 +44,7 @@ class RideAvailableController extends GetxController {
var res = await CRUD().get(
link: AppLink.getRideWaiting,
payload: {
"carType": box.read(BoxName.carTypeOfDriver),
"carType": box.read(BoxName.carTypeOfDriver).toString(),
'southwestLat': bounds.southwest.latitude.toString(),
'southwestLon': bounds.southwest.longitude.toString(),
'northeastLat': bounds.northeast.latitude.toString(),

View File

@@ -662,25 +662,28 @@ class PaymentController extends GetxController {
onPayment: (PaymobResponse response) {},
);
if (response!.responseCode == 'APPROVED') {
Get.defaultDialog(
barrierDismissible: false,
title: 'Payment Successful'.tr,
titleStyle: AppStyle.title,
// backgroundColor: AppColor.greenColor,
content: Text(
'The payment was approved.'.tr,
style: AppStyle.title,
),
confirm: MyElevatedButton(
kolor: AppColor.greenColor,
title: 'OK'.tr,
onPressed: () async {
Get.back();
method();
},
),
);
// if (response!.responseCode == 'APPROVED') {
if (response!.responseCode == '200' && response.success == true) {
Toast.show(context, 'Payment Successful'.tr, AppColor.greenColor);
method();
// Get.defaultDialog(
// barrierDismissible: false,
// title: 'Payment Successful'.tr,
// titleStyle: AppStyle.title,
// // backgroundColor: AppColor.greenColor,
// content: Text(
// 'The payment was approved.'.tr,
// style: AppStyle.title,
// ),
// confirm: MyElevatedButton(
// kolor: AppColor.greenColor,
// title: 'OK'.tr,
// onPressed: () async {
// Get.back();
// method();
// },
// ),
// );
} else {
Get.defaultDialog(
barrierDismissible: false,