date validations

This commit is contained in:
venbaittech 2025-06-11 17:41:07 +05:30
parent 66b62c7ad4
commit b66391fbb5
9 changed files with 535 additions and 405 deletions

View File

@ -898,6 +898,7 @@ class _ApprovalListState extends State<ApprovalList> {
plan.planId, plan.planId,
plan.approverId, plan.approverId,
plan.delegaterId, plan.delegaterId,
plan.approver_status,
isViewMode: isViewMode:
false, false,
isApprover: isApprover:
@ -1144,6 +1145,7 @@ class _ApprovalListState extends State<ApprovalList> {
plan.planId, plan.planId,
plan.approverId, plan.approverId,
plan.delegaterId, plan.delegaterId,
plan.approver_status,
isViewMode: false, isViewMode: false,
isApprover: true, isApprover: true,
); );

View File

@ -125,6 +125,7 @@ class _LoginWidgetState extends State<LoginWidget> {
final token = data['token']; // Assuming the token is in response final token = data['token']; // Assuming the token is in response
// final userId = data['user_id'].toString(); // final userId = data['user_id'].toString();
print("Token - $token");
await storeUserDetails(token); await storeUserDetails(token);
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(

View File

@ -568,7 +568,7 @@ class FlightScreenState extends State<FlightScreen> {
} }
bool validateFields() { bool validateFields() {
// errorMessages.clear(); // Reset errors errorMessages.clear(); // Reset errors
rowCount = 1; // Default row count for One-way rowCount = 1; // Default row count for One-way
if (selectedTripType == "Roundtrip") { if (selectedTripType == "Roundtrip") {
@ -637,7 +637,7 @@ class FlightScreenState extends State<FlightScreen> {
} else { } else {
seenFrom.add(fromValue); seenFrom.add(fromValue);
errorMessages.remove("from_place_$i"); // errorMessages.remove("from_place_$i");
} }
} }
@ -646,7 +646,7 @@ class FlightScreenState extends State<FlightScreen> {
errorMessages["to_place_$i"] = "Duplicate Destination "; errorMessages["to_place_$i"] = "Duplicate Destination ";
print("Error: to_place_$i duplicates a previous departure"); print("Error: to_place_$i duplicates a previous departure");
} else { } else {
errorMessages.remove("to_place_$i"); // errorMessages.remove("to_place_$i");
seenTo.add(toValue); seenTo.add(toValue);
} }
} }

View File

@ -124,6 +124,7 @@ class _CreatePlansState extends State<CreatePlan> {
final bool isApprover = args?['isApprover'] ?? false; final bool isApprover = args?['isApprover'] ?? false;
final String approverId = args['approverId'] ?? ""; final String approverId = args['approverId'] ?? "";
final String delegaterId = args['delegaterId'] ?? ""; final String delegaterId = args['delegaterId'] ?? "";
final String approverStatus = args['approver_status'] ?? "";
final Map<String, dynamic> planData = final Map<String, dynamic> planData =
args['planData'] as Map<String, dynamic>? ?? {}; args['planData'] as Map<String, dynamic>? ?? {};
@ -216,6 +217,7 @@ class _CreatePlansState extends State<CreatePlan> {
isApprover: isApprover, isApprover: isApprover,
approverId: approverId, approverId: approverId,
delegaterId: delegaterId, delegaterId: delegaterId,
approverStatus: approverStatus,
), ),
), ),
), ),
@ -325,6 +327,7 @@ class CreateNewPlan extends StatefulWidget {
final bool isDesktop; final bool isDesktop;
final bool isViewMode; final bool isViewMode;
final bool isApprover; final bool isApprover;
final String? approverStatus;
final Color? bodyColor; final Color? bodyColor;
final Color? layoutColor; final Color? layoutColor;
@ -341,6 +344,7 @@ class CreateNewPlan extends StatefulWidget {
required this.selectedPlanData, required this.selectedPlanData,
required this.isViewMode, required this.isViewMode,
required this.isApprover, required this.isApprover,
required this.approverStatus,
required this.approverId, required this.approverId,
required this.delegaterId, required this.delegaterId,
}); });
@ -375,6 +379,7 @@ class CreateNewPlansState extends State<CreateNewPlan> {
bool isStatusExpanded = false; bool isStatusExpanded = false;
bool isShowApprovalAction = false; bool isShowApprovalAction = false;
String? selectedPlanId; String? selectedPlanId;
String? approverStatus;
String? userDetails; String? userDetails;
String? userName; String? userName;
@ -502,7 +507,11 @@ class CreateNewPlansState extends State<CreateNewPlan> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
print("approverStatus - ${widget.approverStatus}");
if (widget.approverStatus == "Approval pending") {
print("Status approver - Approval Pending");
}
flightTripTypeNotifier = ValueNotifier(null); flightTripTypeNotifier = ValueNotifier(null);
fetchUserDetails(); fetchUserDetails();
@ -1169,6 +1178,8 @@ class CreateNewPlansState extends State<CreateNewPlan> {
data['plan_id'], data['plan_id'],
data['approverId'], data['approverId'],
data['delegaterId'], data['delegaterId'],
data['approver_status'],
isViewMode: false, isViewMode: false,
isApprover: true, isApprover: true,
); );
@ -1295,376 +1306,374 @@ class CreateNewPlansState extends State<CreateNewPlan> {
), ),
); );
return return FocusTraversalGroup(
FocusTraversalGroup(
policy: OrderedTraversalPolicy(), // 👈 more predictable tab order policy: OrderedTraversalPolicy(), // 👈 more predictable tab order
descendantsAreFocusable: true, descendantsAreFocusable: true,
child: ResponsiveBuilder( child: ResponsiveBuilder(
builder: (context, sizingInfo) { builder: (context, sizingInfo) {
bool isMobile = sizingInfo.isMobile; bool isMobile = sizingInfo.isMobile;
bool isDesktop = bool isDesktop =
sizingInfo.deviceScreenType == DeviceScreenType.desktop; sizingInfo.deviceScreenType == DeviceScreenType.desktop;
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Row(
children: [ children: [
Expanded( Expanded(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
ResponsiveBuilder( ResponsiveBuilder(
builder: (context, sizingInfo) { builder: (context, sizingInfo) {
bool isDesktop = bool isDesktop =
sizingInfo.deviceScreenType == sizingInfo.deviceScreenType ==
DeviceScreenType.desktop; DeviceScreenType.desktop;
return Container( return Container(
padding: const EdgeInsets.all(5), padding: const EdgeInsets.all(5),
child: child:
isDesktop isDesktop
? Row( ? Row(
crossAxisAlignment: crossAxisAlignment:
CrossAxisAlignment.start, CrossAxisAlignment.start,
// mainAxisAlignment: MainAxisAlignment.end, // mainAxisAlignment: MainAxisAlignment.end,
children: [ children: [
_buildTripName(isDesktop), _buildTripName(isDesktop),
if (isDesktop) Spacer(), if (isDesktop) Spacer(),
..._buildApproverControls(isDesktop), ..._buildApproverControls(isDesktop),
// Text( // Text(
// widget.isViewMode // widget.isViewMode
// ? "View Plan" // ? "View Plan"
// : (selectedPlanId != null && // : (selectedPlanId != null &&
// selectedPlanId!.isNotEmpty // selectedPlanId!.isNotEmpty
// ? "Update Plan" // ? "Update Plan"
// : "New Plan"), // : "New Plan"),
// style: TextStyle(fontSize: 18), // style: TextStyle(fontSize: 18),
// ), // ),
// Spacer(), // Spacer(),
if (statusValue != "") if (statusValue != "")
..._buildPlanPdf(isDesktop), ..._buildPlanPdf(isDesktop),
], ],
) )
: Column( : Column(
children: [ children: [
Row( Row(
// crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment.end, MainAxisAlignment.end,
children: [ children: [
..._buildApproverControls( ..._buildApproverControls(
isDesktop, isDesktop,
), ),
if (statusValue != "") if (statusValue != "")
..._buildPlanPdf(isDesktop), ..._buildPlanPdf(isDesktop),
], ],
), ),
Row( Row(
crossAxisAlignment: crossAxisAlignment:
CrossAxisAlignment.start, CrossAxisAlignment.start,
children: [_buildTripName(isDesktop)], children: [
), _buildTripName(isDesktop),
], ],
), ),
); ],
}, ),
), );
// if (isStatusExpanded) },
// Container( ),
// margin: isDesktop // if (isStatusExpanded)
// ? const EdgeInsets.only(left: 0, top: 0) // Container(
// : const EdgeInsets.only(left: 5, top: 2), // margin: isDesktop
// padding: const EdgeInsets.all(12), // ? const EdgeInsets.only(left: 0, top: 0)
// width: isDesktop // : const EdgeInsets.only(left: 5, top: 2),
// ? MediaQuery.of(context).size.width * 0.2 // padding: const EdgeInsets.all(12),
// : MediaQuery.of(context).size.width, // width: isDesktop
// decoration: BoxDecoration( // ? MediaQuery.of(context).size.width * 0.2
// color: Color(0xFFF5F5F5), // : MediaQuery.of(context).size.width,
// border: Border.all( // decoration: BoxDecoration(
// // color: Colors.grey.shade300, // color: Color(0xFFF5F5F5),
// color: Colors.white, // border: Border.all(
// width: 0.2), // // color: Colors.grey.shade300,
// borderRadius: BorderRadius.circular(8), // color: Colors.white,
// // boxShadow: [ // width: 0.2),
// // BoxShadow( // borderRadius: BorderRadius.circular(8),
// // // color: Colors.grey.withAlpha(20), // // boxShadow: [
// // color: Colors.grey.withAlpha(20), // // BoxShadow(
// // spreadRadius: 1.5, // // // color: Colors.grey.withAlpha(20),
// // blurRadius: 7, // // color: Colors.grey.withAlpha(20),
// // offset: Offset(0, 4), // shadow direction: bottom // // spreadRadius: 1.5,
// // ), // // blurRadius: 7,
// // ], // // offset: Offset(0, 4), // shadow direction: bottom
// ), // // ),
// child: Column( // // ],
// crossAxisAlignment: CrossAxisAlignment.start, // ),
// children: [ // child: Column(
// if (!hasApprovals) // crossAxisAlignment: CrossAxisAlignment.start,
// Center( // children: [
// child: Text( // if (!hasApprovals)
// "--- No Approvals ---", // Center(
// style: TextStyle( // child: Text(
// fontFamily: "Archivo", // "--- No Approvals ---",
// fontSize: 11, // style: TextStyle(
// fontWeight: FontWeight.w500, // fontFamily: "Archivo",
// color: Colors.black87, // fontSize: 11,
// ), // fontWeight: FontWeight.w500,
// )), // color: Colors.black87,
// for (int i = 0; i < planStatusList.length; i++) ...[ // ),
// if (planStatusList[i].entries.any((entry) => // )),
// entry.key.contains('status') && // for (int i = 0; i < planStatusList.length; i++) ...[
// entry.value != null && // if (planStatusList[i].entries.any((entry) =>
// entry.value.toString().isNotEmpty)) ...[ // entry.key.contains('status') &&
// _buildApprovalItem( // entry.value != null &&
// "Approver ${i + 1}", // entry.value.toString().isNotEmpty)) ...[
// planStatusList[i] // _buildApprovalItem(
// .entries // "Approver ${i + 1}",
// .firstWhere( // planStatusList[i]
// (entry) => entry.key.contains('status'), // .entries
// orElse: () => MapEntry('', ''), // .firstWhere(
// ) // (entry) => entry.key.contains('status'),
// .value // orElse: () => MapEntry('', ''),
// .toString(), // )
// ), // .value
// SizedBox(height: 6), // .toString(),
// ], // ),
// ], // SizedBox(height: 6),
// ], // ],
// ), // ],
// ), // ],
if (isApproverRejected) // ),
Row( // ),
crossAxisAlignment: CrossAxisAlignment.start, if (isApproverRejected)
children: [ Row(
const Padding( crossAxisAlignment: CrossAxisAlignment.start,
padding: EdgeInsets.only(top: 4, left: 8), children: [
child: Text( const Padding(
"Remarks : ", padding: EdgeInsets.only(top: 4, left: 8),
style: TextStyle( child: Text(
fontFamily: "Archivo", "Remarks : ",
fontWeight: FontWeight.w600,
fontSize: 11,
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
top: 0,
), // tweak if needed
child: TextFormField(
controller: _remarksController,
style: TextStyle( style: TextStyle(
fontFamily: "Archivo", fontFamily: "Archivo",
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
fontSize: 11, fontSize: 11,
), ),
decoration: InputDecoration(
hintText: "Please enter remarks...",
hintStyle: GoogleFonts.poppins(
fontSize: 13,
color: Colors.grey,
),
border: InputBorder.none,
isDense: true,
),
maxLines: null,
), ),
), ),
), Expanded(
], child: Padding(
), padding: const EdgeInsets.only(
top: 0,
// if (widget.isApprover || isStatusExpanded) ), // tweak if needed
Divider(thickness: 0.1, color: Colors.blueGrey), child: TextFormField(
if (widget.isApprover) SizedBox(height: 5), controller: _remarksController,
style: TextStyle(
Text( fontFamily: "Archivo",
"Planning This Trip For*", // Your label fontWeight: FontWeight.w600,
style: GoogleFonts.poppins( fontSize: 11,
fontSize: 12, ),
fontWeight: FontWeight.w600, decoration: InputDecoration(
color: Color(0xFF575A74), hintText: "Please enter remarks...",
), hintStyle: GoogleFonts.poppins(
), fontSize: 13,
SizedBox(height: 6), color: Colors.grey,
isDesktop ),
? SingleChildScrollView( border: InputBorder.none,
scrollDirection: Axis.horizontal, isDense: true,
child: Row(children: _buildPlanTrip(isDesktop)), ),
) maxLines: null,
: Row(children: _buildPlanTrip(isDesktop)), ),
SizedBox(height: 7), ),
// Text(
// otherUserName ?? userName ?? " ", // Your label
//
// style: GoogleFonts.poppins(
// fontSize: 11,
// fontWeight: FontWeight.w400,
// color: widget.layoutColor,
// ),
// ),
Text.rich(
TextSpan(
text: "Trip Planned User : ", // Static text
style: GoogleFonts.poppins(
fontSize: 11,
fontWeight: FontWeight.w400,
color: Color(0xFF212121),
// color: Color(0xFF575A74), // Default color
),
children: [
TextSpan(
text:
otherUserName ??
userName ??
" ", // Dynamic username
style: GoogleFonts.poppins(
fontSize: 11,
fontWeight: FontWeight.w400,
color:
widget
.layoutColor, // Change this to any color
// color: Colors.blueAccent, // Change this to any color
), ),
), ],
], ),
// if (widget.isApprover || isStatusExpanded)
Divider(thickness: 0.1, color: Colors.blueGrey),
if (widget.isApprover) SizedBox(height: 5),
Text(
"Planning This Trip For*", // Your label
style: GoogleFonts.poppins(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Color(0xFF575A74),
),
), ),
), SizedBox(height: 6),
SizedBox(height: 5), isDesktop
], ? SingleChildScrollView(
), scrollDirection: Axis.horizontal,
), child: Row(children: _buildPlanTrip(isDesktop)),
], )
), : Row(children: _buildPlanTrip(isDesktop)),
SizedBox(height: 7),
// Padding( // Text(
// padding: const EdgeInsets.all(8.0), // otherUserName ?? userName ?? " ", // Your label
// child: Divider( //
// color: Color(0xFFE6E7F5), // Change color // style: GoogleFonts.poppins(
// thickness: 0.5, // fontSize: 11,
// ), // fontWeight: FontWeight.w400,
// ), // color: widget.layoutColor,
SizedBox(height: 10), // ),
// ),
// Row( Text.rich(
// children: [ TextSpan(
// Expanded( text: "Trip Planned User : ", // Static text
// child: style: GoogleFonts.poppins(
// ), fontSize: 11,
// ], fontWeight: FontWeight.w400,
// ), color: Color(0xFF212121),
isDesktop // color: Color(0xFF575A74), // Default color
? Row( ),
crossAxisAlignment: CrossAxisAlignment.start, children: [
children: _buildTripRow(isMobile), TextSpan(
) text:
: Column( otherUserName ??
crossAxisAlignment: CrossAxisAlignment.start, userName ??
children: _buildTripRow(isMobile), " ", // Dynamic username
), style: GoogleFonts.poppins(
SizedBox(height: 15), fontSize: 11,
fontWeight: FontWeight.w400,
isDesktop color:
? Row( widget
crossAxisAlignment: CrossAxisAlignment.start, .layoutColor, // Change this to any color
children: _buildCostCenter(isDesktop), // color: Colors.blueAccent, // Change this to any color
) ),
: Column( ),
crossAxisAlignment: CrossAxisAlignment.start, ],
children: _buildCostCenter(isDesktop), ),
), ),
SizedBox(height: 8), SizedBox(height: 5),
isDesktop ],
? Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// _buildNonDescriptionColumn(),
// SizedBox(width: 25),
_buildDescriptionColumn(isDesktop),
],
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// _buildNonDescriptionColumn(),
// SizedBox(height: 15),
_buildDescriptionColumn(isDesktop),
],
),
// Padding(
// padding: const EdgeInsets.all(8.0),
// child: Divider(
// color: Color(0xFFE6E7F5), // Change color
// thickness: 0.5,
// ),
// ),
SizedBox(height: 20),
if (temporaryMessage != null)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
// validationErrors["services"]!,
temporaryMessage!,
style: GoogleFonts.poppins(
color: Colors.red,
fontSize: 12,
fontWeight: FontWeight.w400,
), ),
), ),
], ],
), ),
if (temporaryMessage != null) SizedBox(height: 10), // Padding(
Row( // padding: const EdgeInsets.all(8.0),
children: [ // child: Divider(
Expanded( // color: Color(0xFFE6E7F5), // Change color
child: DynamicItinerary( // thickness: 0.5,
key: dynamicItineraryKey, // ),
flightScreenKey: flightScreenKey, // ),
tripTypeNotifier: flightTripTypeNotifier, SizedBox(height: 10),
hasAction: hasAction,
tripType: _selectedTripType, // Row(
apiData: apiData, // children: [
apiDataForClass: apiDataForClass, // Expanded(
apiCountryData: apiCountryData, // child:
onItineraryUpdate: handleItineraryUpdate, // ),
loginUser: selfId, // ],
selectedPlanData: planData, // ),
isViewMode: widget.isViewMode, isDesktop
? Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: _buildTripRow(isMobile),
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: _buildTripRow(isMobile),
), ),
), // Wrap with Expanded if needed SizedBox(height: 15),
],
),
SizedBox(height: 15),
],
);
// Row( isDesktop
// children: [ ? Row(
// isDesktop crossAxisAlignment: CrossAxisAlignment.start,
// ? Row( children: _buildCostCenter(isDesktop),
// mainAxisAlignment: MainAxisAlignment.end, )
// children: _buildSubmit(isDesktop), : Column(
// ) crossAxisAlignment: CrossAxisAlignment.start,
// : Row( children: _buildCostCenter(isDesktop),
// mainAxisAlignment: MainAxisAlignment.center, ),
// children: _buildSubmit(isDesktop), SizedBox(height: 8),
// ) isDesktop
// ], ? Row(
// ) crossAxisAlignment: CrossAxisAlignment.start,
}, children: [
) // _buildNonDescriptionColumn(),
// replace with your full form column // SizedBox(width: 25),
); _buildDescriptionColumn(isDesktop),
],
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// _buildNonDescriptionColumn(),
// SizedBox(height: 15),
_buildDescriptionColumn(isDesktop),
],
),
// Padding(
// padding: const EdgeInsets.all(8.0),
// child: Divider(
// color: Color(0xFFE6E7F5), // Change color
// thickness: 0.5,
// ),
// ),
SizedBox(height: 20),
if (temporaryMessage != null)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
// validationErrors["services"]!,
temporaryMessage!,
style: GoogleFonts.poppins(
color: Colors.red,
fontSize: 12,
fontWeight: FontWeight.w400,
),
),
],
),
if (temporaryMessage != null) SizedBox(height: 10),
Row(
children: [
Expanded(
child: DynamicItinerary(
key: dynamicItineraryKey,
flightScreenKey: flightScreenKey,
tripTypeNotifier: flightTripTypeNotifier,
hasAction: hasAction,
tripType: _selectedTripType,
apiData: apiData,
apiDataForClass: apiDataForClass,
apiCountryData: apiCountryData,
onItineraryUpdate: handleItineraryUpdate,
loginUser: selfId,
selectedPlanData: planData,
isViewMode: widget.isViewMode,
),
), // Wrap with Expanded if needed
],
),
SizedBox(height: 15),
],
);
// Row(
// children: [
// isDesktop
// ? Row(
// mainAxisAlignment: MainAxisAlignment.end,
// children: _buildSubmit(isDesktop),
// )
// : Row(
// mainAxisAlignment: MainAxisAlignment.center,
// children: _buildSubmit(isDesktop),
// )
// ],
// )
},
),
// replace with your full form column
);
} }
// String? getSelectedCostCenterName() { // String? getSelectedCostCenterName() {
@ -3141,7 +3150,7 @@ class CreateNewPlansState extends State<CreateNewPlan> {
// ], // ],
// ), // ),
const SizedBox(height: 10, width: 10), const SizedBox(height: 10, width: 10),
if (widget.isApprover) if (widget.isApprover && (widget.approverStatus == "Approval pending"))
GestureDetector( GestureDetector(
// onTap: () { // onTap: () {
// setState(() { // setState(() {

View File

@ -656,7 +656,7 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
void handleSubmit() async { void handleSubmit() async {
print("USR Detail Submit"); print("USR Detail Submit");
// printFormData(); // printFormData();
print("travel validation");
bool isValid = travellerDetailsKey.currentState?.boolValidation() ?? false; bool isValid = travellerDetailsKey.currentState?.boolValidation() ?? false;
if (selectedRole == "5" || setSelectesUserType == true) { if (selectedRole == "5" || setSelectesUserType == true) {
print("NO validation"); print("NO validation");

View File

@ -155,6 +155,9 @@ class TravellerDetailsState extends State<TravellerDetails> {
} }
bool boolValidation() { bool boolValidation() {
print("travel validation start");
print("visaEntries - $visaEntries");
final passportText = controllers["passportNumber"]?.text ?? ""; final passportText = controllers["passportNumber"]?.text ?? "";
if (_selectedTripType == "Indian") { if (_selectedTripType == "Indian") {
@ -173,6 +176,80 @@ class TravellerDetailsState extends State<TravellerDetails> {
} }
} }
final format = DateFormat("dd-MM-yyyy");
DateTime? start_Date;
DateTime? end_Date;
try {
if (controllers["dateOfIssue"]?.text != null &&
controllers["dateOfIssue"]!.text.isNotEmpty) {
start_Date = format.parse(controllers["dateOfIssue"]!.text);
}
if (controllers["dateOfExpiry"]?.text != null &&
controllers["dateOfExpiry"]!.text.isNotEmpty) {
end_Date = format.parse(controllers["dateOfExpiry"]!.text);
}
if (start_Date != null &&
end_Date != null &&
end_Date.isBefore(start_Date)) {
setState(() {
errorMessages["date_of_expiry"] = "End date cannot be earlier";
});
print("End date cannot be earlier than start date");
}
} catch (e) {
print("Invalid passport date format");
}
// Additional validation starts - travelDetailsData passport
// DateTime? start_Date = travelDetailsData?['date_of_issue'];
// DateTime? end_Date = travelDetailsData?['date_of_expiry'];
//
// if (start_Date != null &&
// end_Date != null &&
// start_Date.toString().isNotEmpty &&
// end_Date.toString().isNotEmpty) {
// try {
// final format = DateFormat("dd-MM-yyyy");
// final checkStartDate = format.parse("$start_Date");
// final checkEndDate = format.parse("$end_Date");
//
// if (checkEndDate.isBefore(checkStartDate)) {
// // return "End date cannot be earlier than start date";;
// return;
// }
// } catch (e) {
// // return "End date cannot be earlier than start date";
// return;
// // errorMessages["end_date"] = "Invalid date format";
// }
// }
// valid_from: 20-06-2025, valid_upto: 19-06-2025
// DateTime? valid_from = data?['valid_from'];
// DateTime? valid_upto = data?['valid_upto'];
//
// if (valid_from != null &&
// valid_upto != null &&
// valid_from.toString().isNotEmpty &&
// valid_upto.toString().isNotEmpty) {
// try {
// final format = DateFormat("dd-MM-yyyy");
// final checkValidFrom = format.parse("$valid_from");
// final checkValidUpto = format.parse("$valid_upto");
//
// if (checkValidUpto.isBefore(checkValidFrom)) {
// // return "valid upto cannot be earlier than valid from";
// }
// } catch (e) {
// // return "valid upto cannot be earlier than valid from";
//
// // errorMessages["end_date"] = "Invalid date format";
// }
// }
print("travel validation end");
return true; return true;
} }
@ -1355,30 +1432,34 @@ class TravellerDetailsState extends State<TravellerDetails> {
DateTime? _selectedDateOfExpiry; DateTime? _selectedDateOfExpiry;
Widget buildDateOfIssue() { Widget buildDateOfIssue() {
Future<void> _selectCheckDateOfIssue(BuildContext context) async { Future<void> _selectCheckDateOfIssue(BuildContext context) async {
DateTime now = DateTime.now(); DateTime now = DateTime.now();
DateTime today = DateTime(now.year, now.month, now.day); DateTime today = DateTime(now.year, now.month, now.day);
DateTime? pickedDate = await showDatePicker( DateTime? pickedDate = await showDatePicker(
context: context, context: context,
initialDate: _selectedDateOfIssue != null && _selectedDateOfIssue!.isAfter(today) initialDate:
? _selectedDateOfIssue! _selectedDateOfIssue != null && _selectedDateOfIssue!.isAfter(today)
: today, ? _selectedDateOfIssue!
: today,
firstDate: DateTime(1900), firstDate: DateTime(1900),
lastDate: DateTime(2100), // lastDate: DateTime(2100),
lastDate: today,
initialEntryMode: DatePickerEntryMode.calendarOnly, initialEntryMode: DatePickerEntryMode.calendarOnly,
); );
if (pickedDate != null && pickedDate != _selectedDateOfIssue) { if (pickedDate != null && pickedDate != _selectedDateOfIssue) {
setState(() { setState(() {
_selectedDateOfIssue = pickedDate; _selectedDateOfIssue = pickedDate;
controllers["dateOfIssue"]?.text = DateFormat('dd-MM-yyyy').format(pickedDate); controllers["dateOfIssue"]?.text = DateFormat(
'dd-MM-yyyy',
).format(pickedDate);
// Revalidate expiry // Revalidate expiry
if (_selectedDateOfExpiry != null && if (_selectedDateOfExpiry != null &&
_selectedDateOfExpiry!.isBefore(_selectedDateOfIssue!)) { _selectedDateOfExpiry!.isBefore(_selectedDateOfIssue!)) {
errorMessages["date_of_expiry"] = "Expiry date cannot be earlier than Issue date"; errorMessages["date_of_expiry"] =
"Expiry date cannot be earlier than Issue date";
} else { } else {
errorMessages.remove("date_of_expiry"); errorMessages.remove("date_of_expiry");
} }
@ -1400,25 +1481,25 @@ class TravellerDetailsState extends State<TravellerDetails> {
SizedBox(height: 5), SizedBox(height: 5),
CustomTextFieldUserTravellerWrapper( CustomTextFieldUserTravellerWrapper(
width: width:
widget.isDesktop widget.isDesktop
? MediaQuery.of(context).size.width * 0.13 ? MediaQuery.of(context).size.width * 0.13
: null, : null,
isFocused: false, isFocused: false,
isDesktop: widget.isDesktop, isDesktop: widget.isDesktop,
child: SizedBox( child: SizedBox(
height: 40, height: 40,
child: GestureDetector( child: GestureDetector(
onTap: onTap:
widget.isViewMode widget.isViewMode
? null ? null
: () async { : () async {
await _selectCheckDateOfIssue(context); await _selectCheckDateOfIssue(context);
if (controllers["dateOfIssue"]!.text.isNotEmpty) { if (controllers["dateOfIssue"]!.text.isNotEmpty) {
setState(() { setState(() {
// errorMessages.remove("start_date"); // errorMessages.remove("start_date");
}); });
} }
}, },
child: AbsorbPointer( child: AbsorbPointer(
child: TextField( child: TextField(
controller: controllers["dateOfIssue"], controller: controllers["dateOfIssue"],
@ -1448,9 +1529,7 @@ class TravellerDetailsState extends State<TravellerDetails> {
} }
Widget buildDateOfExpiry() { Widget buildDateOfExpiry() {
Future<void> _selectCheckDateOfExpiry(BuildContext context) async { Future<void> _selectCheckDateOfExpiry(BuildContext context) async {
DateTime now = DateTime.now(); DateTime now = DateTime.now();
DateTime today = DateTime(now.year, now.month, now.day); DateTime today = DateTime(now.year, now.month, now.day);
// DateTime firstDate = today; // DateTime firstDate = today;
@ -1499,11 +1578,14 @@ class TravellerDetailsState extends State<TravellerDetails> {
if (pickedDate != null) { if (pickedDate != null) {
setState(() { setState(() {
_selectedDateOfExpiry = pickedDate; _selectedDateOfExpiry = pickedDate;
controllers["dateOfExpiry"]?.text = DateFormat("dd-MM-yyyy").format(pickedDate); controllers["dateOfExpiry"]?.text = DateFormat(
"dd-MM-yyyy",
).format(pickedDate);
if (_selectedDateOfIssue != null && if (_selectedDateOfIssue != null &&
_selectedDateOfExpiry!.isBefore(_selectedDateOfIssue!)) { _selectedDateOfExpiry!.isBefore(_selectedDateOfIssue!)) {
errorMessages["date_of_expiry"] = "Expiry date cannot be earlier than Issue date"; errorMessages["date_of_expiry"] =
"Expiry date cannot be earlier than Issue date";
} else { } else {
errorMessages.remove("date_of_expiry"); errorMessages.remove("date_of_expiry");
} }
@ -1539,23 +1621,23 @@ class TravellerDetailsState extends State<TravellerDetails> {
isFocused: false, isFocused: false,
isDesktop: widget.isDesktop, isDesktop: widget.isDesktop,
width: width:
widget.isDesktop widget.isDesktop
? MediaQuery.of(context).size.width * 0.13 ? MediaQuery.of(context).size.width * 0.13
: null, : null,
child: SizedBox( child: SizedBox(
height: 40, height: 40,
child: GestureDetector( child: GestureDetector(
onTap: onTap:
widget.isViewMode widget.isViewMode
? null ? null
: () async { : () async {
await _selectCheckDateOfExpiry(context); await _selectCheckDateOfExpiry(context);
if (controllers["dateOfExpiry"]!.text.isNotEmpty) { if (controllers["dateOfExpiry"]!.text.isNotEmpty) {
setState(() { setState(() {
// errorMessages.remove("start_date"); // errorMessages.remove("start_date");
}); });
} }
}, },
child: AbsorbPointer( child: AbsorbPointer(
child: TextField( child: TextField(
controller: controllers["dateOfExpiry"], controller: controllers["dateOfExpiry"],
@ -1586,7 +1668,8 @@ class TravellerDetailsState extends State<TravellerDetails> {
errorMessages["date_of_expiry"]!, errorMessages["date_of_expiry"]!,
style: const TextStyle(color: Colors.red, fontSize: 10), style: const TextStyle(color: Colors.red, fontSize: 10),
maxLines: 2, // Allow it to wrap onto two lines maxLines: 2, // Allow it to wrap onto two lines
overflow: TextOverflow.ellipsis, // Add ellipsis if it still overflows overflow:
TextOverflow.ellipsis, // Add ellipsis if it still overflows
), ),
], ],
], ],
@ -4054,7 +4137,6 @@ class TravellerDetailsState extends State<TravellerDetails> {
DateTime? _selectedCheckInDate; DateTime? _selectedCheckInDate;
Widget buildVisaValidFrom(Map<String, dynamic> entry) { Widget buildVisaValidFrom(Map<String, dynamic> entry) {
TimeOfDay? _selectedCheckOutTime; TimeOfDay? _selectedCheckOutTime;
Future<void> _selectValidFromDate(BuildContext context) async { Future<void> _selectValidFromDate(BuildContext context) async {
@ -4075,19 +4157,23 @@ class TravellerDetailsState extends State<TravellerDetails> {
// initialDate: initialDate, // initialDate: initialDate,
// firstDate: initialDate, // firstDate: initialDate,
firstDate: DateTime(1900), firstDate: DateTime(1900),
lastDate: DateTime(2100), // lastDate: DateTime(2100),
lastDate: today,
initialEntryMode: DatePickerEntryMode.calendarOnly, initialEntryMode: DatePickerEntryMode.calendarOnly,
); );
if (pickedDate != null && pickedDate != _selectedCheckOutDate) { if (pickedDate != null && pickedDate != _selectedCheckOutDate) {
setState(() { setState(() {
_selectedCheckInDate = pickedDate; _selectedCheckInDate = pickedDate;
entry["controller_valid_from"]?.text = DateFormat('dd-MM-yyyy').format(pickedDate); entry["controller_valid_from"]?.text = DateFormat(
'dd-MM-yyyy',
).format(pickedDate);
// Revalidate expiry // Revalidate expiry
if (_selectedCheckOutDate != null && if (_selectedCheckOutDate != null &&
_selectedCheckOutDate!.isBefore(_selectedCheckInDate!)) { _selectedCheckOutDate!.isBefore(_selectedCheckInDate!)) {
errorMessages["valid_upto"] = "valid upto cannot be earlier than valid from"; errorMessages["valid_upto"] =
"valid upto cannot be earlier than valid from";
} else { } else {
errorMessages.remove("valid_upto"); errorMessages.remove("valid_upto");
} }
@ -4109,9 +4195,9 @@ class TravellerDetailsState extends State<TravellerDetails> {
SizedBox(height: 5), SizedBox(height: 5),
CustomTextFieldUserTravellerWrapper( CustomTextFieldUserTravellerWrapper(
width: width:
widget.isDesktop widget.isDesktop
? MediaQuery.of(context).size.width * 0.15 ? MediaQuery.of(context).size.width * 0.15
: null, : null,
isFocused: false, isFocused: false,
isDesktop: widget.isDesktop, isDesktop: widget.isDesktop,
child: SizedBox( child: SizedBox(
@ -4148,7 +4234,6 @@ class TravellerDetailsState extends State<TravellerDetails> {
} }
Widget buildVisaValidUpTo(Map<String, dynamic> entry) { Widget buildVisaValidUpTo(Map<String, dynamic> entry) {
TimeOfDay? _selectedCheckOutTime; TimeOfDay? _selectedCheckOutTime;
Future<void> _selectValidUpToDate(BuildContext context) async { Future<void> _selectValidUpToDate(BuildContext context) async {
@ -4199,11 +4284,14 @@ class TravellerDetailsState extends State<TravellerDetails> {
if (pickedDate != null && pickedDate != _selectedCheckOutDate) { if (pickedDate != null && pickedDate != _selectedCheckOutDate) {
setState(() { setState(() {
_selectedCheckOutDate = pickedDate; _selectedCheckOutDate = pickedDate;
entry["controller_valid_upto"].text = DateFormat("dd-MM-yyyy").format(pickedDate); entry["controller_valid_upto"].text = DateFormat(
"dd-MM-yyyy",
).format(pickedDate);
if (_selectedCheckInDate != null && if (_selectedCheckInDate != null &&
_selectedCheckOutDate!.isBefore(_selectedCheckInDate!)) { _selectedCheckOutDate!.isBefore(_selectedCheckInDate!)) {
errorMessages["valid_upto"] = "valid upto cannot be earlier than valid from"; errorMessages["valid_upto"] =
"valid upto cannot be earlier than valid from";
} else { } else {
errorMessages.remove("valid_upto"); errorMessages.remove("valid_upto");
} }
@ -4225,9 +4313,9 @@ class TravellerDetailsState extends State<TravellerDetails> {
SizedBox(height: 5), SizedBox(height: 5),
CustomTextFieldUserTravellerWrapper( CustomTextFieldUserTravellerWrapper(
width: width:
widget.isDesktop widget.isDesktop
? MediaQuery.of(context).size.width * 0.15 ? MediaQuery.of(context).size.width * 0.15
: null, : null,
isFocused: false, isFocused: false,
isDesktop: widget.isDesktop, isDesktop: widget.isDesktop,
child: SizedBox( child: SizedBox(
@ -4265,7 +4353,8 @@ class TravellerDetailsState extends State<TravellerDetails> {
errorMessages["valid_upto"]!, errorMessages["valid_upto"]!,
style: const TextStyle(color: Colors.red, fontSize: 10), style: const TextStyle(color: Colors.red, fontSize: 10),
maxLines: 2, // Allow it to wrap onto two lines maxLines: 2, // Allow it to wrap onto two lines
overflow: TextOverflow.ellipsis, // Add ellipsis if it still overflows overflow:
TextOverflow.ellipsis, // Add ellipsis if it still overflows
), ),
], ],
], ],

View File

@ -5,6 +5,7 @@ class Plan {
final String tripTitle; final String tripTitle;
final String tripType; final String tripType;
final String status; final String status;
final String approver_status;
final String costCenter; final String costCenter;
final String functionalDepartment; final String functionalDepartment;
final String purposeOfTravel; final String purposeOfTravel;
@ -23,6 +24,7 @@ class Plan {
required this.planId, required this.planId,
this.employeeCode, this.employeeCode,
required this.tripTitle, required this.tripTitle,
required this.approver_status,
required this.tripType, required this.tripType,
required this.status, required this.status,
required this.costCenter, required this.costCenter,
@ -46,6 +48,7 @@ class Plan {
employeeCode: json['employee_code'], employeeCode: json['employee_code'],
tripTitle: json['trip_title'], tripTitle: json['trip_title'],
tripType: json['trip_type_value'], tripType: json['trip_type_value'],
approver_status: json['approver_status'],
status: json['status'] == "0" ? "Inactive" : "Active", status: json['status'] == "0" ? "Inactive" : "Active",
costCenter: json['cost_center_value'] ?? '', costCenter: json['cost_center_value'] ?? '',
functionalDepartment: json['functional_department_value'] ?? '', functionalDepartment: json['functional_department_value'] ?? '',

View File

@ -117,6 +117,7 @@ class _CustomAppBarState extends State<CustomAppBar> {
"name": "${userDetails["first_name"]} ${userDetails["last_name"]}", "name": "${userDetails["first_name"]} ${userDetails["last_name"]}",
"email": userDetails["email"] ?? "", "email": userDetails["email"] ?? "",
"role": userDetails["role"] ?? "", "role": userDetails["role"] ?? "",
"last_login_at": userDetails["last_login_at"] ?? "",
}; };
} catch (e) { } catch (e) {
print("Error decoding user data: $e"); print("Error decoding user data: $e");
@ -282,6 +283,18 @@ class _CustomAppBarState extends State<CustomAppBar> {
}); });
} }
Future<void> logout(BuildContext context) async {
// Clear localStorage
final prefs = await SharedPreferences.getInstance();
await prefs.clear(); // Clears all keys
// Optional: clear sessionStorage if used
// html.window.sessionStorage.clear();
// Navigate to login or home page
context.go('/');
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AppBar( return AppBar(
@ -431,7 +444,7 @@ class _CustomAppBarState extends State<CustomAppBar> {
actions: [ actions: [
Padding( Padding(
padding: EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
horizontal: MediaQuery.of(context).size.width * 0.05, horizontal: MediaQuery.of(context).size.width * 0.055,
), ),
child: Row( child: Row(
children: [ children: [
@ -478,7 +491,8 @@ class _CustomAppBarState extends State<CustomAppBar> {
}, },
); );
case '/logout': case '/logout':
context.go('/'); logout(context);
// context.go('/');
break; break;
} }
}, },
@ -523,6 +537,15 @@ class _CustomAppBarState extends State<CustomAppBar> {
color: Colors.black, color: Colors.black,
), ),
), ),
Text(
"Last Login: ${userData?["last_login_at"]}" ??
'',
style: GoogleFonts.poppins(
fontSize: 8.5,
fontWeight: FontWeight.w400,
color: Colors.black,
),
),
const Divider(), // 👈 Divider after role const Divider(), // 👈 Divider after role
], ],
), ),
@ -702,4 +725,4 @@ Widget buildNavItem(
), ),
), ),
); );
} }

View File

@ -102,6 +102,7 @@ class ApiService {
throw Exception('Failed to load country list'); throw Exception('Failed to load country list');
} }
} }
Future<List<dynamic>> fetchAirlineList() async { Future<List<dynamic>> fetchAirlineList() async {
final String apiUrldata = '$apiUrl/api/getAirlineMaster'; final String apiUrldata = '$apiUrl/api/getAirlineMaster';
final token = await getToken(); final token = await getToken();
@ -617,6 +618,7 @@ class ApiService {
BuildContext context, BuildContext context,
String planId, String planId,
String? approverId, String? approverId,
String? approver_status,
String? delegaterId, { String? delegaterId, {
bool isViewMode = false, bool isViewMode = false,
bool isApprover = true, bool isApprover = true,
@ -629,6 +631,7 @@ class ApiService {
'/approver/plans', '/approver/plans',
extra: { extra: {
'planData': planData, 'planData': planData,
'approver_status': approver_status,
'approverId': approverId, 'approverId': approverId,
'delegaterId': delegaterId, 'delegaterId': delegaterId,
'isViewMode': isViewMode, 'isViewMode': isViewMode,