Stop Cheque @ 2
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,32 +28,18 @@ class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
|
||||
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<StopSingleChequeScreen> {
|
||||
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<StopSingleChequeScreen> {
|
||||
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<StopSingleChequeScreen> {
|
||||
initialValue: widget.instrType,
|
||||
readOnly: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Instrument Type',
|
||||
labelText: 'Instrument Type *',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
@@ -154,7 +139,7 @@ class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
|
||||
),
|
||||
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<StopSingleChequeScreen> {
|
||||
const SizedBox(height: 32),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate() && _validateChequeNumber()) {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
// TODO: Implement stop single cheque logic
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user