contactAllTicketTypeEndDate method

Map<TicketType, num> contactAllTicketTypeEndDate(
  1. String contactIdString, {
  2. DateTime? end,
})

Implementation

Map<TicketType, num> contactAllTicketTypeEndDate(String contactIdString,
    {DateTime? end}) {
  final filterByRange = (end != null)
      ? where((t) => t.status)
          .where((t) => '${t.contactId}' == contactIdString)
          .where((t) => t.date.isBefore(end) || t.date.isAtSameMomentAs(end))
      : where((t) => t.status)
          .where((t) => '${t.contactId}' == contactIdString);

  num totalSell = 0;
  num totalSellDeferred = 0;
  num totalSellCovered = 0;
  num totalSpend = 0;
  num totalSpendDeferred = 0;
  num totalSpendCovered = 0;
  num totalWage = 0;

  for (final ticket in filterByRange) {
    switch (ticket.ticketType) {
      case TicketType.sell:
        totalSell += ticket.total;

      case TicketType.sellDeferred:
        totalSellDeferred += ticket.total;

      case TicketType.sellCovered:
        totalSellCovered += ticket.total;

      case TicketType.spend:
        totalSpend += ticket.total;

      case TicketType.spendDeferred:
        totalSpendDeferred += ticket.total;

      case TicketType.spendCovered:
        totalSpendCovered += ticket.total;

      case TicketType.wage:
        totalWage += ticket.total;

      case TicketType.unknown:
        print(
            'rhaaaa unknow ticket type in herderTicketTypeRange, not again !');

      default:
        print(
            'default error in herderAllTicketTypeEndDate ${ticket.toJson(isProto: false)} !');
    }
  }

  return {
    TicketType.sell: totalSell,
    TicketType.sellDeferred: totalSellDeferred,
    TicketType.sellCovered: totalSellCovered,
    TicketType.spend: totalSpend,
    TicketType.spendDeferred: totalSpendDeferred,
    TicketType.spendCovered: totalSpendCovered,
    TicketType.wage: totalWage,
  };
}