Invoice Rules

Validate invoice arithmetic before it reaches the next system

3 minute readBy Brownsmith Dynamics

A practical way to catch malformed invoice data and amount mismatches before an import or approval step.

An invoice record can look convincing and still fail when it reaches accounting software: a line total may not equal quantity times price, the header tax may not match the line taxes, or a date field may be malformed. Catching these problems at the boundary between data entry and the next application step makes them easier to explain and fix.

Invoice Rules is a Node.js library for validating invoice-shaped JavaScript values. It checks structure, dates, decimal values, configured policies, and arithmetic, then returns issues with a field path, stable code, severity, and message. It is a data validation component, not an invoice issuer or legal tax decision system. Brownsmith Dynamics publishes practical software tools; learn more at its main site.

Use it where data enters your workflow

Imagine a small service app collecting an invoice before a staff member approves it. The submitted record has two consulting hours at 10.00 each, a supplied tax amount of 2.00, and a total of 22.00. A validator can check whether required fields exist and whether line and header figures agree under the configured arithmetic policy. If someone enters a line total of 21.00, the result can point to the relevant path instead of leaving an unexplained mismatch downstream.

The package accepts an unknown value, so an application can validate data parsed from JSON or built from a form. For JSON text, a separate helper parses and validates it, reporting invalid JSON as an issue. A reusable validator can capture chosen options for repeated use. The report distinguishes errors, warnings, and informational findings; an error makes the overall result invalid. Callers can use stable issue codes in application behavior rather than depending on message wording.

Make decimal policy explicit

Money arithmetic is a common source of avoidable surprises. Invoice Rules uses decimal handling with configurable precision, rounding mode, and tax aggregation policy. Defaults use two decimal places, half-up rounding, and per-line tax rounding. If exact decimal input matters, pass strings such as “125.40” instead of first calculating with JavaScript floating-point values. Once precision is lost in an earlier calculation, validation cannot recover it.

Tax rates are data supplied by the caller. The library checks amounts against those inputs; it does not infer a legally applicable rate from a country, product, date, or customer. The optional India rules can perform specified format and consistency checks when a caller has already established the transaction context. They do not verify that a registration is active or determine the legally correct treatment.

Treat a passing result as one check

A valid result means the enabled checks passed. It does not certify statutory completeness, identify the parties, or replace accounting review. Currency validation checks a three-letter uppercase shape, for example, rather than confirming that a code appears in a registry. Applications should still decide which fields and business rules matter for their own intake process.

Set realistic input limits, inspect the report’s truncation flag, and review any custom rules you add.

Invoice Rules requires Node.js 22 or newer and is distributed as an ES module. Read its source and documentation or find Invoice Rules on npm before adding it to a project.