FuelSurcharge

Copy Markdown

Small, dependency-free Elixir functions for the fuel surcharge line on a trucking rate: per-mile FSC from a weekly diesel price, the total for a trip, the share of the linehaul that is really fuel, and the bracket tables shippers print in their contracts.

Why

Most contracts don't pay fuel as a flat number. They name a base price (the peg) and an MPG divisor, then pay the gap between this week's diesel average and the peg, divided by the MPG, for every loaded mile. It is simple math, but it is easy to get wrong when the peg and divisor change from customer to customer.

FuelSurcharge.per_mile(3.85, 1.25, 6)
#=> 0.433

FuelSurcharge.for_trip(3.85, 1.25, 6, 812)
#=> 351.6

FuelSurcharge.percent_of_linehaul(3.85, 1.25, 6, 812, 2100)
#=> 16.7

Notes:

  • Deadhead miles normally earn no surcharge, so pass loaded miles only.
  • When diesel drops to or below the peg the surcharge is zero, never negative.
  • bracket_table/5 reproduces the step tables printed in contracts so you can check a customer's table against the formula.

If you just need a quick answer without writing code, there is an in-browser version of this surcharge math by TruckLeap.

Installation

def deps do
  [{:fuel_surcharge, "~> 0.1"}]
end

License

MIT, by George Green.