minor issues fixes 7
This commit is contained in:
parent
179e1db5d7
commit
57f7f29054
@ -47,6 +47,7 @@ class FlightScreenState extends State<FlightScreen> {
|
||||
|
||||
bool isCountryLoading = true;
|
||||
late Map<String, String> countryMap;
|
||||
late Map<String, String> countryCodeMap;
|
||||
late List<String> countryCodes;
|
||||
|
||||
late ValueNotifier<String?> flightFirstTripDateNotifier;
|
||||
@ -260,6 +261,7 @@ class FlightScreenState extends State<FlightScreen> {
|
||||
|
||||
// Create a map: Country_Code -> "City, Airport"
|
||||
Map<String, String> tempCountryMap = {};
|
||||
Map<String, String> tempCountryCode = {};
|
||||
|
||||
for (var country in result) {
|
||||
// String city = country['City'] ?? '';
|
||||
@ -269,13 +271,16 @@ class FlightScreenState extends State<FlightScreen> {
|
||||
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<FlightScreen> {
|
||||
// "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<FlightScreen> {
|
||||
(entry) => entry.value == newValue,
|
||||
)
|
||||
.key;
|
||||
|
||||
if (selectedTripType == "Roundtrip") {
|
||||
print('rounfTo${selectedFrom[index]}');
|
||||
// textControllers["_to${index+1}Controller"]?.text = selectedFrom[index]!;
|
||||
|
||||
@ -43,6 +43,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
|
||||
late ValueNotifier<String?> flightFirstTripDateNotifier;
|
||||
late ValueNotifier<String?> flightLastTripDateNotifier;
|
||||
late ValueNotifier<String?> flightFirstTripToPlaceNotifier;
|
||||
// late final tripuserId;
|
||||
String? tripuserId;
|
||||
|
||||
@ -192,7 +193,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
Future<void> postgetForexData(Map<String, dynamic> 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<ForexScreen> {
|
||||
.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<ForexScreen> {
|
||||
|
||||
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<ForexScreen> {
|
||||
// Add listeners to text fields
|
||||
textControllers["_forexStartDate"]?.addListener(_onFieldChanged);
|
||||
textControllers["_forexEndDate"]?.addListener(_onFieldChanged);
|
||||
textControllers["_countries"]?.addListener(_onFieldChanged); // Reattach
|
||||
|
||||
flightFirstTripDateNotifier = ValueNotifier<String?>(null);
|
||||
flightLastTripDateNotifier = ValueNotifier<String?>(null);
|
||||
flightFirstTripToPlaceNotifier = ValueNotifier<String?>(null);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
tripuserId = await getTripUserId();
|
||||
@ -439,6 +444,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
|
||||
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<ForexScreen> {
|
||||
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<ForexScreen> {
|
||||
// 'dd-MM-yyyy',
|
||||
// ).format(parsedEndDate);
|
||||
// }
|
||||
|
||||
_onFieldChanged();
|
||||
handleUpdatedField();
|
||||
});
|
||||
}
|
||||
|
||||
@ -528,6 +528,37 @@ class _FlightListWidgetState extends State<FlightListWidget> {
|
||||
item["trips"] != null &&
|
||||
item["trips"].isNotEmpty)
|
||||
...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(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6.0),
|
||||
child: Container(
|
||||
@ -547,7 +578,7 @@ class _FlightListWidgetState extends State<FlightListWidget> {
|
||||
),
|
||||
_buildKeyValueRow(
|
||||
"Sector",
|
||||
"${trip["from_place"] ?? "N/A"} - ${trip["to_place"] ?? "N/A"}",
|
||||
"$fromcity ($fromcode), $fromairport → $tocity ($tocode), $toairport",
|
||||
),
|
||||
|
||||
_buildKeyValueRow(
|
||||
|
||||
@ -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"),
|
||||
],
|
||||
),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user