KTPv5
Reference

Barcode Normalization

Reference for item barcode normalization on item create and update.

Scope

Item server normalizes barcode lookup fields when an item is created or updated. The original barcode value is still stored as entered. Normalization writes additional fields used for matching scanned barcodes.

Code references:

AreaFile
Create/update write pathktpv5-item/src/item/item.service.ts
Normalization rulesktpv5-item/src/libs/barcode-utils.ts
Barcode lookup helpersktpv5-item/src/item/item.barcode.service.ts
Item model fieldsktpv5-item/prisma/schema.prisma

Stored Fields

Item stores both the raw barcode and normalized lookup fields:

FieldMeaning
barcodeRaw item barcode entered by the client.
barcodeTypeDetected type: RAW, GTIN, PLU, UPC, or EAN.
barcodeGTINNormalized GTIN-14 lookup value when the barcode can be converted to GTIN-14.
barcodePLUNormalized PLU lookup value for scale/internal labels.

Create And Update Behavior

createItem(companyId, data) and updateItem(companyId, itemId, data) both:

  1. Validate raw barcode uniqueness through validateBarcode(...).
  2. Call getNormalizedBarcode(barcode).
  3. Save the raw barcode.
  4. Save derived barcodeType, barcodeGTIN, and barcodePLU.

This means new and edited items should always carry normalized lookup fields when their barcode matches a supported pattern.

Normalization Rules

Normalization only runs for digits-only raw barcode strings. If the raw value contains any non-digit character, it is treated as RAW.

Raw barcode shapeResult
7 digits starting with 02barcodeType = PLU, barcodePLU = raw barcode, barcodeGTIN = null
13 digits starting with 02barcodeType = PLU, barcodePLU = first 7 digits, barcodeGTIN = null
Valid EAN-13barcodeType = EAN, barcodeGTIN = "0" + barcode
Valid UPC-AbarcodeType = UPC, barcodeGTIN = "00" + barcode
Valid GTIN-14barcodeType = GTIN, barcodeGTIN = barcode
More than 14 digits starting with 01, with valid GTIN-14 at digits 3-16barcodeType = GTIN, barcodeGTIN = extracted GTIN-14
Anything elsebarcodeType = RAW, normalized fields are null

Lookup Behavior

Barcode lookup uses normalized fields before falling back to raw matching:

  1. Normalize the scanned barcode.
  2. If a GTIN-14 is available, search barcodeGTIN.
  3. For short 02... or 2... labels, extract a candidate PLU and search barcodePLU.
  4. Fall back to raw barcode matching.

The rapid lookup path follows the same priority but uses narrower selected fields for POS/device use.

Backfill Helper

The item server also exposes a barcode normalization backfill path:

GET /barcode/normalize

It finds items where both barcodePLU and barcodeGTIN are null, runs getNormalizedBarcode(item.barcode), and updates barcodeType, barcodeGTIN, and barcodePLU.

Use this only as an operational backfill helper. Normal create/update flows already write normalized fields.

On this page