Class: CustomerOutletPurchase::Commission

Inherits:
Object
  • Object
show all
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.

See Also:

  • CustomerOutletPurchase
  • doc/tasks/202608081330_OUTLET_PURCHASE_ATTRIBUTIONdoc/tasks/202608081330_OUTLET_PURCHASE_ATTRIBUTION.md

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(purchase) ⇒ Commission

Returns a new instance of Commission.

Parameters:



20
21
22
# File 'app/models/customer_outlet_purchase/commission.rb', line 20

def initialize(purchase)
  @purchase = purchase
end

Instance Attribute Details

#purchaseCustomerOutletPurchase (readonly)



25
26
27
# File 'app/models/customer_outlet_purchase/commission.rb', line 25

def purchase
  @purchase
end

Instance Method Details

#basisBigDecimal

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.

Returns:

  • (BigDecimal)


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

#rateFloat

Returns the configured rate, e.g. 0.01 for 1%.

Returns:

  • (Float)

    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

#valueBigDecimal?

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.

Returns:

  • (BigDecimal, nil)


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