Forum: Ruby on Rails HOW TO: Implementing discounts in an invoicing/billing/pos

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
gberz3 (Guest)
on 2007-05-29 18:45
(Received via mailing list)
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.

Jeff E. (Guest)
on 2007-05-29 19:31
(Received via mailing list)
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...

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
This topic is locked and can not be replied to.