# HOW TO: Implementing discounts in an invoicing/billing/pos

**URL:** <https://www.ruby-forum.com/t/how-to-implementing-discounts-in-an-invoicing-billing-pos/105397>\
**Category:** Rails\
**Created:** [May 29, 2007, 4:45pm UTC](https://www.ruby-forum.com/t/how-to-implementing-discounts-in-an-invoicing-billing-pos/105397 "2007-05-29T16:45:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gberz3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f9ae1b/32.png) [@gberz3](https://www.ruby-forum.com/u/gberz3)\
**Post date:** [May 29, 2007, 4:45pm UTC](https://www.ruby-forum.com/t/how-to-implementing-discounts-in-an-invoicing-billing-pos/105397/1 "2007-05-29T16:45:26Z")

</div>

Hi All,

I’m in the process of creating an invoicing/billing/pos-esque package  
with Rails. It was suggested I do something I’m excited about and  
potentially even need in order to motivate me; so, that’s what I’m  
doing.

Aaaaaanywho, I’ve got a bit of an implementation question. I want  
this application to be as “real-world” as possible. That being the  
case, I’m having an issue with how to implement discounts. Personally  
I usually only discount on the basis of the entire order whenever  
billing. However, I’m sure certain ones discount on a per-line-item  
basis.

So, I guess, I’m basically asking for implementation suggestions when  
it comes to discounts. For instance should I implement a discount:

1. per invoice?

2. per line item?

3. on both?

4. by some mechanism not mentioned here?

. . .please provide a few details to back up your suggestion(s) if at  
all possible.

Thanks,  
Michael

---

<div class="post-metadata">

**Author:** ![gberz3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f9ae1b/32.png) [@gberz3](https://www.ruby-forum.com/u/gberz3)\
**Post date:** [May 29, 2007, 5:31pm UTC](https://www.ruby-forum.com/t/how-to-implementing-discounts-in-an-invoicing-billing-pos/105397/2 "2007-05-29T17:31:49Z")

</div>

depends on how you want to do it 😉

very roughly and off the top of my head, i’d think you could  
accomplish #3 like so:

class Order \< AR::B  
has\_many :order\_discounts

def get\_total\_with\_discounts  
… total the line\_items with respective discounts if any…  
… return total with order\_discounts applied if any…  
end  
end

class LineItem \< AR::B  
has\_many :line\_item\_discounts  
end

this assumes multiple discounts are allowed for Order and LineItem…  
otherwise use has\_one

hope this helps
