Billing: Prefer Attribute over gebunden status for price
This commit is contained in:
@ -139,10 +139,10 @@ namespace Elwig.Helpers.Billing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async Task CalculatePrices(SqliteConnection cnx) {
|
protected async Task CalculatePrices(SqliteConnection cnx) {
|
||||||
var parts = new List<(int Year, int DId, int DPNr, int BktNr, string SortId, string Discr, int Value, double Oe, double Kmw, string QualId)>();
|
var parts = new List<(int Year, int DId, int DPNr, int BktNr, string SortId, string? AttrId, string Discr, int Value, double Oe, double Kmw, string QualId)>();
|
||||||
using (var cmd = cnx.CreateCommand()) {
|
using (var cmd = cnx.CreateCommand()) {
|
||||||
cmd.CommandText = $"""
|
cmd.CommandText = $"""
|
||||||
SELECT d.year, d.did, d.dpnr, b.bktnr, d.sortid, b.discr, b.value, d.oe, d.kmw, d.qualid
|
SELECT d.year, d.did, d.dpnr, b.bktnr, d.sortid, d.attrid, b.discr, b.value, d.oe, d.kmw, d.qualid
|
||||||
FROM delivery_part_bucket b
|
FROM delivery_part_bucket b
|
||||||
JOIN v_delivery d ON (d.year, d.did, d.dpnr) = (b.year, b.did, b.dpnr)
|
JOIN v_delivery d ON (d.year, d.did, d.dpnr) = (b.year, b.did, b.dpnr)
|
||||||
WHERE b.year = {Year}
|
WHERE b.year = {Year}
|
||||||
@ -151,16 +151,18 @@ namespace Elwig.Helpers.Billing {
|
|||||||
while (await reader.ReadAsync()) {
|
while (await reader.ReadAsync()) {
|
||||||
parts.Add((
|
parts.Add((
|
||||||
reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetInt32(3),
|
reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetInt32(3),
|
||||||
reader.GetString(4), reader.GetString(5), reader.GetInt32(6),
|
reader.GetString(4), reader.IsDBNull(5) ? null : reader.GetString(5), reader.GetString(6),
|
||||||
reader.GetDouble(7), reader.GetDouble(8), reader.GetString(9)
|
reader.GetInt32(7), reader.GetDouble(8), reader.GetDouble(9), reader.GetString(10)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var inserts = new List<(int Year, int DId, int DPNr, int BktNr, long Price, long Amount)>();
|
var inserts = new List<(int Year, int DId, int DPNr, int BktNr, long Price, long Amount)>();
|
||||||
foreach (var part in parts) {
|
foreach (var part in parts) {
|
||||||
var attrId = (part.Discr == "_" || part.Discr == "") ? null : part.Discr;
|
var ungeb = part.Discr == "_";
|
||||||
var price = Data.CalculatePrice(part.SortId, attrId, part.QualId, part.Discr != "_", part.Oe, part.Kmw);
|
var payAttrId = (part.Discr is "" or "_") ? null : part.Discr;
|
||||||
|
var geb = !ungeb && payAttrId == part.AttrId;
|
||||||
|
var price = Data.CalculatePrice(part.SortId, part.AttrId, part.QualId, geb, part.Oe, part.Kmw);
|
||||||
var priceL = PaymentVariant.Season.DecToDb(price);
|
var priceL = PaymentVariant.Season.DecToDb(price);
|
||||||
inserts.Add((part.Year, part.DId, part.DPNr, part.BktNr, priceL, priceL * part.Value));
|
inserts.Add((part.Year, part.DId, part.DPNr, part.BktNr, priceL, priceL * part.Value));
|
||||||
}
|
}
|
||||||
|
@ -63,11 +63,11 @@ namespace Elwig.Helpers.Billing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Curve GetCurve(string sortid, string? attrid) {
|
protected Curve GetCurve(string sortid, string? attrid) {
|
||||||
return PaymentData[$"{sortid}{attrid ?? ""}"];
|
return PaymentData[$"{sortid}{attrid}"];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Curve? GetQualityCurve(string qualid, string sortid, string? attrid) {
|
protected Curve? GetQualityCurve(string qualid, string sortid, string? attrid) {
|
||||||
return QualityData.TryGetValue($"{qualid}/{sortid}{attrid ?? ""}", out var curve) ? curve : null;
|
return QualityData.TryGetValue($"{qualid}/{sortid}{attrid}", out var curve) ? curve : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user