document

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package document holds the types of the stored document body and reads it back for the agent.

Input: the stored JSON (Decode) or an x12.Set of a 997 (BuildAck). Output: the typed header and lines of an 850 or 810, or the body of a 997. Money and quantities are decimal strings written as JSON numbers (json.Number), never float64.

The body of an 850 or 810 is not made here: internal/sanitize builds it through the white list of elements and their formats, and puts every free text into notes. This package only gives that code the types and the number helpers (Decimal, ImpliedDecimal, ISODate).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAck

func BuildAck(set *x12.Set) ([]byte, error)

BuildAck makes the JSON body of an accepted 997. It holds codes and counters only.

func Decimal

func Decimal(s string) string

Decimal turns an X12 R value (digits, one point, optional minus) into a valid JSON number: no leading zeros, no bare point, no negative zero.

func ISODate

func ISODate(s string) string

ISODate turns CCYYMMDD into CCYY-MM-DD. The dictionary already guarantees the shape; anything else comes back unchanged.

func ImpliedDecimal

func ImpliedDecimal(s string, places int) string

ImpliedDecimal turns an N2 value ("5250" with two implied decimals) into "52.50".

Types

type Ack

type Ack struct {
	GroupCode    string   `json:"group_code"`    // AK101
	GroupControl string   `json:"group_control"` // AK102
	Sets         []AckSet `json:"sets"`
	GroupAck     string   `json:"group_ack"` // AK901
	Included     string   `json:"included"`  // AK902
	Received     string   `json:"received"`  // AK903
	Accepted     string   `json:"accepted"`  // AK904
}

Ack is the body of a 997. The gateway reads it (wave 2-7); the agent never sees it.

type AckSet

type AckSet struct {
	SetID   string   `json:"set_id"`  // AK201
	Control string   `json:"control"` // AK202
	Ack     string   `json:"ack"`     // AK501
	Errors  []string `json:"errors"`  // AK502..AK506
}

AckSet is one AK2..AK5 pair of a 997.

type Body810

type Body810 struct {
	Header Header810 `json:"header"`
	Lines  []Line    `json:"lines"`
}

Body810 is the stored body of an 810.

type Body850

type Body850 struct {
	Header Header850 `json:"header"`
	Lines  []Line    `json:"lines"`
}

Body850 is the stored body of an 850.

type Header810

type Header810 struct {
	PartnerID   string      `json:"partner_id"`
	BusinessRef string      `json:"business_ref"` // BIG02
	InvoiceDate string      `json:"invoice_date"` // BIG01, YYYY-MM-DD
	OrderRef    *string     `json:"order_ref"`    // BIG04
	Currency    *string     `json:"currency"`     // CUR02
	TotalAmount json.Number `json:"total_amount"` // TDS01 with two implied decimals
	ShipTo      *string     `json:"ship_to"`      // N1-04 of the N1 loop with N1-01 = ST
	Buyer       *string     `json:"buyer"`        // N1-04 of the N1 loop with N1-01 = BY
	References  []Reference `json:"references"`   // REF01 and REF02 of the heading
}

Header810 is the header of an invoice.

type Header850

type Header850 struct {
	PartnerID   string      `json:"partner_id"`
	BusinessRef string      `json:"business_ref"` // BEG03
	Purpose     string      `json:"purpose"`      // BEG01
	OrderType   string      `json:"order_type"`   // BEG02
	OrderDate   string      `json:"order_date"`   // BEG05, YYYY-MM-DD
	Currency    *string     `json:"currency"`     // CUR02
	ShipTo      *string     `json:"ship_to"`      // N1-04 of the N1 loop with N1-01 = ST
	Buyer       *string     `json:"buyer"`        // N1-04 of the N1 loop with N1-01 = BY
	References  []Reference `json:"references"`   // REF01 and REF02 of the heading
}

Header850 is the header of a purchase order.

type Line

type Line struct {
	LineNo       *string      `json:"line_no"`
	Qty          *json.Number `json:"qty"`
	Unit         *string      `json:"unit"`
	UnitPrice    *json.Number `json:"unit_price"`
	SKU          *string      `json:"sku"`
	SKUQualifier *string      `json:"sku_qualifier"`
}

Line is one PO1 or IT1 loop. Every value is optional in the standard.

func Decode

func Decode(st01 string, raw []byte) (header any, lines []Line, err error)

Decode reads a stored body of an 850 or 810 back into typed values. Fields that are not part of the types are dropped, so nothing else reaches the agent.

type Reference

type Reference struct {
	Qualifier string  `json:"qualifier"`
	ID        *string `json:"id"`
}

Reference is one REF of the heading: qualifier REF01 and identification REF02 (null when the partner left it out). A value that failed its format is a note reference ("$note_N") in place of the text.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL