Bug fixes in converting invoice to gbp method

This commit is contained in:
2025-06-27 09:02:22 +01:00
parent 29f9fae508
commit 5900a6e6e4
2 changed files with 24 additions and 8 deletions

View File

@@ -113,14 +113,14 @@ namespace bnhtrade.Core.Logic.Account
// convert line items
var lineWeighting = new List<(int, decimal)>();
var lineCalculatedTotalByWeighting = new List<(int, decimal)>();
decimal newLineSum = 0;
decimal convertedLineListSum = 0;
int i = 0;
foreach (var line in invoice.InvoiceLineList)
{
decimal weighting = line.LineTotalAmount / invoiceOriginalTotalAmount;
decimal lineCalculatedTotal = invoiceOriginalTotalAmount * weighting;
decimal lineConvertedTotal = existingRate.ConvertToGbp(invoiceOriginalTotalAmount * weighting);
lineWeighting.Add(new(i, weighting));
lineCalculatedTotalByWeighting.Add(new(i, lineCalculatedTotal));
lineCalculatedTotalByWeighting.Add(new(i, lineConvertedTotal));
// edit line
if (line.TaxAmountAdjust != 0)
@@ -128,17 +128,17 @@ namespace bnhtrade.Core.Logic.Account
line.TaxAmountAdjust = existingRate.ConvertToGbp(line.TaxAmountAdjust);
}
line.UnitAmount = null;
line.SetUnitAmountByLineTotal(decimal.Round(lineCalculatedTotal, 2));
newLineSum += line.LineTotalAmount;
line.SetUnitAmountByLineTotal(decimal.Round(lineConvertedTotal, 2));
convertedLineListSum += line.LineTotalAmount;
i++;
}
// there may be rounding errors
// section untested - may have to fix some bugs in here when I've got some invoice to test on
if (invoiceOriginalTotalAmount != newLineSum)
if (invoice.InvoiceTotalAmount != convertedLineListSum)
{
decimal amountRemainingToDistribute = invoiceOriginalTotalAmount - newLineSum;
decimal amountRemainingToDistribute = invoice.InvoiceTotalAmount.Value - convertedLineListSum;
lineWeighting = lineWeighting.OrderByDescending(i => i.Item2).ToList();
foreach (var line in lineWeighting)