discountBlockLines function

List<DiscountBlockLine> discountBlockLines(
  1. Iterable<ShiftDiscount>? discounts
)

Zeilen des Rabatte-Blocks auf Z-Bon und Zwischenbericht: je Name <Name> (n×) mit dem Abzug, ab zwei Eintraegen zusaetzlich Rabatte gesamt. Ein leerer Name heisst „Rabatt“. Ein voll stornierter Name (Betrag 0) entfaellt wie in der Liste des Servers. Ohne Rabatte leer (kein Block). Zwilling von discountBlockLines.

Implementation

List<DiscountBlockLine> discountBlockLines(Iterable<ShiftDiscount>? discounts) {
  final liste = [for (final r in discounts ?? const <ShiftDiscount>[]) if (r.cents != 0) r];
  final zeilen = [
    for (final r in liste)
      DiscountBlockLine(
        label: labelText('shift_receipt.discount_line', {
          'name': r.name.isEmpty ? labelText('shift_receipt.discount_unnamed') : r.name,
          'count': r.count,
        }),
        cents: -r.cents,
      ),
  ];
  if (zeilen.length > 1) {
    zeilen.add(DiscountBlockLine(label: labelText('shift_receipt.discounts_total'), cents: -liste.fold<int>(0, (x, r) => x + r.cents)));
  }
  return zeilen;
}