PMJBY/SBY enquiry created
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/data/models/user.dart';
|
||||
import 'package:kmobile/l10n/app_localizations.dart';
|
||||
|
||||
class APYScreen extends StatefulWidget {
|
||||
final List<User> users;
|
||||
final int selectedIndex;
|
||||
const APYScreen({
|
||||
super.key,
|
||||
required this.users,
|
||||
required this.selectedIndex,
|
||||
});
|
||||
|
||||
@override
|
||||
State<APYScreen> createState() => _APYScreenState();
|
||||
}
|
||||
|
||||
class _APYScreenState extends State<APYScreen> {
|
||||
User? _selectedAccount;
|
||||
List<User> _filteredUsers = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_filteredUsers = widget.users
|
||||
.where((user) => ['SA', 'SB', 'CA', 'CC'].contains(user.accountType))
|
||||
.toList();
|
||||
|
||||
// Pre-fill the account number if possible
|
||||
if (widget.users.isNotEmpty && widget.selectedIndex < widget.users.length) {
|
||||
if (_filteredUsers.isNotEmpty) {
|
||||
if (_filteredUsers.contains(widget.users[widget.selectedIndex])) {
|
||||
_selectedAccount = widget.users[widget.selectedIndex];
|
||||
} else {
|
||||
_selectedAccount = _filteredUsers.first;
|
||||
}
|
||||
} else {
|
||||
_selectedAccount = widget.users[widget.selectedIndex];
|
||||
}
|
||||
} else {
|
||||
if (_filteredUsers.isNotEmpty) {
|
||||
_selectedAccount = _filteredUsers.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('APY registration'),
|
||||
centerTitle: false,
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Card(
|
||||
elevation: 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
"Atal Pension Yojana (APY) is a periodic contribution-based pension scheme for citizens of India.",
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Card(
|
||||
elevation: 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
DropdownButtonFormField<User>(
|
||||
value: _selectedAccount,
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).accountNumber,
|
||||
border: const OutlineInputBorder(),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
vertical: 20, horizontal: 12),
|
||||
),
|
||||
items: _filteredUsers.map((user) {
|
||||
return DropdownMenuItem<User>(
|
||||
value: user,
|
||||
child: Text(user.accountNo.toString()),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (User? newUser) {
|
||||
setState(() {
|
||||
_selectedAccount = newUser;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null) {
|
||||
return AppLocalizations.of(context)
|
||||
.accountNumberRequired;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/data/models/user.dart';
|
||||
import 'package:kmobile/features/yojna/screens/apy_screen.dart';
|
||||
import 'package:kmobile/features/yojna/screens/pm_main_screen.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
|
||||
@@ -51,10 +52,18 @@ class _GovSchemeScreenState extends State<GovSchemeScreen> {
|
||||
Expanded(
|
||||
child: GovSchemeTile(
|
||||
logoText: "APY",
|
||||
label: "Atal Pension Yojana",
|
||||
subtitle: "Secure your future with Atal Pension Yojana (APY) retirement scheme",
|
||||
label: "Register for Atal Pension Yojana",
|
||||
subtitle: "Secure your future with Atal Pension Yojana (APY) retirement scheme. Register in a few steps.",
|
||||
onTap: () {
|
||||
// Action for APY will be added later
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => APYScreen(
|
||||
users: widget.users,
|
||||
selectedIndex: widget.selectedIndex,
|
||||
),
|
||||
),
|
||||
);// Action for APY will be added later
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
@@ -4,6 +4,8 @@ import 'package:kmobile/data/models/user.dart';
|
||||
import 'package:kmobile/di/injection.dart';
|
||||
import 'package:kmobile/features/yojna/screens/pmjjby_screen.dart';
|
||||
import 'package:kmobile/features/yojna/screens/pmsby_screen.dart';
|
||||
import 'package:kmobile/features/yojna/screens/pmjjby_enquiry_screen.dart';
|
||||
import 'package:kmobile/features/yojna/screens/pmsby_enquiry_screen.dart';
|
||||
import 'package:kmobile/l10n/app_localizations.dart';
|
||||
|
||||
class PMMainScreen extends StatefulWidget {
|
||||
@@ -132,6 +134,35 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
void _handleEnquiry() {
|
||||
if (_selectedAccount == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Please select account number')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_selectedScheme == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Please select a scheme first')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
if (_selectedScheme!.contains('PMJJBY')) {
|
||||
return PMJJBYEnquiryScreen(cifNumber: _selectedAccount!.cifNumber);
|
||||
} else {
|
||||
return PMSBYEnquiryScreen(cifNumber: _selectedAccount!.cifNumber);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -265,9 +296,7 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
// Action for Enquiry button
|
||||
},
|
||||
onPressed: _handleEnquiry,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor:
|
||||
Theme.of(context).colorScheme.primaryContainer,
|
||||
@@ -293,3 +322,4 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
215
lib/features/yojna/screens/pmjjby_enquiry_screen.dart
Normal file
215
lib/features/yojna/screens/pmjjby_enquiry_screen.dart
Normal file
@@ -0,0 +1,215 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/api/services/yojna_service.dart';
|
||||
import 'package:kmobile/di/injection.dart';
|
||||
|
||||
class PMJJBYEnquiryScreen extends StatefulWidget {
|
||||
final String? cifNumber;
|
||||
|
||||
const PMJJBYEnquiryScreen({
|
||||
super.key,
|
||||
required this.cifNumber,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PMJJBYEnquiryScreen> createState() => _PMJJBYEnquiryScreenState();
|
||||
}
|
||||
|
||||
class _PMJJBYEnquiryScreenState extends State<PMJJBYEnquiryScreen> {
|
||||
String? _selectedFinancialYear;
|
||||
bool _isLoading = false;
|
||||
Map<String, dynamic>? _enquiryData;
|
||||
String? _errorMessage;
|
||||
|
||||
final List<String> _financialYears = [
|
||||
'2021-2022',
|
||||
'2022-2023',
|
||||
'2023-2024',
|
||||
'2024-2025',
|
||||
'2025-2026',
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedFinancialYear = null;
|
||||
}
|
||||
|
||||
Future<void> _fetchEnquiryData() async {
|
||||
if (_selectedFinancialYear == null || widget.cifNumber == null) return;
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_enquiryData = null;
|
||||
_errorMessage = null;
|
||||
});
|
||||
|
||||
final formattedYear = _selectedFinancialYear!.replaceAll('-', '');
|
||||
|
||||
try {
|
||||
final response = await getIt<YojnaService>().enquiry(
|
||||
scheme: '02',
|
||||
action: 'E',
|
||||
financialyear: formattedYear,
|
||||
customerno: widget.cifNumber,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
if (response is Map<String, dynamic>) {
|
||||
if (response['status'] == 'FAILED') {
|
||||
_errorMessage = response['message'] ?? 'No record found';
|
||||
} else {
|
||||
_enquiryData = response;
|
||||
}
|
||||
} else if (response is List && response.isNotEmpty) {
|
||||
_enquiryData = response[0] as Map<String, dynamic>;
|
||||
} else {
|
||||
_errorMessage = 'No data found for the selected year.';
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_errorMessage = 'Error: ${e.toString()}';
|
||||
});
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('PMJJBY details'),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Card(
|
||||
elevation: 4,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: const Icon(Icons.person, color: Colors.blue),
|
||||
title: const Text('CIF Number'),
|
||||
subtitle: Text(
|
||||
widget.cifNumber ?? 'N/A',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<String>(
|
||||
value: _selectedFinancialYear,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Select Financial Year',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.calendar_today),
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
),
|
||||
items: _financialYears.map((String year) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: year,
|
||||
child: Text(year),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? newValue) {
|
||||
setState(() {
|
||||
_selectedFinancialYear = newValue;
|
||||
});
|
||||
_fetchEnquiryData();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
if (_isLoading)
|
||||
const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(20.0),
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
)
|
||||
else if (_errorMessage != null)
|
||||
Card(
|
||||
color: Colors.red.shade50,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
_errorMessage!,
|
||||
style: TextStyle(color: Colors.red.shade700, fontWeight: FontWeight.bold),
|
||||
//textAlign: Center,
|
||||
),
|
||||
),
|
||||
)
|
||||
else if (_enquiryData != null)
|
||||
Card(
|
||||
elevation: 4,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Scheme Details',
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
_buildDetailRow('Customer Name', _enquiryData!['customername']),
|
||||
_buildDetailRow('Policy Number', _enquiryData!['policynumber']),
|
||||
_buildDetailRow('Account Number', _enquiryData!['accountno']),
|
||||
_buildDetailRow('Premium Amount', _enquiryData!['preimiumamount']),
|
||||
_buildDetailRow('Nominee Name', _enquiryData!['nomineename']),
|
||||
_buildDetailRow('Transaction Date', _enquiryData!['transactiondate']),
|
||||
_buildDetailRow('Journal No', _enquiryData!['journalno']),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailRow(String label, dynamic value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(fontWeight: FontWeight.w500, color: Colors.grey),
|
||||
),
|
||||
Flexible(
|
||||
child: Text(
|
||||
value?.toString() ?? 'N/A',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
textAlign: TextAlign.end,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,48 @@ class _PMJJBYScreenState extends State<PMJJBYScreen> {
|
||||
late final _policyNumberController = TextEditingController(text: widget.initialData?['policynumber']?.toString());
|
||||
late final _premiumAmountController = TextEditingController(text: widget.initialData?['premiumamount']?.toString());
|
||||
late final _stateController = TextEditingController(text: widget.initialData?['state']?.toString());
|
||||
|
||||
// Mapping options
|
||||
final Map<String, String> _healthStatusOptions = {
|
||||
'1': 'Excellent',
|
||||
'2': 'Good',
|
||||
'3': 'Bad',
|
||||
};
|
||||
|
||||
final Map<String, String> _relationshipOptions = {
|
||||
'01': 'Self',
|
||||
'02': 'Wife',
|
||||
'03': 'Father',
|
||||
'04': 'Mother',
|
||||
'05': 'Son',
|
||||
'06': 'Daughter',
|
||||
'07': 'Brother',
|
||||
'08': 'Sister',
|
||||
'09': 'Father-in-law',
|
||||
'10': 'Mother-in-law',
|
||||
'11': 'Grandson',
|
||||
'12': 'Granddaughter',
|
||||
'13': 'Grandfather',
|
||||
'14': 'Grandmother',
|
||||
'15': 'Brother-in-law',
|
||||
'16': 'Sister-in-law',
|
||||
'17': 'Husband',
|
||||
'18': 'Guardian',
|
||||
'99': 'Others',
|
||||
};
|
||||
|
||||
final Map<String, String> _minorOptions = {
|
||||
'Y': 'Yes',
|
||||
'N': 'No',
|
||||
};
|
||||
|
||||
final Map<String, String> _ruralOptions = {
|
||||
'R': 'Rural',
|
||||
'U': 'Urban',
|
||||
'S': 'Semi-Urban',
|
||||
'M': 'Metro',
|
||||
};
|
||||
|
||||
final _healthStatusController = TextEditingController();
|
||||
final _collectionChannelController = TextEditingController();
|
||||
final _nomineeNameController = TextEditingController();
|
||||
@@ -41,6 +83,26 @@ class _PMJJBYScreenState extends State<PMJJBYScreen> {
|
||||
final _nomineeMinorController = TextEditingController();
|
||||
final _ruralCategoryController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Initialize dropdown controllers if data exists in initialData
|
||||
if (widget.initialData != null) {
|
||||
if (widget.initialData!.containsKey('ruralcategory')) {
|
||||
_ruralCategoryController.text = widget.initialData!['ruralcategory'].toString();
|
||||
}
|
||||
if (widget.initialData!.containsKey('healthstatus')) {
|
||||
_healthStatusController.text = widget.initialData!['healthstatus'].toString();
|
||||
}
|
||||
if (widget.initialData!.containsKey('nomineerelationship')) {
|
||||
_nomineeRelationshipController.text = widget.initialData!['nomineerelationship'].toString();
|
||||
}
|
||||
if (widget.initialData!.containsKey('nomineeminor')) {
|
||||
_nomineeMinorController.text = widget.initialData!['nomineeminor'].toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_aadhaarController.dispose();
|
||||
@@ -180,22 +242,22 @@ class _PMJJBYScreenState extends State<PMJJBYScreen> {
|
||||
_buildTextField(_pincodeController, 'Pincode', keyboardType: TextInputType.number, readOnly: _isFetched('pincode')),
|
||||
_buildTextField(_stateController, 'State', readOnly: _isFetched('state')),
|
||||
_buildTextField(_countryController, 'Country', readOnly: _isFetched('country')),
|
||||
_buildTextField(_ruralCategoryController, 'Rural Category'),
|
||||
_buildDropdownField(_ruralCategoryController, 'Rural Category', _ruralOptions, readOnly: _isFetched('ruralcategory')),
|
||||
const Divider(height: 32),
|
||||
const Text('Policy Details', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 16),
|
||||
_buildTextField(_policyNumberController, 'Policy Number', readOnly: _isFetched('policynumber')),
|
||||
_buildTextField(_premiumAmountController, 'Premium Amount', keyboardType: TextInputType.number, readOnly: _isFetched('premiumamount')),
|
||||
_buildTextField(_financialYearController, 'Financial Year', readOnly: _isFetched('financialyear')),
|
||||
_buildTextField(_healthStatusController, 'Health Status'),
|
||||
_buildDropdownField(_healthStatusController, 'Health Status', _healthStatusOptions),
|
||||
_buildTextField(_collectionChannelController, 'Collection Channel'),
|
||||
const Divider(height: 32),
|
||||
const Text('Nominee Details', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 16),
|
||||
_buildTextField(_nomineeNameController, 'Nominee Name'),
|
||||
_buildTextField(_nomineeAddressController, 'Nominee Address'),
|
||||
_buildTextField(_nomineeRelationshipController, 'Nominee Relationship'),
|
||||
_buildTextField(_nomineeMinorController, 'Nominee Minor (Yes/No)'),
|
||||
_buildDropdownField(_nomineeRelationshipController, 'Nominee Relationship', _relationshipOptions, readOnly: _isFetched('nomineerelationship')),
|
||||
_buildDropdownField(_nomineeMinorController, 'Nominee Minor', _minorOptions, readOnly: _isFetched('nomineeminor')),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton(
|
||||
onPressed: _handleRegister,
|
||||
@@ -220,6 +282,36 @@ class _PMJJBYScreenState extends State<PMJJBYScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDropdownField(
|
||||
TextEditingController controller, String label, Map<String, String> options,
|
||||
{bool readOnly = false}) {
|
||||
// Determine current value
|
||||
String? currentValue = options.containsKey(controller.text) ? controller.text : null;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16.0),
|
||||
child: DropdownButtonFormField<String>(
|
||||
value: currentValue,
|
||||
onChanged: readOnly ? null : (newValue) {
|
||||
setState(() {
|
||||
controller.text = newValue ?? '';
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
border: const OutlineInputBorder(),
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
|
||||
),
|
||||
items: options.entries.map((entry) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: entry.key,
|
||||
child: Text("${entry.key} - ${entry.value}"),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTextField(TextEditingController controller, String label, {TextInputType keyboardType = TextInputType.text, bool readOnly = false}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16.0),
|
||||
|
||||
215
lib/features/yojna/screens/pmsby_enquiry_screen.dart
Normal file
215
lib/features/yojna/screens/pmsby_enquiry_screen.dart
Normal file
@@ -0,0 +1,215 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/api/services/yojna_service.dart';
|
||||
import 'package:kmobile/di/injection.dart';
|
||||
|
||||
class PMSBYEnquiryScreen extends StatefulWidget {
|
||||
final String? cifNumber;
|
||||
|
||||
const PMSBYEnquiryScreen({
|
||||
super.key,
|
||||
required this.cifNumber,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PMSBYEnquiryScreen> createState() => _PMSBYEnquiryScreenState();
|
||||
}
|
||||
|
||||
class _PMSBYEnquiryScreenState extends State<PMSBYEnquiryScreen> {
|
||||
String? _selectedFinancialYear;
|
||||
bool _isLoading = false;
|
||||
Map<String, dynamic>? _enquiryData;
|
||||
String? _errorMessage;
|
||||
|
||||
final List<String> _financialYears = [
|
||||
'2021-2022',
|
||||
'2022-2023',
|
||||
'2023-2024',
|
||||
'2024-2025',
|
||||
'2025-2026',
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedFinancialYear = null;
|
||||
}
|
||||
|
||||
Future<void> _fetchEnquiryData() async {
|
||||
if (_selectedFinancialYear == null || widget.cifNumber == null) return;
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_enquiryData = null;
|
||||
_errorMessage = null;
|
||||
});
|
||||
|
||||
final formattedYear = _selectedFinancialYear!.replaceAll('-', '');
|
||||
|
||||
try {
|
||||
final response = await getIt<YojnaService>().enquiry(
|
||||
scheme: '01',
|
||||
action: 'E',
|
||||
financialyear: formattedYear,
|
||||
customerno: widget.cifNumber,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
if (response is Map<String, dynamic>) {
|
||||
if (response['status'] == 'FAILED') {
|
||||
_errorMessage = response['message'] ?? 'No record found';
|
||||
} else {
|
||||
_enquiryData = response;
|
||||
}
|
||||
} else if (response is List && response.isNotEmpty) {
|
||||
_enquiryData = response[0] as Map<String, dynamic>;
|
||||
} else {
|
||||
_errorMessage = 'No data found for the selected year.';
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_errorMessage = 'Error: ${e.toString()}';
|
||||
});
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('PMSBY details'),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Card(
|
||||
elevation: 4,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: const Icon(Icons.person, color: Colors.blue),
|
||||
title: const Text('CIF Number'),
|
||||
subtitle: Text(
|
||||
widget.cifNumber ?? 'N/A',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<String>(
|
||||
value: _selectedFinancialYear,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Select Financial Year',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.calendar_today),
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
),
|
||||
items: _financialYears.map((String year) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: year,
|
||||
child: Text(year),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? newValue) {
|
||||
setState(() {
|
||||
_selectedFinancialYear = newValue;
|
||||
});
|
||||
_fetchEnquiryData();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
if (_isLoading)
|
||||
const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(20.0),
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
)
|
||||
else if (_errorMessage != null)
|
||||
Card(
|
||||
color: Colors.red.shade50,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
_errorMessage!,
|
||||
style: TextStyle(color: Colors.red.shade700, fontWeight: FontWeight.bold),
|
||||
//textAlign: Center,
|
||||
),
|
||||
),
|
||||
)
|
||||
else if (_enquiryData != null)
|
||||
Card(
|
||||
elevation: 4,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Scheme Details',
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
_buildDetailRow('Customer Name', _enquiryData!['customername']),
|
||||
_buildDetailRow('Policy Number', _enquiryData!['policynumber'] ?? _enquiryData!['policyno']),
|
||||
_buildDetailRow('Account Number', _enquiryData!['accountno']),
|
||||
_buildDetailRow('Premium Amount', _enquiryData!['preimiumamount'] ?? _enquiryData!['premiumamount']),
|
||||
_buildDetailRow('Nominee Name', _enquiryData!['nomineename']),
|
||||
_buildDetailRow('Transaction Date', _enquiryData!['transactiondate']),
|
||||
_buildDetailRow('Journal No', _enquiryData!['journalno']),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailRow(String label, dynamic value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(fontWeight: FontWeight.w500, color: Colors.grey),
|
||||
),
|
||||
Flexible(
|
||||
child: Text(
|
||||
value?.toString() ?? 'N/A',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
textAlign: TextAlign.end,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,47 @@ class _PMSBYScreenState extends State<PMSBYScreen> {
|
||||
late final _relationWithNomineeController = TextEditingController(text: widget.initialData?['relationwithnominee']?.toString());
|
||||
late final _policyStatusController = TextEditingController(text: widget.initialData?['policystatus']?.toString());
|
||||
|
||||
// Mapping options
|
||||
final Map<String, String> _healthStatusOptions = {
|
||||
'1': 'Excellent',
|
||||
'2': 'Good',
|
||||
'3': 'Bad',
|
||||
};
|
||||
|
||||
final Map<String, String> _relationshipOptions = {
|
||||
'01': 'Self',
|
||||
'02': 'Wife',
|
||||
'03': 'Father',
|
||||
'04': 'Mother',
|
||||
'05': 'Son',
|
||||
'06': 'Daughter',
|
||||
'07': 'Brother',
|
||||
'08': 'Sister',
|
||||
'09': 'Father-in-law',
|
||||
'10': 'Mother-in-law',
|
||||
'11': 'Grandson',
|
||||
'12': 'Granddaughter',
|
||||
'13': 'Grandfather',
|
||||
'14': 'Grandmother',
|
||||
'15': 'Brother-in-law',
|
||||
'16': 'Sister-in-law',
|
||||
'17': 'Husband',
|
||||
'18': 'Guardian',
|
||||
'99': 'Others',
|
||||
};
|
||||
|
||||
final Map<String, String> _minorOptions = {
|
||||
'Y': 'Yes',
|
||||
'N': 'No',
|
||||
};
|
||||
|
||||
final Map<String, String> _ruralOptions = {
|
||||
'R': 'Rural',
|
||||
'U': 'Urban',
|
||||
'S': 'Semi-Urban',
|
||||
'M': 'Metro',
|
||||
};
|
||||
|
||||
final _healthStatusController = TextEditingController();
|
||||
final _collectionChannelController = TextEditingController();
|
||||
final _nomineeNameController = TextEditingController();
|
||||
@@ -47,6 +88,26 @@ class _PMSBYScreenState extends State<PMSBYScreen> {
|
||||
final _nomineeMinorController = TextEditingController();
|
||||
final _ruralCategoryController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Initialize dropdown controllers if data exists in initialData
|
||||
if (widget.initialData != null) {
|
||||
if (widget.initialData!.containsKey('ruralcategory')) {
|
||||
_ruralCategoryController.text = widget.initialData!['ruralcategory'].toString();
|
||||
}
|
||||
if (widget.initialData!.containsKey('healthstatus')) {
|
||||
_healthStatusController.text = widget.initialData!['healthstatus'].toString();
|
||||
}
|
||||
if (widget.initialData!.containsKey('relationwithnominee')) {
|
||||
_nomineeRelationshipController.text = widget.initialData!['relationwithnominee'].toString();
|
||||
}
|
||||
if (widget.initialData!.containsKey('nomineeminor')) {
|
||||
_nomineeMinorController.text = widget.initialData!['nomineeminor'].toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_aadhaarController.dispose();
|
||||
@@ -196,7 +257,7 @@ class _PMSBYScreenState extends State<PMSBYScreen> {
|
||||
_buildTextField(_pincodeController, 'Pincode', keyboardType: TextInputType.number, readOnly: _isFetched('pincode')),
|
||||
_buildTextField(_stateController, 'State', readOnly: _isFetched('state')),
|
||||
_buildTextField(_countryController, 'Country', readOnly: _isFetched('country')),
|
||||
_buildTextField(_ruralCategoryController, 'Rural Category'),
|
||||
_buildDropdownField(_ruralCategoryController, 'Rural Category', _ruralOptions, readOnly: _isFetched('ruralcategory')),
|
||||
const Divider(height: 32),
|
||||
const Text('Policy Details', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 16),
|
||||
@@ -204,16 +265,16 @@ class _PMSBYScreenState extends State<PMSBYScreen> {
|
||||
_buildTextField(_premiumAmountController, 'Premium Amount', keyboardType: TextInputType.number, readOnly: _isFetched('premiumamount')),
|
||||
_buildTextField(_financialYearController, 'Financial Year', readOnly: _isFetched('financialyear')),
|
||||
_buildTextField(_policyStatusController, 'Policy Status', readOnly: _isFetched('policystatus')),
|
||||
_buildTextField(_healthStatusController, 'Health Status'),
|
||||
_buildDropdownField(_healthStatusController, 'Health Status', _healthStatusOptions),
|
||||
_buildTextField(_collectionChannelController, 'Collection Channel'),
|
||||
const Divider(height: 32),
|
||||
const Text('Nominee Details', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 16),
|
||||
_buildTextField(_nomineeNameController, 'Nominee Name'),
|
||||
_buildTextField(_nomineeAddressController, 'Nominee Address'),
|
||||
_buildTextField(_relationWithNomineeController, 'Relation with Nominee', readOnly: _isFetched('relationwithnominee')),
|
||||
_buildDropdownField(_relationWithNomineeController, 'Relation with Nominee', _relationshipOptions, readOnly: _isFetched('relationwithnominee')),
|
||||
_buildTextField(_nomineeRelationshipController, 'Nominee Relationship'),
|
||||
_buildTextField(_nomineeMinorController, 'Nominee Minor (Yes/No)'),
|
||||
_buildDropdownField(_nomineeMinorController, 'Nominee Minor', _minorOptions, readOnly: _isFetched('nomineeminor')),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton(
|
||||
onPressed: _handleRegister,
|
||||
@@ -238,6 +299,36 @@ class _PMSBYScreenState extends State<PMSBYScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDropdownField(
|
||||
TextEditingController controller, String label, Map<String, String> options,
|
||||
{bool readOnly = false}) {
|
||||
// Determine current value
|
||||
String? currentValue = options.containsKey(controller.text) ? controller.text : null;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16.0),
|
||||
child: DropdownButtonFormField<String>(
|
||||
value: currentValue,
|
||||
onChanged: readOnly ? null : (newValue) {
|
||||
setState(() {
|
||||
controller.text = newValue ?? '';
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
border: const OutlineInputBorder(),
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
|
||||
),
|
||||
items: options.entries.map((entry) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: entry.key,
|
||||
child: Text("${entry.key} - ${entry.value}"),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTextField(TextEditingController controller, String label, {TextInputType keyboardType = TextInputType.text, bool readOnly = false}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16.0),
|
||||
|
||||
Reference in New Issue
Block a user