Answer the question
In order to leave comments, you need to log in
Check discount, partitioning algorithm?
Hello, we have 54FZ, and there is a check of the form:
Позиция Кол-во Цена Сумма
Позиция1 3.8 98 372.4
Позиция2 1 4.5 4.5
Позиция3 6 88.2 529.2
Позиция4 1 180 180
Сумма чека: 1086.1
Answer the question
In order to leave comments, you need to log in
First, once rounding to the second decimal place, multiply all amounts by 100 during the calculation and count all kopecks. Then rounding will be to integers - it's easier.
Second, to make it look better from the start, apply a percentage discount to all prices, rounding up.
Those. in your example the discount should be 86.1/1086.1. In position 1, the price will be 9800*(1-86.1/1086.1) = 9023.11 ~ 9024.
To do this, you can do
item.price = item.price - floor(item.price * discount / total )
leftover = ... # сколько осталось скинуть с чека
foreach item in items:
if leftover == 0: break
if item.count > leftover:
new_item = item
new_item.count = item.count - leftover
item.count = leftover
item.price -= 1
items.add(new_item)
break
else:
item.price -= 1
leftover -= item.count
the problem is simple, solve
the discount, scatter it over the lines of the check (for example, in proportion to the amount of the line),
get the amount of the check line with a discount, then calculate the price again (dividing the discounted amount by the quantity),
be sure to round the price to kopecks (always down! !),
spend all these lines on the fiscal (calculated price with a discount * quantity)
and at the end of the trick, with the introduction of 54FZ, the fiscals lost the opportunity to make markdowns on the check - the price must be indicated taking into account the discount, but penny markdowns can be done, => make a markdown on the check for the number of kopecks that were formed due to price rounding down
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question