A list of all products with the current quantities is saved. You can count over several sessions and approve at the end.
Whatever is not refunded now is deducted from the remaining balance of the invoice.
Quantities are added through purchases and stocktakes only, so every change has a history.