36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
using Elwig.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Elwig.Helpers.Billing {
|
|
public class Transaction {
|
|
|
|
public readonly Member Member;
|
|
public readonly long AmountCent;
|
|
public readonly string Currency;
|
|
public readonly int Nr;
|
|
|
|
public Transaction(Member m, decimal amount, string currency, int nr) {
|
|
Member = m;
|
|
AmountCent = (long)Math.Round(amount * 100);
|
|
Currency = currency;
|
|
Nr = nr;
|
|
}
|
|
|
|
public static IEnumerable<Transaction> FromPaymentVariant(PaymentVar variant) {
|
|
var last = variant.Season.PaymentVariants.Where(v => v.TransferDate != null).OrderBy(v => v.TransferDate).LastOrDefault();
|
|
var dict = last?.MemberPayments.ToDictionary(m => m.MgNr, m => m.Amount) ?? new();
|
|
return variant.MemberPayments
|
|
.OrderBy(m => m.MgNr)
|
|
.Select(m => {
|
|
var amt = Math.Round(dict.GetValueOrDefault(m.MgNr, 0), 2);
|
|
return new Transaction(m.Member, m.Amount - amt, m.Variant.Season.CurrencyCode, m.TgNr ?? 0);
|
|
})
|
|
.ToList();
|
|
}
|
|
|
|
public static string FormatAmountCent(long cents) => $"{cents / 100}.{cents % 100:00}";
|
|
}
|
|
}
|