Cheque Functionality Stop Cheque done
This commit is contained in:
@@ -235,6 +235,10 @@ class _StopChequeScreenState extends State<StopChequeScreen> {
|
|||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
StopMultipleChequesScreen(
|
StopMultipleChequesScreen(
|
||||||
selectedAccount: _selectedAccount!,
|
selectedAccount: _selectedAccount!,
|
||||||
|
date: _ciCheque!.Date!,
|
||||||
|
instrType: _ciCheque!.InstrType!,
|
||||||
|
fromCheque: _ciCheque!.fromCheque!,
|
||||||
|
toCheque: _ciCheque!.toCheque!,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,10 +1,25 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:kmobile/api/services/cheque_service.dart';
|
||||||
import 'package:kmobile/data/models/user.dart';
|
import 'package:kmobile/data/models/user.dart';
|
||||||
|
import 'package:kmobile/di/injection.dart';
|
||||||
|
|
||||||
class StopMultipleChequesScreen extends StatefulWidget {
|
class StopMultipleChequesScreen extends StatefulWidget {
|
||||||
final User selectedAccount;
|
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
|
@override
|
||||||
State<StopMultipleChequesScreen> createState() =>
|
State<StopMultipleChequesScreen> createState() =>
|
||||||
@@ -13,56 +28,216 @@ class StopMultipleChequesScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _StopMultipleChequesScreenState extends State<StopMultipleChequesScreen> {
|
class _StopMultipleChequesScreenState extends State<StopMultipleChequesScreen> {
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
final _fromChequeController = TextEditingController();
|
final _stopFromChequeNoController = TextEditingController();
|
||||||
final _toChequeController = TextEditingController();
|
final _stopToChequeNoController = TextEditingController();
|
||||||
|
final _stopIssueDateController = TextEditingController();
|
||||||
|
final _stopExpiryDateController = TextEditingController();
|
||||||
|
final _stopAmountController = TextEditingController();
|
||||||
|
final _stopCommentController = TextEditingController();
|
||||||
|
final _chequeService = getIt<ChequeService>();
|
||||||
|
|
||||||
|
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<void> _showResponseDialog(String title, String message) async {
|
||||||
|
return showDialog<void>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false, // user must tap button!
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(title),
|
||||||
|
content: SingleChildScrollView(
|
||||||
|
child: ListBody(
|
||||||
|
children: <Widget>[
|
||||||
|
Text(message),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: <Widget>[
|
||||||
|
TextButton(
|
||||||
|
child: const Text('Close'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Stop Multiple Cheques'),
|
title: const Text('Stop Single Cheque'),
|
||||||
),
|
),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: Form(
|
child: Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
child: Column(
|
child: ListView(
|
||||||
children: [
|
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(
|
TextFormField(
|
||||||
controller: _fromChequeController,
|
controller: _stopFromChequeNoController,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'From Cheque Number',
|
labelText: 'From Cheque Number *',
|
||||||
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value == null || value.isEmpty) {
|
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;
|
return null;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 16),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _toChequeController,
|
controller: _stopToChequeNoController,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'To Cheque Number',
|
labelText: 'To Cheque Number *',
|
||||||
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value == null || value.isEmpty) {
|
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;
|
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(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
if (_formKey.currentState!.validate()) {
|
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'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:kmobile/api/services/cheque_service.dart';
|
||||||
import 'package:kmobile/data/models/user.dart';
|
import 'package:kmobile/data/models/user.dart';
|
||||||
|
import 'package:kmobile/di/injection.dart';
|
||||||
|
|
||||||
class StopSingleChequeScreen extends StatefulWidget {
|
class StopSingleChequeScreen extends StatefulWidget {
|
||||||
final User selectedAccount;
|
final User selectedAccount;
|
||||||
@@ -27,6 +31,7 @@ class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
|
|||||||
final _stopExpiryDateController = TextEditingController();
|
final _stopExpiryDateController = TextEditingController();
|
||||||
final _stopAmountController = TextEditingController();
|
final _stopAmountController = TextEditingController();
|
||||||
final _stopCommentController = TextEditingController();
|
final _stopCommentController = TextEditingController();
|
||||||
|
final _chequeService = getIt<ChequeService>();
|
||||||
|
|
||||||
String _formatDate(String dateString) {
|
String _formatDate(String dateString) {
|
||||||
if (dateString.length != 8) {
|
if (dateString.length != 8) {
|
||||||
@@ -42,6 +47,33 @@ class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _showResponseDialog(String title, String message) async {
|
||||||
|
return showDialog<void>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false, // user must tap button!
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(title),
|
||||||
|
content: SingleChildScrollView(
|
||||||
|
child: ListBody(
|
||||||
|
children: <Widget>[
|
||||||
|
Text(message),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: <Widget>[
|
||||||
|
TextButton(
|
||||||
|
child: const Text('Close'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -148,9 +180,32 @@ class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
if (_formKey.currentState!.validate()) {
|
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'),
|
child: const Text('Stop Cheque'),
|
||||||
|
|||||||
Reference in New Issue
Block a user