29 lines
1.0 KiB
C#
29 lines
1.0 KiB
C#
using Elwig.Models.Entities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Elwig.Models.Dtos {
|
|
public class Transaction(Member member, decimal amount, string currency, int nr) {
|
|
|
|
public readonly Member Member = member;
|
|
public readonly decimal Amount = amount;
|
|
public readonly string Currency = currency;
|
|
public readonly int Nr = nr;
|
|
|
|
public Transaction(Credit c) : this(c.Member, c.Amount, c.Variant.Season.CurrencyCode, c.TgNr) { }
|
|
|
|
public static IEnumerable<Transaction> FromPaymentVariant(PaymentVar variant) {
|
|
return variant.Credits
|
|
.Where(c => c.Member.Iban != null)
|
|
.OrderBy(c => c.TgNr)
|
|
.Select(c => new Transaction(c))
|
|
.ToList();
|
|
}
|
|
|
|
public static string FormatAmountCent(long cents) => $"{cents / 100}.{Math.Abs(cents % 100):00}";
|
|
|
|
public static string FormatAmount(decimal amount) => FormatAmountCent((int)(amount * 100));
|
|
}
|
|
}
|