minor issues fixes 7

This commit is contained in:
venba-Inspriron-3558 2025-06-27 09:17:04 +05:30
parent 179e1db5d7
commit 57f7f29054
4 changed files with 176 additions and 18 deletions

View File

@ -47,6 +47,7 @@ class FlightScreenState extends State<FlightScreen> {
bool isCountryLoading = true; bool isCountryLoading = true;
late Map<String, String> countryMap; late Map<String, String> countryMap;
late Map<String, String> countryCodeMap;
late List<String> countryCodes; late List<String> countryCodes;
late ValueNotifier<String?> flightFirstTripDateNotifier; late ValueNotifier<String?> flightFirstTripDateNotifier;
@ -260,6 +261,7 @@ class FlightScreenState extends State<FlightScreen> {
// Create a map: Country_Code -> "City, Airport" // Create a map: Country_Code -> "City, Airport"
Map<String, String> tempCountryMap = {}; Map<String, String> tempCountryMap = {};
Map<String, String> tempCountryCode = {};
for (var country in result) { for (var country in result) {
// String city = country['City'] ?? ''; // String city = country['City'] ?? '';
@ -269,13 +271,16 @@ class FlightScreenState extends State<FlightScreen> {
final code = country['Code'] ?? ''; final code = country['Code'] ?? '';
final city = country['City'] ?? ''; final city = country['City'] ?? '';
final airport = country['Airport'] ?? ''; final airport = country['Airport'] ?? '';
final countyCode = country['Country_Code'] ?? '';
final displayName = '$city ($code)\n$airport'; final displayName = '$city ($code)\n$airport';
tempCountryMap[country['Code']] = displayName; tempCountryMap[country['Code']] = displayName;
tempCountryCode[country['Code']] = countyCode;
} }
setState(() { setState(() {
countryMap = tempCountryMap; // Update the map countryMap = tempCountryMap; // Update the map
countryCodeMap = tempCountryCode;
isCountryLoading = false; isCountryLoading = false;
}); });
} }
@ -416,7 +421,8 @@ class FlightScreenState extends State<FlightScreen> {
// "from_place": countryMap[selectedFrom[i]], // "from_place": countryMap[selectedFrom[i]],
"from_place": selectedFrom[i], "from_place": selectedFrom[i],
"to_place": selectedTo[i], "to_place": selectedTo[i],
"from_country_code": countryCodeMap[selectedFrom[i]],
"to_country_code": countryCodeMap[selectedTo[i]],
// "from_place": textControllers["_from${i}Controller"]?.text ?? "", // "from_place": textControllers["_from${i}Controller"]?.text ?? "",
// "to_place": textControllers["_to${i}Controller"]?.text ?? "", // "to_place": textControllers["_to${i}Controller"]?.text ?? "",
"date": textControllers["_date${i}Controller"]?.text ?? "", "date": textControllers["_date${i}Controller"]?.text ?? "",
@ -1766,7 +1772,6 @@ class FlightScreenState extends State<FlightScreen> {
(entry) => entry.value == newValue, (entry) => entry.value == newValue,
) )
.key; .key;
if (selectedTripType == "Roundtrip") { if (selectedTripType == "Roundtrip") {
print('rounfTo${selectedFrom[index]}'); print('rounfTo${selectedFrom[index]}');
// textControllers["_to${index+1}Controller"]?.text = selectedFrom[index]!; // textControllers["_to${index+1}Controller"]?.text = selectedFrom[index]!;

View File

@ -43,6 +43,7 @@ class _ForexScreenState extends State<ForexScreen> {
late ValueNotifier<String?> flightFirstTripDateNotifier; late ValueNotifier<String?> flightFirstTripDateNotifier;
late ValueNotifier<String?> flightLastTripDateNotifier; late ValueNotifier<String?> flightLastTripDateNotifier;
late ValueNotifier<String?> flightFirstTripToPlaceNotifier;
// late final tripuserId; // late final tripuserId;
String? tripuserId; String? tripuserId;
@ -192,7 +193,7 @@ class _ForexScreenState extends State<ForexScreen> {
Future<void> postgetForexData(Map<String, dynamic> forexData) async { Future<void> postgetForexData(Map<String, dynamic> forexData) async {
final String apiUrldata = '$apiUrl/api/plans/getForexPerdiem'; 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 final token = await getToken(); // Fetch token
@ -338,7 +339,7 @@ class _ForexScreenState extends State<ForexScreen> {
.toList(); .toList();
if (allTrips.isEmpty) { if (allTrips.isEmpty) {
return {'firstTripDate': null, 'lastTripDate': null}; return {'firstTripDate': null, 'lastTripDate': null, 'toTripPlace' : null};
} }
allTrips.sort((a, b) { allTrips.sort((a, b) {
@ -349,10 +350,12 @@ class _ForexScreenState extends State<ForexScreen> {
final firstTrip = allTrips.first; final firstTrip = allTrips.first;
final lastTrip = allTrips.last; final lastTrip = allTrips.last;
final toPlaceCode = allTrips.first['to_country_code'];
return { return {
'firstTripDate': firstTrip['date'], 'firstTripDate': firstTrip['date'],
'lastTripDate': lastTrip['date'], 'lastTripDate': lastTrip['date'],
'toTripPlace' : toPlaceCode
}; };
} }
@ -426,9 +429,11 @@ class _ForexScreenState extends State<ForexScreen> {
// Add listeners to text fields // Add listeners to text fields
textControllers["_forexStartDate"]?.addListener(_onFieldChanged); textControllers["_forexStartDate"]?.addListener(_onFieldChanged);
textControllers["_forexEndDate"]?.addListener(_onFieldChanged); textControllers["_forexEndDate"]?.addListener(_onFieldChanged);
textControllers["_countries"]?.addListener(_onFieldChanged); // Reattach
flightFirstTripDateNotifier = ValueNotifier<String?>(null); flightFirstTripDateNotifier = ValueNotifier<String?>(null);
flightLastTripDateNotifier = ValueNotifier<String?>(null); flightLastTripDateNotifier = ValueNotifier<String?>(null);
flightFirstTripToPlaceNotifier = ValueNotifier<String?>(null);
WidgetsBinding.instance.addPostFrameCallback((_) async { WidgetsBinding.instance.addPostFrameCallback((_) async {
tripuserId = await getTripUserId(); tripuserId = await getTripUserId();
@ -439,6 +444,7 @@ class _ForexScreenState extends State<ForexScreen> {
flightFirstTripDateNotifier.value = result['firstTripDate']; flightFirstTripDateNotifier.value = result['firstTripDate'];
flightLastTripDateNotifier.value = result['lastTripDate']; flightLastTripDateNotifier.value = result['lastTripDate'];
flightFirstTripToPlaceNotifier.value = result['toTripPlace'];
// Only set controller after value is updated // Only set controller after value is updated
// final parsedDate = // final parsedDate =
@ -489,6 +495,26 @@ class _ForexScreenState extends State<ForexScreen> {
print("flightEndTripDateNotifier is null or empty"); 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( // final parsedEndDate = DateFormat(
// "dd-MM-yyyy", // "dd-MM-yyyy",
// ).parse(flightLastTripDateNotifier.value ?? ''); // ).parse(flightLastTripDateNotifier.value ?? '');
@ -497,7 +523,7 @@ class _ForexScreenState extends State<ForexScreen> {
// 'dd-MM-yyyy', // 'dd-MM-yyyy',
// ).format(parsedEndDate); // ).format(parsedEndDate);
// } // }
_onFieldChanged();
handleUpdatedField(); handleUpdatedField();
}); });
} }

View File

@ -528,6 +528,37 @@ class _FlightListWidgetState extends State<FlightListWidget> {
item["trips"] != null && item["trips"] != null &&
item["trips"].isNotEmpty) item["trips"].isNotEmpty)
...item["trips"].map<Widget>((trip) { ...item["trips"].map<Widget>((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( return Padding(
padding: const EdgeInsets.symmetric(vertical: 6.0), padding: const EdgeInsets.symmetric(vertical: 6.0),
child: Container( child: Container(
@ -547,7 +578,7 @@ class _FlightListWidgetState extends State<FlightListWidget> {
), ),
_buildKeyValueRow( _buildKeyValueRow(
"Sector", "Sector",
"${trip["from_place"] ?? "N/A"} - ${trip["to_place"] ?? "N/A"}", "$fromcity ($fromcode), $fromairport$tocity ($tocode), $toairport",
), ),
_buildKeyValueRow( _buildKeyValueRow(

View File

@ -222,6 +222,14 @@ class ForexListWidget extends StatelessWidget {
itemCount: filteredList.length, itemCount: filteredList.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final item = filteredList[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( return Container(
margin: EdgeInsets.symmetric(horizontal: 8, vertical: 6), margin: EdgeInsets.symmetric(horizontal: 8, vertical: 6),
@ -339,6 +347,46 @@ class ForexListWidget extends StatelessWidget {
// style: TextStyle( // style: TextStyle(
// fontSize: 11, fontFamily: "Archivo"), // 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( Expanded(
flex: 2, flex: 2,
child: Text( child: Text(
@ -386,17 +434,61 @@ class ForexListWidget extends StatelessWidget {
), ),
), ),
SizedBox(width: 10), SizedBox(width: 10),
// Expanded( Expanded(
// flex: 2, flex: 2,
// child: Text( child: Text(
// " ", "$perdiemAmount",
// style: TextStyle( style: GoogleFonts.poppins(
// fontSize: 12, fontSize: 12,
// fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
// fontFamily: "Archivo"), ),
// ), ),
// ), ),
// SizedBox(width: 10), 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( Expanded(
flex: 2, flex: 2,
child: _buildComments( child: _buildComments(
@ -419,7 +511,11 @@ class ForexListWidget extends StatelessWidget {
// SizedBox(height: 6), // SizedBox(height: 6),
_buildRow("StartDate:", item["start_date"]!), _buildRow("StartDate:", item["start_date"]!),
_buildRow("EndDate:", item["end_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"), _buildRow("Comments:", item["comments"] ?? "N/A"),
], ],
), ),