97 lines
2.4 KiB
Dart
97 lines
2.4 KiB
Dart
import 'package:dio/dio.dart';
|
|
class Cheque {
|
|
final String? type;
|
|
final String? InstrType;
|
|
final String? Date;
|
|
final String? branchCode;
|
|
final String? fromCheque;
|
|
final String? toCheque;
|
|
final String? Chequescount;
|
|
final String? ChequeNumber;
|
|
final String? transactionCode;
|
|
final int? amount;
|
|
final String? status;
|
|
final String? stopIssueDate;
|
|
final String? StopExpiryDate;
|
|
|
|
Cheque({
|
|
this.type,
|
|
this.InstrType,
|
|
this.Date,
|
|
this.branchCode,
|
|
this.fromCheque,
|
|
this.toCheque,
|
|
this.Chequescount,
|
|
this.ChequeNumber,
|
|
this.transactionCode,
|
|
this.amount,
|
|
this.status,
|
|
this.stopIssueDate,
|
|
this.StopExpiryDate,
|
|
});
|
|
|
|
factory Cheque.fromJson(Map<String, dynamic> json) {
|
|
return Cheque(
|
|
type: json['type'] ?? '',
|
|
InstrType: json['InstrType'] ?? '',
|
|
Date: json['Date'] ?? '',
|
|
branchCode: json['branchCode'] ?? '',
|
|
fromCheque: json['fromCheque'] ?? '',
|
|
toCheque: json['toCheque'] ?? '',
|
|
Chequescount: json['Chequescount'] ?? '',
|
|
ChequeNumber: json['ChequeNumber'] ?? '',
|
|
transactionCode: json['transactionCode'] ?? '',
|
|
amount: json['amount'],
|
|
status: json['status'] ?? '',
|
|
stopIssueDate: json['stopIssueDate'] ?? '',
|
|
StopExpiryDate: json['StopExpiryDate'] ?? '',
|
|
);
|
|
}
|
|
|
|
static List<Cheque> listFromJson(List<dynamic> jsonList) {
|
|
final chequeList =
|
|
jsonList.map((cheque) => Cheque.fromJson(cheque)).toList();
|
|
return chequeList;
|
|
}
|
|
}
|
|
|
|
class ChequeService {
|
|
final Dio _dio;
|
|
ChequeService(this._dio);
|
|
|
|
Future<List<Cheque>> ChequeEnquiry(
|
|
{required String accountNumber,
|
|
required String instrType,
|
|
}) async {
|
|
try {
|
|
final response = await _dio.get(
|
|
"/api/cheque",
|
|
queryParameters: {
|
|
'accountNumber': accountNumber,
|
|
'instrumentType': instrType,
|
|
},
|
|
options: Options(
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
),
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
if (response.data is Map<String, dynamic> && response.data.containsKey('records')) {
|
|
final records = response.data['records'];
|
|
if (records is List) {
|
|
return Cheque.listFromJson(records);
|
|
}
|
|
}
|
|
throw Exception("Unexpected API response format: 'records' list not found or malformed");
|
|
} else {
|
|
throw Exception("Failed to fetch");
|
|
}
|
|
} catch (e) {
|
|
print('Error in ChequeEnquiry: $e');
|
|
throw e;
|
|
}
|
|
}
|
|
}
|