Add NBT support to GRN processing and pricing calculations

This commit is contained in:
2026-10-08 12:41:44 +05:30
parent 40e890d4ff
commit 55aa35308a
7 changed files with 92 additions and 34 deletions
+10 -5
View File
@@ -1,21 +1,26 @@
namespace Distribution.Features.Grn;
public record LineAmounts(decimal Gross, decimal Discount, decimal Nbt, decimal Vat, decimal Total);
/// <summary>
/// GRN costing. Per line: gross = accepted qty x unit cost; discount = gross x disc%;
/// VAT = (gross - discount) x VAT%; total = gross - discount + VAT. Rejected units are never costed.
/// NBT = (gross - discount) x NBT%; VAT = (gross - discount + NBT) x VAT%;
/// total = gross - discount + NBT + VAT. Rejected units are never costed.
/// Each amount is rounded to 2 dp per line so the GRN totals equal the sum of what the lines show.
/// </summary>
public static class GrnPricing
{
public static decimal Round(decimal value) => Math.Round(value, 2, MidpointRounding.AwayFromZero);
public static (decimal Gross, decimal Discount, decimal Vat, decimal Total) Line(
int acceptedQty, decimal unitCost, decimal discountPercent, decimal vatPercent)
public static LineAmounts Line(
int acceptedQty, decimal unitCost, decimal discountPercent, decimal nbtPercent, decimal vatPercent)
{
var gross = Round(acceptedQty * unitCost);
var discount = Round(gross * discountPercent / 100m);
var vat = Round((gross - discount) * vatPercent / 100m);
return (gross, discount, vat, gross - discount + vat);
var net = gross - discount;
var nbt = Round(net * nbtPercent / 100m);
var vat = Round((net + nbt) * vatPercent / 100m);
return new LineAmounts(gross, discount, nbt, vat, net + nbt + vat);
}
public static void ValidatePercent(decimal value, string label)