From 537a4faa62adb55bfa3fdb9c48635a4161383835 Mon Sep 17 00:00:00 2001 From: asif Date: Tue, 30 Dec 2025 12:45:45 +0530 Subject: [PATCH] Stop Cheque @ 2 --- lib/api/services/cheque_service.dart | 33 ++++++++++++- .../screens/stop_single_cheque_screen.dart | 49 +++++++------------ 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/lib/api/services/cheque_service.dart b/lib/api/services/cheque_service.dart index 4f991c7..4ca0626 100644 --- a/lib/api/services/cheque_service.dart +++ b/lib/api/services/cheque_service.dart @@ -65,7 +65,7 @@ class ChequeService { }) async { try { final response = await _dio.get( - "/api/cheque", + "/api/cheque/enquiry", queryParameters: { 'accountNumber': accountNumber, 'instrumentType': instrType, @@ -93,4 +93,35 @@ class ChequeService { throw e; } } + + Future stopCheque({ + required String accountno, + required String stopFromChequeNo, + required String instrType, + String? stopToChequeNo, + String? stopIssueDate, + String? stopExpiryDate, + String? stopAmount, + String? stopComment, + String? chequeIssueDate, + }) async { + final response = await _dio.post( + '/api/cheque/stop', + data: { + 'accountNumber': accountno, + 'stopFromChequeNo': stopFromChequeNo, + 'instrumentType': instrType, + 'stopToChequeNo': stopToChequeNo, + 'stopIssueDate': stopIssueDate, + 'stopExpiryDate': stopExpiryDate, + 'stopAmount': stopAmount, + 'stopComment': stopComment, + 'chqIssueDate': chequeIssueDate, + }, + ); + if (response.statusCode != 200) { + throw Exception("Error"); + } + return response.toString(); + } } diff --git a/lib/features/cheque/screens/stop_single_cheque_screen.dart b/lib/features/cheque/screens/stop_single_cheque_screen.dart index c94658a..e8dff79 100644 --- a/lib/features/cheque/screens/stop_single_cheque_screen.dart +++ b/lib/features/cheque/screens/stop_single_cheque_screen.dart @@ -28,32 +28,18 @@ class _StopSingleChequeScreenState extends State { final _stopAmountController = TextEditingController(); final _stopCommentController = TextEditingController(); - bool _validateChequeNumber() { - final value = _stopFromChequeNoController.text; - if (value.isEmpty) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Please enter a cheque number')), - ); - return false; + String _formatDate(String dateString) { + if (dateString.length != 8) { + return dateString; // Return as is if not in expected ddmmyyyy format } - final chequeNumber = int.tryParse(value); - final fromCheque = int.tryParse(widget.fromCheque); - final toCheque = int.tryParse(widget.toCheque); - if (chequeNumber == null || fromCheque == null || toCheque == null) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Invalid cheque number format')), - ); - return false; + 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 } - if (chequeNumber < fromCheque || chequeNumber > toCheque) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - 'Cheque number must be between ${widget.fromCheque} and ${widget.toCheque}')), - ); - return false; - } - return true; } @override @@ -85,14 +71,13 @@ class _StopSingleChequeScreenState extends State { TextFormField( controller: _stopFromChequeNoController, decoration: const InputDecoration( - labelText: 'Cheque Number', + labelText: 'Cheque Number *', border: OutlineInputBorder(), ), keyboardType: TextInputType.number, validator: (value) { - // This validator will only return null or empty string to allow SnackBar to display if (value == null || value.isEmpty) { - return ''; // Return empty string to trigger error state without message + return 'Please enter a cheque number'; } final chequeNumber = int.tryParse(value); final fromCheque = int.tryParse(widget.fromCheque); @@ -100,10 +85,10 @@ class _StopSingleChequeScreenState extends State { if (chequeNumber == null || fromCheque == null || toCheque == null) { - return ''; + return 'Invalid cheque number format'; } if (chequeNumber < fromCheque || chequeNumber > toCheque) { - return ''; + return 'Cheque number must be between ${widget.fromCheque} and ${widget.toCheque}'; } return null; }, @@ -113,7 +98,7 @@ class _StopSingleChequeScreenState extends State { initialValue: widget.instrType, readOnly: true, decoration: const InputDecoration( - labelText: 'Instrument Type', + labelText: 'Instrument Type *', border: OutlineInputBorder(), ), ), @@ -154,7 +139,7 @@ class _StopSingleChequeScreenState extends State { ), const SizedBox(height: 16), TextFormField( - initialValue: widget.date, + initialValue: _formatDate(widget.date), readOnly: true, decoration: const InputDecoration( labelText: 'Chequebook Issue Date', @@ -164,7 +149,7 @@ class _StopSingleChequeScreenState extends State { const SizedBox(height: 32), ElevatedButton( onPressed: () { - if (_formKey.currentState!.validate() && _validateChequeNumber()) { + if (_formKey.currentState!.validate()) { // TODO: Implement stop single cheque logic } },