outbound

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: 7 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 outbound builds the documents the gateway sends to a partner: the 855 (order acknowledgment) and the 856 (ship notice).

Input: a Spec, the typed content of the document that the gateway took from its own records (the order it created, the facts of the warehouse), and an Envelope with the three control numbers and the two interchange ids. Output: the bytes of one X12 004010 interchange, or an error. Nothing here comes from the agent.

Build parses its own output with the strict parser and refuses to return bytes the parser would reject, so the gateway never sends what it could not read itself.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(s Spec, env Envelope) ([]byte, error)

Build writes the interchange for the spec.

func Build997

func Build997(a AckSpec, env Envelope) ([]byte, error)

Build997 writes the 997 for the spec. Values copied from the partner are made to fit the field (length, no separators) first, so a strange ST02 or segment id cannot make the gateway's own bytes unreadable; if the strict parser still refuses them, Build997 returns the error and the caller sends no 997.

func GroupCode

func GroupCode(st01 string) string

GroupCode is GS01 of a set: PR for the 855, SH for the 856.

Types

type AckSet

type AckSet struct {
	ID      string // ST01
	Control string // ST02
	Errors  []x12.Error
}

AckSet is the verdict on one set: its ST01 and ST02 as the partner sent them and the errors of the strict parser (none means accepted).

type AckSpec

type AckSpec struct {
	PartnerID    string // ISA05:ISA06 of the receiver of the 997, the partner that sent the group
	GroupCode    string // GS01 of the group
	GroupControl string // GS06 of the group
	Sets         []AckSet
}

AckSpec describes the 997 for one functional group: GS01 and GS06 of the group and its sets.

type Envelope

type Envelope struct {
	Sender, Receiver  string
	ISA13, GS06, ST02 string
	Now               time.Time
}

Envelope holds what the interchange needs besides the content: the ids of the two sides ("ZZ:ID"), the control numbers and the moment of writing.

type Line

type Line struct {
	SKU       string `json:"sku"`
	Qty       string `json:"qty"`
	Unit      string `json:"unit"`
	UnitPrice string `json:"unit_price"`
	Status    string `json:"status,omitempty"`
	SSCC      string `json:"sscc,omitempty"`
}

Line is one line of an outgoing document. Qty is a decimal string with at most three places. Status (855 only) is IA (accepted) or IR (rejected). SSCC (856 only) is the pallet label of the line.

type Spec

type Spec struct {
	ST01       string `json:"st01"`                  // 855 or 856
	PartnerID  string `json:"partner_id"`            // ISA05:ISA06 of the receiver
	Ref        string `json:"ref"`                   // the order number of the partner (BEG03)
	OrderDate  string `json:"order_date"`            // CCYYMMDD (BEG05)
	Currency   string `json:"currency"`              // ISO 4217
	AckType    string `json:"ack_type,omitempty"`    // 855: AC, AD or RJ
	ShipTo     string `json:"ship_to,omitempty"`     // code of the ship-to place
	ShipmentID string `json:"shipment_id,omitempty"` // 856: identification of the shipment (BSN02)
	Lines      []Line `json:"lines"`
}

Spec is the content of an outgoing document. It is stored as JSON in the request to the operator and in the outbox, so the field names are fixed.

func (Spec) AmountCents

func (s Spec) AmountCents() (int64, error)

AmountCents is the sum of the document: quantity times price over the lines that are not rejected, in whole cents.

Jump to

Keyboard shortcuts

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