diff --git a/lib/Screens/itnerary/accomodations.dart b/lib/Screens/itnerary/accomodations.dart index 47c12ce..0cc5201 100644 --- a/lib/Screens/itnerary/accomodations.dart +++ b/lib/Screens/itnerary/accomodations.dart @@ -768,6 +768,7 @@ class _AccomodationScreenState extends State { child: TextField( focusNode: _checkInFocusNode, controller: _checkInController, + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select Date", @@ -822,6 +823,7 @@ class _AccomodationScreenState extends State { child: TextField( focusNode: _checkInTimeFocusNode, controller: _checkInTimeController, + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select Time", @@ -873,6 +875,7 @@ class _AccomodationScreenState extends State { child: TextField( focusNode: _checkOutFocusNode, controller: _checkOutController, + readOnly: true, style: const TextStyle(fontSize: 12, color: Colors.black), decoration: const InputDecoration( labelText: "Select Date", @@ -924,6 +927,7 @@ class _AccomodationScreenState extends State { child: TextField( focusNode: _checkOutTimeFocusNode, controller: _checkOutTimeController, + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select Time", diff --git a/lib/Screens/itnerary/bus.dart b/lib/Screens/itnerary/bus.dart index 241c925..e36337f 100644 --- a/lib/Screens/itnerary/bus.dart +++ b/lib/Screens/itnerary/bus.dart @@ -541,6 +541,7 @@ class _BusScreenState extends State { child: TextField( focusNode: _dateFocusNode, controller: _dateController, + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select Date", @@ -593,6 +594,7 @@ class _BusScreenState extends State { child: TextField( focusNode: _timeFocusNode, controller: _timeController, + readOnly: true, style: const TextStyle(fontSize: 12, color: Colors.black), decoration: const InputDecoration( labelText: "Select Time", diff --git a/lib/Screens/itnerary/flights.dart b/lib/Screens/itnerary/flights.dart index 0a98e7d..94ef85d 100644 --- a/lib/Screens/itnerary/flights.dart +++ b/lib/Screens/itnerary/flights.dart @@ -1947,6 +1947,7 @@ class FlightScreenState extends State { focusNode: focusNodes["_date${index}FocusNode"], // controller: _dateController, controller: textControllers["_date${index}Controller"], + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select Date", @@ -2012,7 +2013,7 @@ class FlightScreenState extends State { focusNode: focusNodes["_time${index}FocusNode"], // controller: _timeController, controller: textControllers["_time${index}Controller"], - + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Time", diff --git a/lib/Screens/itnerary/forex.dart b/lib/Screens/itnerary/forex.dart index 611a049..b53c38d 100644 --- a/lib/Screens/itnerary/forex.dart +++ b/lib/Screens/itnerary/forex.dart @@ -82,19 +82,49 @@ class _ForexScreenState extends State { String _formatDate(String? date) { if (date == null || date.isEmpty) return ""; + try { - DateTime parsedDate = DateTime.parse( - date, - ); // Assuming input is YYYY-MM-DD - return DateFormat( - "dd-MM-yyyy", - ).format(parsedDate); // Convert to DD-MM-YYYY + // First try parsing as ISO format (YYYY-MM-DD) + DateTime parsedDate; + + try { + parsedDate = DateTime.parse(date); + } catch (e) { + // If ISO parse fails, try parsing as DD-MM-YYYY + final parts = date.split('-'); + if (parts.length == 3) { + parsedDate = DateTime( + int.parse(parts[2]), // year + int.parse(parts[1]), // month + int.parse(parts[0]), // day + ); + } else { + throw FormatException("Unsupported date format"); + } + } + + return DateFormat("dd-MM-yyyy").format(parsedDate); } catch (e) { - print("Error formatting date: $e"); - return date; // Return as is if parsing fails + print("Error formatting date '$date': $e"); + return ""; // Return empty string or handle differently } } + // String _formatDate(String? date) { + // if (date == null || date.isEmpty) return ""; + // try { + // DateTime parsedDate = DateTime.parse( + // date, + // ); // Assuming input is YYYY-MM-DD + // return DateFormat( + // "dd-MM-yyyy", + // ).format(parsedDate); // Convert to DD-MM-YYYY + // } catch (e) { + // print("Error formatting date: $e"); + // return date; // Return as is if parsing fails + // } + // } + Map errorMessages = {}; String? selectedCountry; @@ -320,6 +350,16 @@ class _ForexScreenState extends State { final cash = data["deposit_on_cash"]; print("card - $card"); print("cash - $cash"); + // Call validations first (they populate errorMessages) + _validateCardAmount(card); + _validateCashAmount(cash); + + // Now check if any errors exist + if (errorMessages.isNotEmpty) { + print("Validation Failed: ${errorMessages}"); + setState(() {}); // Refresh UI with error messages + return; + } if (!isValidForexData(data)) { // && errorMessages.isNotEmpty) { @@ -376,8 +416,6 @@ class _ForexScreenState extends State { textControllers["_forexStartDate"]?.addListener(_onFieldChanged); textControllers["_forexEndDate"]?.addListener(_onFieldChanged); - handleUpdatedField(); - flightFirstTripDateNotifier = ValueNotifier(null); flightLastTripDateNotifier = ValueNotifier(null); @@ -386,6 +424,8 @@ class _ForexScreenState extends State { print("tripuserId - $tripuserId"); final result = getFlightTripDateRange(widget.flightData); + print("result - $result"); + flightFirstTripDateNotifier.value = result['firstTripDate']; flightLastTripDateNotifier.value = result['lastTripDate']; @@ -409,6 +449,9 @@ class _ForexScreenState extends State { 'dd-MM-yyyy', ).format(parsedEndDate); } + + handleUpdatedField(); + }); } @@ -429,16 +472,16 @@ class _ForexScreenState extends State { print("UPDATAED SELECTION"); textControllers["_forexStartDate"] = initController("start_date"); + textControllers["_forexStartDate"]?.addListener(_onFieldChanged); // Reattach textControllers["_forexEndDate"] = initController("end_date"); + textControllers["_forexEndDate"]?.addListener(_onFieldChanged); // Reattach textControllers["_transport"] = initController("transport"); textControllers["_accomodation"] = initController("accommodation"); textControllers["_telephone"] = initController("telephone"); textControllers["_cardNumber"] = initController("card_number"); textControllers["_card"] = initController("deposit_on_card"); textControllers["_cash"] = initController("deposit_on_cash"); - textControllers["_deliveryLocation"] = initController( - "delivery_location", - ); + textControllers["_deliveryLocation"] = initController("delivery_location"); textControllers["_comments"] = initController("comments"); // Set dropdown values @@ -466,7 +509,6 @@ class _ForexScreenState extends State { // textControllers["_cardNumber"]!.text = userCardNumber ?? ''; // // } - _onFieldChangedForOthers(); setState(() {}); // Update the UI @@ -502,6 +544,7 @@ class _ForexScreenState extends State { // Handle field changes void _onFieldChanged() { + print("_on Field Changed Called"); if (_isForexDataDurationComplete()) { print("Calculate 1"); CalculateDuration(); @@ -532,14 +575,13 @@ class _ForexScreenState extends State { // final startDate = DateFormat('dd/mm/yyyy').parse(startDateString); // final endDate = DateFormat('dd/mm/yyyy').parse(endDateString); - final startDate = DateFormat('dd-MM-yyyy').parse(startDateString); - final endDate = DateFormat('dd-MM-yyyy').parse(endDateString); + final startDate = DateFormat('dd-MM-yyyy').parse(startDateString.trim()) ; + final endDate = DateFormat('dd-MM-yyyy').parse(endDateString.trim()) ; print("Calculate 4"); // Calculate difference - final durationInDays = - endDate.difference(startDate).inDays + 1; // +1 to include both days + final durationInDays = endDate.difference(startDate).inDays ; // +1 to include both days // You can now use durationInDays however you want: print("Duration: $durationInDays days"); @@ -721,6 +763,9 @@ class _ForexScreenState extends State { for (var controller in textControllers.values) { controller.dispose(); } + // textControllers["_forexStartDate"]?.removeListener(_onFieldChanged); + // textControllers["_forexEndDate"]?.removeListener(_onFieldChanged); + // textControllers.forEach((_, controller) => controller.dispose()); super.dispose(); } @@ -994,6 +1039,7 @@ class _ForexScreenState extends State { child: TextField( focusNode: focusNodes["_forexStartDate"], controller: textControllers["_forexStartDate"], + readOnly: true, style: const TextStyle(fontSize: 12), decoration: InputDecoration( labelText: "Select Date", @@ -1074,6 +1120,7 @@ class _ForexScreenState extends State { child: TextField( focusNode: focusNodes["_forexEndDate"], controller: textControllers["_forexEndDate"], + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select Date", diff --git a/lib/Screens/itnerary/insurance.dart b/lib/Screens/itnerary/insurance.dart index 98de2a1..f46fc26 100644 --- a/lib/Screens/itnerary/insurance.dart +++ b/lib/Screens/itnerary/insurance.dart @@ -887,6 +887,7 @@ class _InsuranceScreenState extends State { child: TextField( focusNode: _startDateFocusNode, controller: _startDateController, + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select ", @@ -956,6 +957,7 @@ class _InsuranceScreenState extends State { child: TextField( focusNode: _endDateFocusNode, controller: _endDateController, + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select ", diff --git a/lib/Screens/itnerary/taxi.dart b/lib/Screens/itnerary/taxi.dart index 2b55e21..0d389f8 100644 --- a/lib/Screens/itnerary/taxi.dart +++ b/lib/Screens/itnerary/taxi.dart @@ -832,6 +832,7 @@ class _TaxiScreenState extends State { child: TextField( focusNode: _dateFocusNode, controller: _dateController, + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select Date", @@ -883,6 +884,7 @@ class _TaxiScreenState extends State { child: TextField( focusNode: _timeFocusNode, controller: _timeController, + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select Time", diff --git a/lib/Screens/itnerary/train.dart b/lib/Screens/itnerary/train.dart index a48e864..723d18f 100644 --- a/lib/Screens/itnerary/train.dart +++ b/lib/Screens/itnerary/train.dart @@ -1034,6 +1034,7 @@ class _TrainScreenState extends State { child: TextField( focusNode: _dateFocusNode, controller: _dateController, + readOnly: true, // Prevents typing style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select Date", @@ -1086,6 +1087,7 @@ class _TrainScreenState extends State { child: TextField( focusNode: _timeFocusNode, controller: _timeController, + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select Time", diff --git a/lib/Screens/itnerary/visa.dart b/lib/Screens/itnerary/visa.dart index 5b025e3..1bd433f 100644 --- a/lib/Screens/itnerary/visa.dart +++ b/lib/Screens/itnerary/visa.dart @@ -734,6 +734,7 @@ class _VisaScreenState extends State { child: TextField( focusNode: _dateFocusNode, controller: _dateController, + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select Date", diff --git a/lib/Screens/traveller/travellerList.dart b/lib/Screens/traveller/travellerList.dart index c26997b..1919534 100644 --- a/lib/Screens/traveller/travellerList.dart +++ b/lib/Screens/traveller/travellerList.dart @@ -142,27 +142,26 @@ class TravellerListState extends State { // }); // print("filteredPlans: $filteredTraveller"); - print("all before filtering: $query"); - final lowerQuery = query.toLowerCase(); + final lowerQuery = query.toLowerCase().trim(); + setState(() { - filteredTraveller = - allTraveller.where((object) { - final isActiveStatus = - object['is_active'] == "1" ? "active" : "inactive"; - return (object['traveller_id']?.toLowerCase().contains( - lowerQuery, - ) ?? - false) || - (object['first_name']?.toLowerCase().contains(lowerQuery) ?? - false) || - (object['last_name']?.toLowerCase().contains(lowerQuery) ?? - false) || - (object['mobile']?.toLowerCase().contains(lowerQuery) ?? - false) || - (object['email']?.toLowerCase().contains(lowerQuery) ?? - false) || - (isActiveStatus.contains(lowerQuery)); - }).toList(); + filteredTraveller = allTraveller.where((object) { + final travellerId = object['traveller_id']?.toLowerCase() ?? ''; + final firstName = object['first_name']?.toLowerCase() ?? ''; + final lastName = object['last_name']?.toLowerCase() ?? ''; + final fullName = '$firstName $lastName'; + final mobile = object['mobile']?.toLowerCase() ?? ''; + final email = object['email']?.toLowerCase() ?? ''; + final isActiveStatus = object['is_active'] == "1" ? "active" : "inactive"; + + return travellerId.contains(lowerQuery) || + firstName.contains(lowerQuery) || + lastName.contains(lowerQuery) || + fullName.contains(lowerQuery) || + mobile.contains(lowerQuery) || + email.contains(lowerQuery) || + isActiveStatus.contains(lowerQuery); + }).toList(); currentPage = 0; }); print("filteredTraveller: $filteredTraveller"); diff --git a/lib/Screens/userManagement/create_user/office_details.dart b/lib/Screens/userManagement/create_user/office_details.dart index a015f23..6c58f9c 100644 --- a/lib/Screens/userManagement/create_user/office_details.dart +++ b/lib/Screens/userManagement/create_user/office_details.dart @@ -1392,6 +1392,7 @@ class _OfficeDetailsState extends State { child: AbsorbPointer( child: TextField( controller: widget.controllers["delegationStartDate"], + readOnly: true, style: const TextStyle(fontSize: 12), decoration: InputDecoration( labelText: "Select Date", @@ -1496,6 +1497,7 @@ class _OfficeDetailsState extends State { child: AbsorbPointer( child: TextField( controller: widget.controllers["delegationEndDate"], + readOnly: true, style: const TextStyle(fontSize: 12), decoration: InputDecoration( labelText: "Select Date", diff --git a/lib/Screens/userManagement/create_user/personal_details.dart b/lib/Screens/userManagement/create_user/personal_details.dart index 6b8bc71..f3e969e 100644 --- a/lib/Screens/userManagement/create_user/personal_details.dart +++ b/lib/Screens/userManagement/create_user/personal_details.dart @@ -1098,6 +1098,7 @@ class PersonalDetailsState extends State { child: AbsorbPointer( child: TextField( controller: widget.controllers["dob"], + readOnly: true, style: GoogleFonts.poppins(fontSize: 12, color: Colors.black), decoration: InputDecoration( labelText: "Select Date", diff --git a/lib/Screens/userManagement/create_user/traveller_details.dart b/lib/Screens/userManagement/create_user/traveller_details.dart index 3781bce..0fde272 100644 --- a/lib/Screens/userManagement/create_user/traveller_details.dart +++ b/lib/Screens/userManagement/create_user/traveller_details.dart @@ -1422,6 +1422,7 @@ class TravellerDetailsState extends State { child: AbsorbPointer( child: TextField( controller: controllers["dateOfIssue"], + readOnly: true, style: GoogleFonts.poppins(fontSize: 12, color: Colors.black), decoration: InputDecoration( labelText: "Select Date", @@ -1559,6 +1560,7 @@ class TravellerDetailsState extends State { child: AbsorbPointer( child: TextField( controller: controllers["dateOfExpiry"], + readOnly: true, style: GoogleFonts.poppins(fontSize: 12, color: Colors.black), decoration: InputDecoration( labelText: "Select Date", @@ -2884,6 +2886,7 @@ class TravellerDetailsState extends State { child: AbsorbPointer( child: TextField( controller: controllers["forex_expiry_date"], + readOnly: true, style: GoogleFonts.poppins(fontSize: 12, color: Colors.black), decoration: InputDecoration( labelText: "Select Date", @@ -4124,7 +4127,7 @@ class TravellerDetailsState extends State { child: TextField( // focusNode: _dateFocusNode, controller: entry["controller_valid_from"], - + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select Date", @@ -4241,6 +4244,7 @@ class TravellerDetailsState extends State { // focusNode: _dateFocusNode, // controller: _dateController, controller: entry["controller_valid_upto"], + readOnly: true, style: const TextStyle(fontSize: 12), decoration: const InputDecoration( labelText: "Select Date",