From 57f7f290548f9d9e466cf0563818ad4567296e5a Mon Sep 17 00:00:00 2001 From: venba-Inspriron-3558 Date: Fri, 27 Jun 2025 09:17:04 +0530 Subject: [PATCH] minor issues fixes 7 --- lib/Screens/itnerary/flights.dart | 9 +- lib/Screens/itnerary/forex.dart | 32 +++++- lib/Screens/itnerary_list/flight_list.dart | 33 +++++- lib/Screens/itnerary_list/forex_list.dart | 120 ++++++++++++++++++--- 4 files changed, 176 insertions(+), 18 deletions(-) diff --git a/lib/Screens/itnerary/flights.dart b/lib/Screens/itnerary/flights.dart index 20f6ca5..0a1fa54 100644 --- a/lib/Screens/itnerary/flights.dart +++ b/lib/Screens/itnerary/flights.dart @@ -47,6 +47,7 @@ class FlightScreenState extends State { bool isCountryLoading = true; late Map countryMap; + late Map countryCodeMap; late List countryCodes; late ValueNotifier flightFirstTripDateNotifier; @@ -260,6 +261,7 @@ class FlightScreenState extends State { // Create a map: Country_Code -> "City, Airport" Map tempCountryMap = {}; + Map tempCountryCode = {}; for (var country in result) { // String city = country['City'] ?? ''; @@ -269,13 +271,16 @@ class FlightScreenState extends State { final code = country['Code'] ?? ''; final city = country['City'] ?? ''; final airport = country['Airport'] ?? ''; + final countyCode = country['Country_Code'] ?? ''; final displayName = '$city ($code)\n$airport'; tempCountryMap[country['Code']] = displayName; + tempCountryCode[country['Code']] = countyCode; } setState(() { countryMap = tempCountryMap; // Update the map + countryCodeMap = tempCountryCode; isCountryLoading = false; }); } @@ -416,7 +421,8 @@ class FlightScreenState extends State { // "from_place": countryMap[selectedFrom[i]], "from_place": selectedFrom[i], "to_place": selectedTo[i], - + "from_country_code": countryCodeMap[selectedFrom[i]], + "to_country_code": countryCodeMap[selectedTo[i]], // "from_place": textControllers["_from${i}Controller"]?.text ?? "", // "to_place": textControllers["_to${i}Controller"]?.text ?? "", "date": textControllers["_date${i}Controller"]?.text ?? "", @@ -1766,7 +1772,6 @@ class FlightScreenState extends State { (entry) => entry.value == newValue, ) .key; - if (selectedTripType == "Roundtrip") { print('rounfTo${selectedFrom[index]}'); // textControllers["_to${index+1}Controller"]?.text = selectedFrom[index]!; diff --git a/lib/Screens/itnerary/forex.dart b/lib/Screens/itnerary/forex.dart index afbc5f2..090babc 100644 --- a/lib/Screens/itnerary/forex.dart +++ b/lib/Screens/itnerary/forex.dart @@ -43,6 +43,7 @@ class _ForexScreenState extends State { late ValueNotifier flightFirstTripDateNotifier; late ValueNotifier flightLastTripDateNotifier; + late ValueNotifier flightFirstTripToPlaceNotifier; // late final tripuserId; String? tripuserId; @@ -192,7 +193,7 @@ class _ForexScreenState extends State { Future postgetForexData(Map forexData) async { final String apiUrldata = '$apiUrl/api/plans/getForexPerdiem'; - print("Sending Data: ${jsonEncode(forexData)}"); + print("getForexPerdiem api - Sending Data: ${jsonEncode(forexData)}"); final token = await getToken(); // Fetch token @@ -338,7 +339,7 @@ class _ForexScreenState extends State { .toList(); if (allTrips.isEmpty) { - return {'firstTripDate': null, 'lastTripDate': null}; + return {'firstTripDate': null, 'lastTripDate': null, 'toTripPlace' : null}; } allTrips.sort((a, b) { @@ -349,10 +350,12 @@ class _ForexScreenState extends State { final firstTrip = allTrips.first; final lastTrip = allTrips.last; + final toPlaceCode = allTrips.first['to_country_code']; return { 'firstTripDate': firstTrip['date'], 'lastTripDate': lastTrip['date'], + 'toTripPlace' : toPlaceCode }; } @@ -426,9 +429,11 @@ class _ForexScreenState extends State { // Add listeners to text fields textControllers["_forexStartDate"]?.addListener(_onFieldChanged); textControllers["_forexEndDate"]?.addListener(_onFieldChanged); + textControllers["_countries"]?.addListener(_onFieldChanged); // Reattach flightFirstTripDateNotifier = ValueNotifier(null); flightLastTripDateNotifier = ValueNotifier(null); + flightFirstTripToPlaceNotifier = ValueNotifier(null); WidgetsBinding.instance.addPostFrameCallback((_) async { tripuserId = await getTripUserId(); @@ -439,6 +444,7 @@ class _ForexScreenState extends State { flightFirstTripDateNotifier.value = result['firstTripDate']; flightLastTripDateNotifier.value = result['lastTripDate']; + flightFirstTripToPlaceNotifier.value = result['toTripPlace']; // ✅ Only set controller after value is updated // final parsedDate = @@ -489,6 +495,26 @@ class _ForexScreenState extends State { print("flightEndTripDateNotifier is null or empty"); } + final toPlaceCountryCode = flightFirstTripToPlaceNotifier.value; + print("toPlaceCode-$toPlaceCountryCode"); + + if (toPlaceCountryCode != null && toPlaceCountryCode.trim().isNotEmpty) { + try { + if (toPlaceCountryCode != null) { + textControllers["_countries"]?.text = toPlaceCountryCode; // set country dropdown + selectedCountry = toPlaceCountryCode; + // textControllers["_countriesFocused"]?.addListener( _onFieldChanged ); // Reattach + // _onFieldChanged; + } else { + print("No matching country found for code: $toPlaceCountryCode"); + } + } catch (e) { + print("Error while mapping to_place to Country_Code: $e"); + } + } else { + print("flightToPlaceTripNotifier is null or empty"); + } + // final parsedEndDate = DateFormat( // "dd-MM-yyyy", // ).parse(flightLastTripDateNotifier.value ?? ''); @@ -497,7 +523,7 @@ class _ForexScreenState extends State { // 'dd-MM-yyyy', // ).format(parsedEndDate); // } - + _onFieldChanged(); handleUpdatedField(); }); } diff --git a/lib/Screens/itnerary_list/flight_list.dart b/lib/Screens/itnerary_list/flight_list.dart index 17bde3e..45ed127 100644 --- a/lib/Screens/itnerary_list/flight_list.dart +++ b/lib/Screens/itnerary_list/flight_list.dart @@ -528,6 +528,37 @@ class _FlightListWidgetState extends State { item["trips"] != null && item["trips"].isNotEmpty) ...item["trips"].map((trip) { + + String fromPlaceCountry = + countryMap[trip["from_place"]?.toString()] ?? + "Unknown Country"; + + final parts = fromPlaceCountry.split('\n'); + final cityAndCode = parts[0]; + final fromairport = parts.length > 1 ? parts[1] : ''; + + // Extract city and code from "City (CODE)" + final cityMatch = RegExp( + r'^(.*)\s+\(([^)]+)\)$', + ).firstMatch(cityAndCode); + final fromcity = cityMatch?.group(1) ?? ''; + final fromcode = cityMatch?.group(2) ?? ''; + + String toPlaceCountry = + countryMap[trip["to_place"]?.toString()] ?? + "Unknown Country"; + + final toparts = toPlaceCountry.split('\n'); + final tocityAndCode = toparts[0]; + final toairport = toparts.length > 1 ? toparts[1] : ''; + + // Extract city and code from "City (CODE)" + final tocityMatch = RegExp( + r'^(.*)\s+\(([^)]+)\)$', + ).firstMatch(tocityAndCode); + final tocity = tocityMatch?.group(1) ?? ''; + final tocode = tocityMatch?.group(2) ?? ''; + return Padding( padding: const EdgeInsets.symmetric(vertical: 6.0), child: Container( @@ -547,7 +578,7 @@ class _FlightListWidgetState extends State { ), _buildKeyValueRow( "Sector", - "${trip["from_place"] ?? "N/A"} - ${trip["to_place"] ?? "N/A"}", + "$fromcity ($fromcode), $fromairport → $tocity ($tocode), $toairport", ), _buildKeyValueRow( diff --git a/lib/Screens/itnerary_list/forex_list.dart b/lib/Screens/itnerary_list/forex_list.dart index da9c9a4..386a13b 100644 --- a/lib/Screens/itnerary_list/forex_list.dart +++ b/lib/Screens/itnerary_list/forex_list.dart @@ -222,6 +222,14 @@ class ForexListWidget extends StatelessWidget { itemCount: filteredList.length, itemBuilder: (context, index) { final item = filteredList[index]; + final double transport = double.tryParse(item["transport"] ?? "0") ?? 0; + final double accommodation = double.tryParse(item["accommodation"] ?? "0") ?? 0; + final double telephone = double.tryParse(item["telephone"] ?? "0") ?? 0; + final double perdiemAmount = double.tryParse(item["perdiem_amount"] ?? "0") ?? 0; + final double calculatedValue = transport + accommodation + telephone; + final String calculatedOtherExpenses = calculatedValue.toStringAsFixed(0); + final double finalTotal = calculatedValue + perdiemAmount; + return Container( margin: EdgeInsets.symmetric(horizontal: 8, vertical: 6), @@ -339,6 +347,46 @@ class ForexListWidget extends StatelessWidget { // style: TextStyle( // fontSize: 11, fontFamily: "Archivo"), // )), + Expanded( + flex: 2, + child: Text( + " Perdiem ", + style: GoogleFonts.poppins( + fontSize: 11, + ), + )), + Expanded( + flex: 2, + child: Text( + " Others ", + style: GoogleFonts.poppins( + fontSize: 11, + ), + )), + Expanded( + flex: 2, + child: Text( + " Total ", + style: GoogleFonts.poppins( + fontSize: 11, + ), + )), + Expanded( + flex: 2, + child: Text( + " Cash ", + style: GoogleFonts.poppins( + fontSize: 11, + ), + )), + Expanded( + flex: 2, + child: Text( + " Card ", + style: GoogleFonts.poppins( + fontSize: 11, + ), + )), Expanded( flex: 2, child: Text( @@ -386,17 +434,61 @@ class ForexListWidget extends StatelessWidget { ), ), SizedBox(width: 10), - // Expanded( - // flex: 2, - // child: Text( - // " ", - // style: TextStyle( - // fontSize: 12, - // fontWeight: FontWeight.w600, - // fontFamily: "Archivo"), - // ), - // ), - // SizedBox(width: 10), + Expanded( + flex: 2, + child: Text( + "$perdiemAmount", + style: GoogleFonts.poppins( + fontSize: 12, + fontWeight: FontWeight.w600, + ), + ), + ), + SizedBox(width: 10), + Expanded( + flex: 2, + child: Text( + "$calculatedOtherExpenses", + style: GoogleFonts.poppins( + fontSize: 12, + fontWeight: FontWeight.w600, + ), + ), + ), + SizedBox(width: 10), + Expanded( + flex: 2, + child: Text( + "$finalTotal", + style: GoogleFonts.poppins( + fontSize: 12, + fontWeight: FontWeight.w600, + ), + ), + ), + SizedBox(width: 10), + Expanded( + flex: 2, + child: Text( + item["deposit_on_cash"], + style: GoogleFonts.poppins( + fontSize: 12, + fontWeight: FontWeight.w600, + ), + ), + ), + SizedBox(width: 10), + Expanded( + flex: 2, + child: Text( + item["deposit_on_card"], + style: GoogleFonts.poppins( + fontSize: 12, + fontWeight: FontWeight.w600, + ), + ), + ), + SizedBox(width: 10), Expanded( flex: 2, child: _buildComments( @@ -419,7 +511,11 @@ class ForexListWidget extends StatelessWidget { // SizedBox(height: 6), _buildRow("StartDate:", item["start_date"]!), _buildRow("EndDate:", item["end_date"]!), - // SizedBox(height: 6), + _buildRow("Perdiem:", "$perdiemAmount",), + _buildRow("Others:", "$calculatedOtherExpenses"), + _buildRow("Total:", "$finalTotal"), + _buildRow("Cash:", item["deposit_on_cash"]!), + _buildRow("Card:", item["deposit_on_card"]!), _buildRow("Comments:", item["comments"] ?? "N/A"), ], ),