list method

Future<List<ReceiptSummary>> list({
  1. String? from,
  2. String? to,
  3. int? limit,
})

Belege dieser Kasse — Zusammenfassungen, neueste zuerst (Serverordnung).

from und to sind Wiener Kalendertage (YYYY-MM-DD); der Server deckelt das Fenster auf 90 Tage und die Anzahl auf 200.

Implementation

Future<List<ReceiptSummary>> list({String? from, String? to, int? limit}) async {
  const name = Aufrufe.listMyReceipts;
  for (final (feld, wert) in [('von', from), ('bis', to)]) {
    if (wert != null && !RegExp(r'^\d{4}-\d{2}-\d{2}').hasMatch(wert)) {
      throw KasseneckValidationError(name, '$feld muss mit YYYY-MM-DD beginnen', 'request');
    }
  }
  if (limit != null && limit < 1) {
    throw const KasseneckValidationError(name, 'hoechstens muss eine ganze Zahl ab 1 sein', 'request');
  }

  final daten = await transport.call(
    name,
    params: {
      'cashregisterId': transport.cashregisterId,
      'from': from,
      'to': to,
      'limit': limit,
    },
  );
  final liste = daten['receipts'];
  if (liste is! List) {
    // Keine Liste ist etwas anderes als eine leere Liste: „heute nichts
    // verkauft" darf nicht aussehen wie „Antwort kaputt".
    throw const KasseneckValidationError(name, 'Antwort enthaelt keine Belegliste (data.receipts fehlt)', 'response');
  }
  return [
    for (final eintrag in liste)
      if (eintrag is Map) ReceiptSummary.fromJson(Map<String, dynamic>.from(eintrag)),
  ];
}