[#32] Dtos/PaymentVariantSummaryData: Allow Data to be exported as Ods
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Documents;
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
@ -8,21 +9,41 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Elwig.Models.Dtos {
|
||||
public class PaymentVariantSummaryData {
|
||||
public class PaymentVariantSummaryData : DataTable<PaymentVariantSummaryData.PaymentRow> {
|
||||
|
||||
public record struct PaymentRow(string Type, string Variety, string? Attribute, string? Cultivation, string QualityLevel, double Oe, int WeightUngeb, decimal? PriceUngeb, int WeightGeb, decimal? PriceGeb, decimal Amount);
|
||||
private static readonly (string, string, string?, int?)[] FieldNames = [
|
||||
("Type", "Typ", null, 10),
|
||||
("Variety", "Sorte", null, 40),
|
||||
("Attribute", "Attribut", null, 20),
|
||||
("Cultivation", "Bewirt.", null, 20),
|
||||
("QualityLevel", "Qualitätsstufe", null, 30),
|
||||
("Oe", "Gradation", "°Oe", 20),
|
||||
("Ungeb", "ungebunden", "kg|€/kg", 40),
|
||||
("Geb", "gebunden", "kg|€/kg", 40),
|
||||
("Amount", "Gesamt", "€", 25),
|
||||
];
|
||||
|
||||
public PaymentRow[] Rows;
|
||||
public record struct PaymentRow(
|
||||
string Type,
|
||||
string Variety,
|
||||
string? Attribute,
|
||||
string? Cultivation,
|
||||
string QualityLevel,
|
||||
double Oe,
|
||||
(int Weight, decimal? Price) Ungeb,
|
||||
(int Weight, decimal? Price) Geb,
|
||||
decimal Amount
|
||||
);
|
||||
|
||||
public PaymentVariantSummaryData(PaymentRow[] rows) {
|
||||
Rows = rows;
|
||||
public PaymentVariantSummaryData(PaymentVar v, IEnumerable<PaymentRow> rows) :
|
||||
base(PaymentVariantSummary.Name, PaymentVariantSummary.Name, v.Name, rows, FieldNames) {
|
||||
}
|
||||
|
||||
public static async Task<PaymentVariantSummaryData> ForPaymentVariant(PaymentVar v, DbSet<PaymentVariantSummaryRow> table) {
|
||||
return new((await FromDbSet(table, v.Year, v.AvNr))
|
||||
return new(v, (await FromDbSet(table, v.Year, v.AvNr))
|
||||
.Select(r => new PaymentRow(r.Type, r.Variety, r.Attribute, r.Cultivation, r.QualityLevel, r.Oe,
|
||||
r.WeightUngeb, r.PriceUngeb != null ? Utils.DecFromDb(r.PriceUngeb.Value, v.Season.Precision) : null,
|
||||
r.WeightGeb, r.PriceGeb != null ? Utils.DecFromDb(r.PriceGeb.Value, v.Season.Precision) : null,
|
||||
(r.WeightUngeb, r.PriceUngeb != null ? Utils.DecFromDb(r.PriceUngeb.Value, v.Season.Precision) : null),
|
||||
(r.WeightGeb, r.PriceGeb != null ? Utils.DecFromDb(r.PriceGeb.Value, v.Season.Precision) : null),
|
||||
Utils.DecFromDb(r.Amount, v.Season.Precision)))
|
||||
.ToArray());
|
||||
}
|
||||
|
Reference in New Issue
Block a user