[#40] Billing: Add Rebelzuschlag

This commit is contained in:
2024-03-09 20:24:49 +01:00
parent 34ebc8fa34
commit dc83e64db6
9 changed files with 130 additions and 16 deletions

View File

@ -42,6 +42,15 @@ namespace Elwig.Helpers.Billing {
set => SetConsider(value, "consider_auto_business_shares");
}
public double NetWeightModifier {
get => GetWeightModifier("net_weight_modifier", "Rebelzuschlag");
set => SetWeightModifier(value, "net_weight_modifier", "Rebelzuschlag");
}
public double GrossWeightModifier {
get => GetWeightModifier("gross_weight_modifier");
set => SetWeightModifier(value, "gross_weight_modifier");
}
private bool GetConsider(string name, string? wgMasterName = null) {
return ((Mode == CalculationMode.Elwig) ? Data[name] : Data[wgMasterName ?? ""])?.AsValue().GetValue<bool>() ?? false;
}
@ -56,6 +65,23 @@ namespace Elwig.Helpers.Billing {
}
}
private double GetWeightModifier(string name, string? wgMasterName = null) {
var isElwig = (Mode == CalculationMode.Elwig);
var val = (isElwig ? Data[name] : Data[wgMasterName ?? ""])?.AsValue().GetValue<double>() ?? 0;
return isElwig ? val : val / 100.0;
}
private void SetWeightModifier(double value, string name, string? wgMasterName = null) {
var isElwig = (Mode == CalculationMode.Elwig);
if (Mode == CalculationMode.WgMaster && wgMasterName == null) {
return;
} else if (value != 0) {
Data[isElwig ? name : wgMasterName ?? ""] = isElwig ? value : value * 100.0;
} else {
Data.Remove(isElwig ? name : wgMasterName ?? "");
}
}
public BillingData(JsonObject data) {
Data = data;
var mode = Data["mode"]?.GetValue<string>();

View File

@ -146,6 +146,8 @@ namespace Elwig.Helpers.Billing {
var inserts = new List<(int Year, int DId, int DPNr, int BktNr, long Price, long Amount)>();
foreach (var part in parts) {
if (part.Value == 0)
continue;
var ungeb = part.Discr == "_";
var payAttrId = (part.Discr is "" or "_") ? null : part.Discr;
var attrId = part.AttrAreaCom ? payAttrId : part.AttrId;
@ -162,7 +164,16 @@ namespace Elwig.Helpers.Billing {
}
protected async Task CalculateDeliveryModifiers(SqliteConnection cnx) {
var netMod = Data.NetWeightModifier.ToString().Replace(',', '.');
var grossMod = Data.GrossWeightModifier.ToString().Replace(',', '.');
await AppDbContext.ExecuteBatch(cnx, $"""
INSERT INTO payment_delivery_part (year, did, dpnr, avnr, net_amount, mod_abs, mod_rel)
SELECT d.year, d.did, d.dpnr, {AvNr}, 0, 0, IIF(d.net_weight, {netMod}, {grossMod})
FROM delivery_part d
WHERE d.year = {Year}
ON CONFLICT DO UPDATE
SET mod_rel = mod_rel + excluded.mod_rel;
INSERT INTO payment_delivery_part (year, did, dpnr, avnr, net_amount, mod_abs, mod_rel)
SELECT d.year, d.did, d.dpnr, {AvNr}, 0, COALESCE(m.abs, 0), COALESCE(m.rel, 0)
FROM delivery_part d
@ -171,7 +182,7 @@ namespace Elwig.Helpers.Billing {
WHERE d.year = {Year}
ON CONFLICT DO UPDATE
SET mod_abs = mod_abs + excluded.mod_abs,
mod_rel = mod_rel + excluded.mod_rel
mod_rel = mod_rel + excluded.mod_rel;
""");
}
}