Skip to content

Additional Services & Charges

CRUD subsystem for managing optional add-on services and mandatory surcharges on a shipping service, with 19 pricing operator types, range-based plan definitions, and condition-based activation for charges.

Overview

Each shipping service can have two categories of add-ons, both stored in the same table and managed through the same API and UI:

  • Additional Services (mandatory = false): Optional features that can be enabled/disabled per shipment (e.g., insurance, signature required, extended area delivery).
  • Additional Charges (mandatory = true): Surcharges automatically applied when activation conditions are met (e.g., overweight fee, oversized package, remote area surcharge).

The distinction is controlled by a single mandatory flag. Additional Charges have an extra conditions layer that defines when the charge triggers.

Key Concepts

ConceptDescription
Additional ServiceAn add-on with mandatory = false, toggleable per shipment
Additional ChargeAn add-on with mandatory = true, auto-applied when conditions match
OperatorOne of 19 pricing calculation methods (flat, percentage, weight-based, range-based, etc.)
Plan DefinitionsRange-based pricing rows for operators 4, 15, 19 (weight ranges or amount ranges with per-range rates)
ConditionA rule that determines when an additional charge is applied: reference_value operator value (e.g., weight > 30)
Apply ToScope of charge calculation: shipment (once), package (per package), or unit (per item)
Include VATWhether VAT is already included in the configured amount (for fiscal reporting)

Operator Reference

IDNameAmount FieldsDescription
1FlatamountFixed fee in service currency
2Percentageamount (%)Percentage of shipment value
3Highest: Flat or %amount (%), minimum_amountHigher of percentage or flat minimum
4Range Price Plansplan_definitionsDifferent rates per weight range
5Min + Commissionminimum_amount, amount (%)Base minimum plus percentage of insurance
6Web Service %amount (%)Percentage of external web service price
7Web Service ResponseAmount returned by external service
8Min or User Inputminimum_amountUser enters amount, minimum enforced
9Flat USDamount (USD)Fixed fee in US dollars
10Package Weightamount (per kg)Multiplied by package weight
11Highest: Flat or % (COD)amount (%), minimum_amountSame as 3, for cash on delivery
12Flat + InsuranceamountFlat fee plus insurance-based calculation
13Highest: Flat or % (USD)amount (%), minimum_amount (USD)Same as 3 with USD minimum
14Weight Over Allowedamount (per kg)Applied to weight exceeding limit
15Range Plans (Amount)plan_definitionsDifferent rates per declared value range
16Package Weight or Minminimum_amount, amount (per kg)Higher of minimum or weight × rate
17Base + Package Weightbase_amount, amount (per kg)Fixed base plus weight × rate
18Higher: Carrier or %amount (%)Higher of carrier surcharge or percentage
19Range Plans (Insurance)plan_definitionsDifferent rates per insurance value range

Percentage operators store the amount as a decimal (0.15 = 15%). The UI converts for display.

Range-based operators (4, 15, 19) use plan_definitions instead of the main amount fields.

Data Flow

List and Toggle Flow

Create Flow

Database

Tables

TablePurpose
additional_service_pricesMain record: service_id, operator, amounts, mandatory flag, apply_to, tax config, active
additional_service_plan_definitionsRange rows for operators 4/15/19: min_value, max_value, operation_id, amount
additional_service_conditionsActivation conditions for charges: reference_value, operator, value, active
catalog_additional_servicesCatalog of available service types (name, description)
catalog_additional_service_operatorsCatalog of operators (id, name, description)

Key Fields (additional_service_prices)

ColumnTypeDescription
idINT (PK)Auto-increment
service_idINT (FK)Reference to services
additional_service_idINT (FK)Reference to catalog
operation_idINTOperator type (1–19)
mandatoryTINYINT0 = additional service, 1 = additional charge
apply_toENUMshipment, package, or unit
amountDECIMALMain amount (meaning depends on operator)
minimum_amountDECIMALMinimum amount (for composite operators)
maximum_amountDECIMALMaximum cap (optional)
base_amountDECIMALBase amount (for operator 17)
editableTINYINTWhether amount is editable per shipment
force_saveTINYINTForce save even if already present
activeTINYINT0 = inactive, 1 = active
include_vatTINYINTWhether VAT is included in amount
tax_percentage_includedDECIMALTax rate to apply (from service tax rules)

Entity Relationships

Condition Fields

ColumnTypeDescription
idINT (PK)Auto-increment
reference_valueVARCHARProperty to evaluate (weight, length, zone, etc.)
conditionVARCHARComparison operator (>, >=, <, <=, =, !=)
valueDECIMAL/VARCHARThreshold value
activeTINYINT0 = disabled, 1 = enabled

Available reference values: weight, rawWeight, length, width, height, dimensionsSum, dimensionsCubic, insurance, declaredValueUSD, zone, shipmentWeight, companyId, custom.

Key Decisions

DecisionReasoningAlternatives Considered
Single table for services + chargesmandatory flag is the only behavioral difference. Avoids table duplication.Separate tables (redundant schema, duplicate API)
19 operator typesCovers all carrier billing models encountered across 50+ carriers in productionGeneric formula engine (too complex for operators to configure), fewer operators (insufficient coverage)
Operator locked after creationChanging operator would require migrating amount fields and plan definitions — error-proneAllow operator change with data migration (complex, risky)
Plan definitions for range-based operatorsRanges with different rates per interval is a common carrier pricing modelJSON blob (not queryable), dynamic columns (schema nightmare)
Conditions as separate tableMultiple conditions per charge, independently toggleable, extensibleJSON array in main table (loses queryability), single condition field (insufficient)

Envia Admin