Skip to content

Pricing & Costs

Matrix-based subsystem for configuring operational costs and selling prices per zone and weight range, with support for 4 tariff types, dual pricing operators, margin tracking, CSV import/export, and bulk operations.

Overview

Every shipping service has two interrelated data layers managed through this subsystem:

  • Operational Costs: What the carrier charges Envia — a single matrix of zones × weight ranges with fuel configuration.
  • Pricing: What Envia charges customers — 4 separate matrices (one per tariff type: basic, pro, enterprise, corporate), each with its own zone × weight range values.

The Pricing section depends on Costs: margin/markup indicators are calculated using the cost matrix, fuel percentage, and tax rules to derive the "graduated cost" against which prices are compared.

Key Concepts

ConceptDescription
Cost MatrixA 2D grid of zones (columns) × weight ranges (rows) where each cell is the carrier cost in the service currency
Price MatrixSame structure as cost matrix, but 4 instances (one per tariff type). Cell values are either absolute prices (Flat) or markup percentages (Margin)
Extra WeightA single row per matrix showing the per-unit cost/price for weight exceeding the maximum defined range
Fuel Typeflat (fixed percentage) or dynamic (variable, externally updated). Affects graduated cost.
Fuel PercentagePercentage applied to base cost for fuel surcharge calculation
OperatorFlat (1): cell value = selling price. Margin (2): cell value = markup % over graduated cost
Graduated Costbase_cost + (base_cost × tax_rate/100) + (base_cost × fuel_rate/100) — the effective cost used for margin calculations
Markup(price - graduated_cost) / graduated_cost × 100 — percentage increase over cost
Margin(price - graduated_cost) / price × 100 — percentage of price that is profit
Secure MarginsColor-coded thresholds: Danger (<15%), Warning (15–25%), Safe (>25%)
Extended ZoneA flat surcharge (in currency) for extended delivery areas, applied across all tariff types
Upgrade PricingA cross-component feature that recalculates all pricing tariffs by applying a percentage over the cost matrix

Data Flow

Cost Save Flow

Price Save Flow (per tab)

Upgrade Pricing Flow

Database

Tables

TablePurpose
plan_costsMetadata per service: locale_id, fuel_type, fuel_percentage, weight_unit_code, weight_extra_cost
plan_cost_definitionsCost cells: service_id, zone, weight_start, weight_end, cost, extra_cost
plan_definitionsPrice cells: service_id, zone, weight_start, weight_end, cost (the price value), plan_type, operator, extended_zone

Key Fields (plan_cost_definitions / plan_definitions)

ColumnTypeDescription
service_idINT (FK)Reference to services
zoneINTZone identifier
weight_startDECIMALWeight range start (e.g., 0)
weight_endDECIMALWeight range end (e.g., 5)
costDECIMALCost value (in plan_cost_definitions) or price/markup value (in plan_definitions)
extra_costDECIMALPer-unit extra weight cost/price
plan_typeVARCHAROnly in plan_definitions: basic, pro, enterprise, corporate
operatorINTOnly in plan_definitions: 1=Flat, 2=Margin

Key Decisions

DecisionReasoningAlternatives Considered
Separate cost and price tablesCosts change independently from prices; different update cadence and permissionsSingle table with type column (coupling, permission complexity)
Delete + re-insert on saveMatrix saves are atomic — no partial updates. Simpler than diffing.Upsert individual cells (complex, race conditions)
Upgrade Pricing via EventBusCross-component communication between Costs and Pricing without tight couplingShared composable state (more coupling), store actions (adds complexity to store)
Markup vs Margin as view toggle, not dataThe stored data doesn't change — only the display formula. Avoids data conversion issues.Store both values (redundancy, sync issues)
CSV supports partial tariff updatesOperators often update one tariff at a time. Forcing all 4 columns would be cumbersome.Require all columns (inflexible)

Envia Admin