read method
Implementation
Future<void> read() async {
state.loading();
await UServices.hotel.readDormBedInvoice(
p: UDormBedInvoiceReadParams(
pageNumber: pageNumber.value,
pageSize: pageSize,
contractId: contract?.id,
isPaid: switch (statusFilter) {
UAdminHotelInvoiceStatusFilter.all => null,
UAdminHotelInvoiceStatusFilter.paid => true,
_ => false,
},
isOverdue: statusFilter == UAdminHotelInvoiceStatusFilter.overdue ? true : null,
minDueDate: startDate,
maxDueDate: endDate,
minDebtAmount: numOf(minDebtFilterController),
maxDebtAmount: numOf(maxDebtFilterController),
selectorArgs: const UDormBedInvoiceSelectorArgs(contract: UDormBedContractSelectorArgs(user: UUserSelectorArgs())),
),
onOk: (UResponse<List<UDormBedInvoiceResponse>> r) {
list = r.result ?? <UDormBedInvoiceResponse>[];
setTotalPages(r.totalCount);
list.isEmpty ? state.emptying() : state.loaded();
},
onError: (UResponse<dynamic> e) => setError(e.message),
onException: (String e) => setError(),
);
if (contract == null) return;
final List<UDormBedInvoiceResponse> all =
(await UServices.hotel.readDormBedInvoice(p: UDormBedInvoiceReadParams(contractId: contract!.id, pageNumber: 1, pageSize: 1000))).$1?.result ?? <UDormBedInvoiceResponse>[];
totalDebt = all.fold(0, (double s, UDormBedInvoiceResponse i) => s + i.debtAmount);
totalPaid = all.fold(0, (double s, UDormBedInvoiceResponse i) => s + i.paidAmount);
totalPenalty = all.fold(0, (double s, UDormBedInvoiceResponse i) => s + i.penaltyAmount);
totalRemaining = all.fold(0, (double s, UDormBedInvoiceResponse i) => s + max(i.netDue, 0));
}