leviroiz.dev Back to the album
PT

Track 03 · Delivered · in productionJavaScript, tested with Playwright

Sales discount calculator

Loyalty, volume pricing and PIX on the same order. Which saves the most?

Try the calculator

3 rules, 1 best totalinternal tool delivered to the sales team

The story

When closing an order, the sales team had to compare loyalty pricing, volume pricing and PIX. The calculator compares the options and shows the lowest total.

The public calculator with gross order amount, PIX payment and quantities by reference.
The public calculator with a synthetic catalog.

Each unit receives a single discount.

Toggle PIX on this sample order and watch the total change. You can also adjust quantities.

Applied total —

Sample order

Standard

—

    PIX

    —
      Why did this total win?

      The rules

      • Loyalty pricing depends on the gross order amount. Volume pricing depends on the quantity of each reference.
      • The engine compares the available discounts for each reference and applies one.
      • The PIX discount is rounded on the eligible total so the cents reconcile across the order.
      • For every scenario: gross − savings = final.

      How the engine decides

      1. Validate quantities and represent amounts as integer cents.
      2. Find the loyalty tier from the gross order amount.
      3. Apply volume pricing by reference and quantity.
      4. Calculate the PIX scenario separately.
      5. The largest savings win. The standard scenario wins a tie.
      6. Verify that gross − savings = final.

      Rules, calculations and interface code live in separate files, so the business logic can be tested without a browser. The interface was tested in both themes at 1440, 390 and 320 px. The order stays in browser memory.

      Next trackConsignment