fixed pegination and for rejected status no data displayed
This commit is contained in:
parent
034de5a601
commit
fe950c5b07
@ -63,7 +63,7 @@ class PaymentRequestController extends GetxController {
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
// ---------------- Load More ----------------
|
||||
// ---------------- Load More ----------------
|
||||
Future<void> loadMorePaymentRequests() async {
|
||||
if (isLoading.value || !_hasMoreData) return;
|
||||
|
||||
@ -74,7 +74,7 @@ class PaymentRequestController extends GetxController {
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
// ---------------- Internal API Call ----------------
|
||||
// ---------------- Internal API Call ----------------
|
||||
Future<void> _fetchPaymentRequestsFromApi() async {
|
||||
try {
|
||||
final response = await ApiService.getExpensePaymentRequestListApi(
|
||||
@ -89,21 +89,26 @@ class PaymentRequestController extends GetxController {
|
||||
// First page, replace the list
|
||||
paymentRequests.assignAll(response.data.data);
|
||||
} else {
|
||||
// Insert new data at the top for latest first
|
||||
paymentRequests.insertAll(0, response.data.data);
|
||||
// Append next page items at the end
|
||||
paymentRequests.addAll(response.data.data);
|
||||
}
|
||||
|
||||
// If returned data is less than page size, no more data
|
||||
if (response.data.data.length < _pageSize) {
|
||||
_hasMoreData = false;
|
||||
}
|
||||
} else {
|
||||
if (_pageNumber == 1) {
|
||||
errorMessage.value = 'No payment requests found.';
|
||||
} else {
|
||||
_hasMoreData = false;
|
||||
}
|
||||
_hasMoreData = false;
|
||||
}
|
||||
} catch (e, stack) {
|
||||
errorMessage.value = 'Failed to fetch payment requests.';
|
||||
logSafe("Exception in _fetchPaymentRequestsFromApi: $e",
|
||||
level: LogLevel.error);
|
||||
logSafe("StackTrace: $stack", level: LogLevel.debug);
|
||||
_hasMoreData = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -113,29 +113,37 @@ class PaymentRequestData {
|
||||
: null,
|
||||
dueDate: DateTime.parse(json['dueDate']),
|
||||
project: Project.fromJson(json['project']),
|
||||
recurringPayment: json['recurringPayment'],
|
||||
recurringPayment: json['recurringPayment'] != null
|
||||
? RecurringPayment.fromJson(json['recurringPayment'])
|
||||
: null,
|
||||
expenseCategory: ExpenseCategory.fromJson(json['expenseCategory']),
|
||||
expenseStatus: ExpenseStatus.fromJson(json['expenseStatus']),
|
||||
paidTransactionId: json['paidTransactionId'],
|
||||
paidAt: json['paidAt'] != null ? DateTime.parse(json['paidAt']) : null,
|
||||
paidBy: json['paidBy'] != null ? User.fromJson(json['paidBy']) : null,
|
||||
isAdvancePayment: json['isAdvancePayment'],
|
||||
isAdvancePayment: json['isAdvancePayment'] ?? false,
|
||||
createdAt: DateTime.parse(json['createdAt']),
|
||||
createdBy: User.fromJson(json['createdBy']),
|
||||
updatedAt: DateTime.parse(json['updatedAt']),
|
||||
updatedBy:
|
||||
json['updatedBy'] != null ? User.fromJson(json['updatedBy']) : null,
|
||||
nextStatus: (json['nextStatus'] as List<dynamic>)
|
||||
.map((e) => NextStatus.fromJson(e))
|
||||
.toList(),
|
||||
updateLogs: (json['updateLogs'] as List<dynamic>)
|
||||
.map((e) => UpdateLog.fromJson(e))
|
||||
.toList(),
|
||||
attachments: (json['attachments'] as List<dynamic>)
|
||||
.map((e) => Attachment.fromJson(e))
|
||||
.toList(),
|
||||
isActive: json['isActive'],
|
||||
isExpenseCreated: json['isExpenseCreated'],
|
||||
nextStatus: (json['nextStatus'] != null
|
||||
? (json['nextStatus'] as List<dynamic>)
|
||||
.map((e) => NextStatus.fromJson(e))
|
||||
.toList()
|
||||
: <NextStatus>[]),
|
||||
updateLogs: (json['updateLogs'] != null
|
||||
? (json['updateLogs'] as List<dynamic>)
|
||||
.map((e) => UpdateLog.fromJson(e))
|
||||
.toList()
|
||||
: <UpdateLog>[]),
|
||||
attachments: (json['attachments'] != null
|
||||
? (json['attachments'] as List<dynamic>)
|
||||
.map((e) => Attachment.fromJson(e))
|
||||
.toList()
|
||||
: <Attachment>[]),
|
||||
isActive: json['isActive'] ?? true,
|
||||
isExpenseCreated: json['isExpenseCreated'] ?? false,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
@ -169,6 +177,35 @@ class PaymentRequestData {
|
||||
};
|
||||
}
|
||||
|
||||
class RecurringPayment {
|
||||
String id;
|
||||
String recurringPaymentUID;
|
||||
double amount;
|
||||
bool isVariable;
|
||||
|
||||
RecurringPayment({
|
||||
required this.id,
|
||||
required this.recurringPaymentUID,
|
||||
required this.amount,
|
||||
required this.isVariable,
|
||||
});
|
||||
|
||||
factory RecurringPayment.fromJson(Map<String, dynamic> json) =>
|
||||
RecurringPayment(
|
||||
id: json['id'],
|
||||
recurringPaymentUID: json['recurringPaymentUID'],
|
||||
amount: (json['amount'] as num).toDouble(),
|
||||
isVariable: json['isVariable'],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'recurringPaymentUID': recurringPaymentUID,
|
||||
'amount': amount,
|
||||
'isVariable': isVariable,
|
||||
};
|
||||
}
|
||||
|
||||
class Currency {
|
||||
String id;
|
||||
String currencyCode;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user