Skip to content

Commit 665ee16

Browse files
committed
Add discount example
1 parent 65a4df8 commit 665ee16

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ invoice.add_line_item do |line_item|
174174
# Clear all taxes
175175
# line_item.clear_taxes
176176

177+
# Add discounts
178+
line_item.discount_rate = 0.1 # 10% discount
179+
# line_item.discount = 15.0 # Fixed discount amount (takes priority over discount_rate)
180+
177181
# Add surcharges (naknade)
178182
line_item.add_surcharge(name: "Refundable deposit", amount: 2.50)
179183
line_item.add_surcharge do |surcharge|
@@ -188,11 +192,11 @@ invoice.add_line_item do |line_item|
188192
# line_item.clear_surcharges
189193
end
190194

191-
invoice.subtotal # => BigDecimal("200.00")
192-
invoice.tax # => BigDecimal("62.50")
195+
invoice.subtotal # => BigDecimal("180.00") # 200.00 - 20.00 discount (10%)
196+
invoice.tax # => BigDecimal("59.00") # Tax calculated on discounted amount: 180.00 * 0.25 + 180.00 * 0.05
193197
invoice.surcharge # => BigDecimal("3.75")
194-
invoice.total # => BigDecimal("266.25")
195-
invoice.total_cents # => 26625
198+
invoice.total # => BigDecimal("242.75")
199+
invoice.total_cents # => 24275
196200

197201
invoice.number # => "64/HQ1/123"
198202

0 commit comments

Comments
 (0)