Stop Cheque @ 2
This commit is contained in:
@@ -65,7 +65,7 @@ class ChequeService {
|
|||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
final response = await _dio.get(
|
final response = await _dio.get(
|
||||||
"/api/cheque",
|
"/api/cheque/enquiry",
|
||||||
queryParameters: {
|
queryParameters: {
|
||||||
'accountNumber': accountNumber,
|
'accountNumber': accountNumber,
|
||||||
'instrumentType': instrType,
|
'instrumentType': instrType,
|
||||||
@@ -93,4 +93,35 @@ class ChequeService {
|
|||||||
throw e;
|
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 _stopAmountController = TextEditingController();
|
||||||
final _stopCommentController = TextEditingController();
|
final _stopCommentController = TextEditingController();
|
||||||
|
|
||||||
bool _validateChequeNumber() {
|
String _formatDate(String dateString) {
|
||||||
final value = _stopFromChequeNoController.text;
|
if (dateString.length != 8) {
|
||||||
if (value.isEmpty) {
|
return dateString; // Return as is if not in expected ddmmyyyy format
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(content: Text('Please enter a cheque number')),
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
final chequeNumber = int.tryParse(value);
|
try {
|
||||||
final fromCheque = int.tryParse(widget.fromCheque);
|
final day = dateString.substring(0, 2);
|
||||||
final toCheque = int.tryParse(widget.toCheque);
|
final month = dateString.substring(2, 4);
|
||||||
if (chequeNumber == null || fromCheque == null || toCheque == null) {
|
final year = dateString.substring(4, 8);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
return '$day/$month/$year';
|
||||||
const SnackBar(content: Text('Invalid cheque number format')),
|
} catch (e) {
|
||||||
);
|
return dateString; // Return original string on error
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
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
|
@override
|
||||||
@@ -85,14 +71,13 @@ class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
|
|||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _stopFromChequeNoController,
|
controller: _stopFromChequeNoController,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Cheque Number',
|
labelText: 'Cheque Number *',
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
// This validator will only return null or empty string to allow SnackBar to display
|
|
||||||
if (value == null || value.isEmpty) {
|
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 chequeNumber = int.tryParse(value);
|
||||||
final fromCheque = int.tryParse(widget.fromCheque);
|
final fromCheque = int.tryParse(widget.fromCheque);
|
||||||
@@ -100,10 +85,10 @@ class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
|
|||||||
if (chequeNumber == null ||
|
if (chequeNumber == null ||
|
||||||
fromCheque == null ||
|
fromCheque == null ||
|
||||||
toCheque == null) {
|
toCheque == null) {
|
||||||
return '';
|
return 'Invalid cheque number format';
|
||||||
}
|
}
|
||||||
if (chequeNumber < fromCheque || chequeNumber > toCheque) {
|
if (chequeNumber < fromCheque || chequeNumber > toCheque) {
|
||||||
return '';
|
return 'Cheque number must be between ${widget.fromCheque} and ${widget.toCheque}';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
@@ -113,7 +98,7 @@ class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
|
|||||||
initialValue: widget.instrType,
|
initialValue: widget.instrType,
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Instrument Type',
|
labelText: 'Instrument Type *',
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -154,7 +139,7 @@ class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
initialValue: widget.date,
|
initialValue: _formatDate(widget.date),
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Chequebook Issue Date',
|
labelText: 'Chequebook Issue Date',
|
||||||
@@ -164,7 +149,7 @@ class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
|
|||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (_formKey.currentState!.validate() && _validateChequeNumber()) {
|
if (_formKey.currentState!.validate()) {
|
||||||
// TODO: Implement stop single cheque logic
|
// TODO: Implement stop single cheque logic
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user