Calculate the invoice discount amount for each sales line when releasing the document


The main problem is that the applied invoice discount is not distributed coherently between the lines, especially when there are negative lines or lines with different VAT.


Example: