From 9d8c8dc8bd2a002584aa77689ad3550b5285d16f Mon Sep 17 00:00:00 2001 From: asif Date: Tue, 30 Dec 2025 13:12:40 +0530 Subject: [PATCH] Cheque Functionality Stop Cheque done --- .../cheque/screens/stop_cheque_screen.dart | 4 + .../screens/stop_multiple_cheques_screen.dart | 207 ++++++++++++++++-- .../screens/stop_single_cheque_screen.dart | 59 ++++- 3 files changed, 252 insertions(+), 18 deletions(-) diff --git a/lib/features/cheque/screens/stop_cheque_screen.dart b/lib/features/cheque/screens/stop_cheque_screen.dart index 4632924..9520577 100644 --- a/lib/features/cheque/screens/stop_cheque_screen.dart +++ b/lib/features/cheque/screens/stop_cheque_screen.dart @@ -235,6 +235,10 @@ class _StopChequeScreenState extends State { builder: (context) => StopMultipleChequesScreen( selectedAccount: _selectedAccount!, + date: _ciCheque!.Date!, + instrType: _ciCheque!.InstrType!, + fromCheque: _ciCheque!.fromCheque!, + toCheque: _ciCheque!.toCheque!, ), ), ); diff --git a/lib/features/cheque/screens/stop_multiple_cheques_screen.dart b/lib/features/cheque/screens/stop_multiple_cheques_screen.dart index f45c5d9..ffc76f1 100644 --- a/lib/features/cheque/screens/stop_multiple_cheques_screen.dart +++ b/lib/features/cheque/screens/stop_multiple_cheques_screen.dart @@ -1,10 +1,25 @@ +import 'dart:convert'; + import 'package:flutter/material.dart'; +import 'package:kmobile/api/services/cheque_service.dart'; import 'package:kmobile/data/models/user.dart'; +import 'package:kmobile/di/injection.dart'; class StopMultipleChequesScreen extends StatefulWidget { final User selectedAccount; + final String date; + final String instrType; + final String fromCheque; + final String toCheque; - const StopMultipleChequesScreen({super.key, required this.selectedAccount}); + + const StopMultipleChequesScreen( + {super.key, + required this.selectedAccount, + required this.date, + required this.instrType, + required this.fromCheque, + required this.toCheque}); @override State createState() => @@ -13,56 +28,216 @@ class StopMultipleChequesScreen extends StatefulWidget { class _StopMultipleChequesScreenState extends State { final _formKey = GlobalKey(); - final _fromChequeController = TextEditingController(); - final _toChequeController = TextEditingController(); + final _stopFromChequeNoController = TextEditingController(); + final _stopToChequeNoController = TextEditingController(); + final _stopIssueDateController = TextEditingController(); + final _stopExpiryDateController = TextEditingController(); + final _stopAmountController = TextEditingController(); + final _stopCommentController = TextEditingController(); + final _chequeService = getIt(); + + String _formatDate(String dateString) { + if (dateString.length != 8) { + return dateString; // Return as is if not in expected ddmmyyyy format + } + try { + final day = dateString.substring(0, 2); + final month = dateString.substring(2, 4); + final year = dateString.substring(4, 8); + return '$day/$month/$year'; + } catch (e) { + return dateString; // Return original string on error + } + } + + Future _showResponseDialog(String title, String message) async { + return showDialog( + context: context, + barrierDismissible: false, // user must tap button! + builder: (BuildContext context) { + return AlertDialog( + title: Text(title), + content: SingleChildScrollView( + child: ListBody( + children: [ + Text(message), + ], + ), + ), + actions: [ + TextButton( + child: const Text('Close'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: const Text('Stop Multiple Cheques'), + title: const Text('Stop Single Cheque'), ), body: Padding( padding: const EdgeInsets.all(16.0), child: Form( key: _formKey, - child: Column( + child: ListView( children: [ + Card( + elevation: 0, + margin: const EdgeInsets.symmetric(vertical: 8.0), + child: ListTile( + leading: Image.asset( + 'assets/images/logo.png', + width: 40, + height: 40, + ), + title: Text(widget.selectedAccount.accountNo!), + subtitle: const Text("Account Number"), + ), + ), + const SizedBox(height: 24), TextFormField( - controller: _fromChequeController, + controller: _stopFromChequeNoController, decoration: const InputDecoration( - labelText: 'From Cheque Number', + labelText: 'From Cheque Number *', + border: OutlineInputBorder(), ), keyboardType: TextInputType.number, validator: (value) { if (value == null || value.isEmpty) { - return 'Please enter the starting cheque number'; + return 'Please enter a cheque number'; + } + final chequeNumber = int.tryParse(value); + final fromCheque = int.tryParse(widget.fromCheque); + final toCheque = int.tryParse(widget.toCheque); + if (chequeNumber == null || + fromCheque == null || + toCheque == null) { + return 'Invalid cheque number format'; + } + if (chequeNumber < fromCheque || chequeNumber > toCheque) { + return 'Cheque number must be between ${widget.fromCheque} and ${widget.toCheque}'; } return null; }, ), - const SizedBox(height: 20), + const SizedBox(height: 16), TextFormField( - controller: _toChequeController, + controller: _stopToChequeNoController, decoration: const InputDecoration( - labelText: 'To Cheque Number', + labelText: 'To Cheque Number *', + border: OutlineInputBorder(), ), keyboardType: TextInputType.number, validator: (value) { if (value == null || value.isEmpty) { - return 'Please enter the ending cheque number'; + return 'Please enter a cheque number'; + } + final chequeNumber = int.tryParse(value); + final fromCheque = int.tryParse(widget.fromCheque); + final toCheque = int.tryParse(widget.toCheque); + if (chequeNumber == null || + fromCheque == null || + toCheque == null) { + return 'Invalid cheque number format'; + } + if (chequeNumber < fromCheque || chequeNumber > toCheque) { + return 'Cheque number must be between ${widget.fromCheque} and ${widget.toCheque}'; } return null; }, ), - const SizedBox(height: 20), + const SizedBox(height: 16), + TextFormField( + initialValue: widget.instrType, + readOnly: true, + decoration: const InputDecoration( + labelText: 'Instrument Type *', + border: OutlineInputBorder(), + ), + ), + const SizedBox(height: 16), + TextFormField( + controller: _stopIssueDateController, + decoration: const InputDecoration( + labelText: 'Stop Issue Date', + border: OutlineInputBorder(), + ), + keyboardType: TextInputType.datetime, + ), + const SizedBox(height: 16), + TextFormField( + controller: _stopExpiryDateController, + decoration: const InputDecoration( + labelText: 'Stop Expiry Date', + border: OutlineInputBorder(), + ), + keyboardType: TextInputType.datetime, + ), + const SizedBox(height: 16), + TextFormField( + controller: _stopAmountController, + decoration: const InputDecoration( + labelText: 'Stop Amount', + border: OutlineInputBorder(), + ), + keyboardType: TextInputType.number, + ), + const SizedBox(height: 16), + TextFormField( + controller: _stopCommentController, + decoration: const InputDecoration( + labelText: 'Stop Comment', + border: OutlineInputBorder(), + ), + ), + const SizedBox(height: 16), + TextFormField( + initialValue: _formatDate(widget.date), + readOnly: true, + decoration: const InputDecoration( + labelText: 'Chequebook Issue Date', + border: OutlineInputBorder(), + ), + ), + const SizedBox(height: 32), ElevatedButton( - onPressed: () { + onPressed: () async { if (_formKey.currentState!.validate()) { - // TODO: Implement stop multiple cheques logic + try { + final response = await _chequeService.stopCheque( + accountno: widget.selectedAccount.accountNo!, + stopFromChequeNo: _stopFromChequeNoController.text, + instrType: widget.instrType, + stopToChequeNo: _stopToChequeNoController.text, + stopIssueDate: _stopIssueDateController.text, + stopExpiryDate: _stopExpiryDateController.text, + stopAmount: _stopAmountController.text, + stopComment: _stopCommentController.text, + chequeIssueDate: widget.date, + ); + if (!mounted) return; + final decodedResponse = jsonDecode(response); + final status = decodedResponse['status']; + final message = decodedResponse['message']; + if (status == 'SUCCESS') { + _showResponseDialog('Success', message); + } else { + _showResponseDialog('Error', message); + } + } catch (e) { + _showResponseDialog('Error', e.toString()); + } } }, - child: const Text('Submit'), + child: const Text('Stop Cheque'), ), ], ), diff --git a/lib/features/cheque/screens/stop_single_cheque_screen.dart b/lib/features/cheque/screens/stop_single_cheque_screen.dart index e8dff79..c0c08df 100644 --- a/lib/features/cheque/screens/stop_single_cheque_screen.dart +++ b/lib/features/cheque/screens/stop_single_cheque_screen.dart @@ -1,5 +1,9 @@ +import 'dart:convert'; + import 'package:flutter/material.dart'; +import 'package:kmobile/api/services/cheque_service.dart'; import 'package:kmobile/data/models/user.dart'; +import 'package:kmobile/di/injection.dart'; class StopSingleChequeScreen extends StatefulWidget { final User selectedAccount; @@ -27,6 +31,7 @@ class _StopSingleChequeScreenState extends State { final _stopExpiryDateController = TextEditingController(); final _stopAmountController = TextEditingController(); final _stopCommentController = TextEditingController(); + final _chequeService = getIt(); String _formatDate(String dateString) { if (dateString.length != 8) { @@ -42,6 +47,33 @@ class _StopSingleChequeScreenState extends State { } } + Future _showResponseDialog(String title, String message) async { + return showDialog( + context: context, + barrierDismissible: false, // user must tap button! + builder: (BuildContext context) { + return AlertDialog( + title: Text(title), + content: SingleChildScrollView( + child: ListBody( + children: [ + Text(message), + ], + ), + ), + actions: [ + TextButton( + child: const Text('Close'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -148,9 +180,32 @@ class _StopSingleChequeScreenState extends State { ), const SizedBox(height: 32), ElevatedButton( - onPressed: () { + onPressed: () async { if (_formKey.currentState!.validate()) { - // TODO: Implement stop single cheque logic + try { + final response = await _chequeService.stopCheque( + accountno: widget.selectedAccount.accountNo!, + stopFromChequeNo: _stopFromChequeNoController.text, + instrType: widget.instrType, + stopToChequeNo: _stopFromChequeNoController.text, + stopIssueDate: _stopIssueDateController.text, + stopExpiryDate: _stopExpiryDateController.text, + stopAmount: _stopAmountController.text, + stopComment: _stopCommentController.text, + chequeIssueDate: widget.date, + ); + if (!mounted) return; + final decodedResponse = jsonDecode(response); + final status = decodedResponse['status']; + final message = decodedResponse['message']; + if (status == 'SUCCESS') { + _showResponseDialog('Success', message); + } else { + _showResponseDialog('Error', message); + } + } catch (e) { + _showResponseDialog('Error', e.toString()); + } } }, child: const Text('Stop Cheque'),