HOW TO: Implementing discounts in an invoicing/billing/pos system. . .?

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

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

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.


depends on how you want to do it :wink:

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...

class LineItem < AR::B
  has_many :line_item_discounts

this assumes multiple discounts are allowed for Order and LineItem...
otherwise use has_one

hope this helps