Class: CustomerOutletPurchase::Commission
- Inherits:
-
Object
- Object
- CustomerOutletPurchase::Commission
- Defined in:
- app/models/customer_outlet_purchase/commission.rb
Overview
What a verified outlet purchase pays the rep who worked the project.
Sales management set 1% (they had floated 2%), treating an outlet purchase
like an assisted tech call rather than a direct sale.
Profit, not revenue. Every other commission tier computes on
(sales_value - cogs_value), so a revenue basis would put the figure the
orders team approves at odds with the tier-9 line that eventually pays it.
#basis mirrors view_sales_net_bases exactly.
Nothing pays out on this yet — the tier-9 wiring is separate work. This is the
number the approver is approving.
Instance Attribute Summary collapse
- #purchase ⇒ CustomerOutletPurchase readonly
Instance Method Summary collapse
-
#basis ⇒ BigDecimal
Gross profit on the retailer invoice — what the commission is a percentage of, surfaced so the approver sees the basis and not just the result.
-
#initialize(purchase) ⇒ Commission
constructor
A new instance of Commission.
-
#rate ⇒ Float
The configured rate, e.g.
-
#value ⇒ BigDecimal?
Commission earned, or nil until a human has verified the link.
Constructor Details
#initialize(purchase) ⇒ Commission
Returns a new instance of Commission.
20 21 22 |
# File 'app/models/customer_outlet_purchase/commission.rb', line 20 def initialize(purchase) @purchase = purchase end |
Instance Attribute Details
#purchase ⇒ CustomerOutletPurchase (readonly)
25 26 27 |
# File 'app/models/customer_outlet_purchase/commission.rb', line 25 def purchase @purchase end |
Instance Method Details
#basis ⇒ BigDecimal
Gross profit on the retailer invoice — what the commission is a percentage
of, surfaced so the approver sees the basis and not just the result.
44 45 46 47 48 49 |
# File 'app/models/customer_outlet_purchase/commission.rb', line 44 def basis @basis ||= begin totals = line_item_totals (totals.first.to_d - totals.last.to_d).round(2) end end |
#rate ⇒ Float
Returns the configured rate, e.g. 0.01 for 1%.
52 |
# File 'app/models/customer_outlet_purchase/commission.rb', line 52 def rate = Setting.outlet_purchase_commission_rate |
#value ⇒ BigDecimal?
Commission earned, or nil until a human has verified the link.
Computed on read, never stored: the rate is a Setting that has already
moved once, and a stored amount would freeze whatever it was on the day
somebody clicked Verify.
34 35 36 37 38 |
# File 'app/models/customer_outlet_purchase/commission.rb', line 34 def value return unless purchase.attributed? (basis * rate.to_d).round(2) end |