Solution

BE-terna Fashion Purchase Matrix

Setup (English) | How it works (English)

What is the purpose of this module

The Purchase Matrix module provides matrix-based quantity entry and store distribution for Fashion purchase orders. It lets users enter quantities for an item across colours, sizes or item lots, dates, and locations without creating every purchase line manually.

Users open the matrix from an item line on a purchase order. Depending on the selected matrix recording type, the module builds either a size-run matrix from item variants or an item-lot matrix from lot definitions. Locations can be selected individually or through a location group, and quantities can be entered directly, copied between locations or colours, or suggested from location weights.

While the matrix is open, headers, lines, and entries are held in temporary records. Saving the matrix updates the purchase lines and persists the matrix data for the purchase order. For size-run recording, completing matrix input creates Fashion item distributions when quantities are assigned to locations other than the purchase order location, optionally stores those distributions, removes the working matrix data, and marks the purchase order as completed for matrix input. Item-lot recording is available for matrix entry and purchase-line updates, but its automatic matrix-to-distribution transfer and storage are not fully implemented; see the setup guide and how the PurchaseMatrix works.

The module prevents concurrent matrix editing through recording locks. It also prevents release of a purchase order while matrix entries still exist, so matrix input must be completed before the order can be released.

Architecture overview

graph LR;

%% Nodes
	title["Purchase Matrix architecture"]
	purchaseLine["Purchase order item line"]
	matrixAction["Matrix action"]
	matrixPage["Purch Matrix page"]
	matrixMgt["Purchase Order Matrix Mgt"]
	matrixHeader[("Purch Matrix Header")]
	matrixLine[("Purch Matrix Line")]
	matrixEntry[("Purchase Order Matrix Entry")]
	itemSize["Purchase Order Matrix Item Size"]
	itemLot["Purchase Order Matrix Item Lot"]
	distributionType["Matrix Distribution Type enum"]
	distributionInterface["IMatrixDistribution"]
	distributionImpl["Distribution implementations"]
	purchaseLines[("Purchase Lines")]
	complete["Complete Matrix Input"]
	creationType["Item Distribution Creation Type mapping"]
	fillInterface["IFillDistributionFromMatrix"]
	itemDistribution[("Fashion Item Distribution")]
	locks[("Purchase Order Matrix Recording Lock")]

%% Flow
	title -.- purchaseLine
	linkStyle 0 stroke:#ffffff
	purchaseLine ==> matrixAction
	matrixAction ==> matrixPage
	matrixPage ==> matrixMgt
	matrixMgt == "creates and releases" ==> locks
	matrixMgt == "loads and persists" ==> matrixHeader
	matrixMgt == "loads and persists" ==> matrixLine
	matrixMgt == "loads and persists" ==> matrixEntry
	matrixPage == "size-run recording" ==> itemSize
	matrixPage == "item-lot recording" ==> itemLot
	matrixHeader ==> distributionType
	distributionType ==> distributionInterface
	distributionInterface ==> distributionImpl
	itemSize == "Save Changes" ==> purchaseLines
	itemLot == "Save Changes" ==> purchaseLines
	matrixEntry ==> complete
	complete ==> creationType
	creationType ==> fillInterface
	fillInterface ==> itemDistribution
	complete == "clears working data" ==> matrixHeader
	complete == "clears working data" ==> matrixLine
	complete == "clears working data" ==> matrixEntry

%% Classes
	class title btProcessTitle
	class purchaseLine,matrixAction,matrixPage,matrixMgt,matrixHeader,matrixLine,matrixEntry,itemSize,itemLot,distributionType,distributionInterface,distributionImpl,purchaseLines,complete,creationType,fillInterface,itemDistribution,locks btProcessActive

The main responsibilities are split as follows:

  • Purch Matrix is the user-facing matrix page. It initializes the matrix for the selected purchase line, presents the size-run or item-lot subpage, manages matrix actions, and asks whether unsaved changes should be saved when the page closes.
  • Purchase Order Matrix Mgt owns matrix initialization, persistence, recording locks, distribution dispatch, completion, and shared validation.
  • Purchase Order Matrix Item Size builds and processes matrices based on item variants and size runs.
  • Purchase Order Matrix Item Lot builds and processes matrices based on Fashion item lots.
  • Purch Matrix Header, Purch Matrix Line, and Purchase Order Matrix Entry store the matrix parameters, row structure, and entered quantities.
  • Matrix Distribution Type selects an IMatrixDistribution implementation. The standard weighted implementation suggests quantities from location weights and handles distribution remainders.
  • Item Distr. Creation Type maps each matrix recording type to the implementations that create matrix data from purchase lines and convert completed matrix entries into Fashion item distributions.
  • Purch Matrix Source Type delegates filtering and deletion for supported source records such as purchase headers, purchase lines, and matrix records.
  • Purchase document event subscribers clean up related matrix data, integrate with item distribution creation, preserve relevant state when documents are copied, and block release while matrix input is unfinished.

Setup and Conditions

The app install code creates one Purchase Order Matrix Setup record per company and initializes the standard item-distribution mappings:

  • Size Run Horizontal maps to Item Size.
  • Item Lot maps to Item Lot.
  • Size Run Vertical maps to Item Size.

The company setup contains these settings:

  • Purchase Order Matrix Reset Type controls how matrix data is reset.
  • Store Distributions controls whether item distributions created during completion are stored immediately.
  • Matrix Recording by Sliding (< >) controls whether users can move through assigned colours as separate matrix views. It is enabled by default.
  • Item Distribution Creation Types opens the mapping between matrix recording types and item-distribution creation types.

Each matrix user also requires configuration on User Setup:

  • Allow Matrix Recording authorizes matrix entry.
  • Matrix Recording Type defines whether the user records by horizontal size run, vertical size run, or item lot.
  • Max. Matrix Column Count limits the displayed matrix columns from 1 to 32.
  • Release Matrix Lock Allowed authorizes manual release of another matrix recording lock.

The purchase order stores the selected Distribution Direction and Matrix Recording Type. These values cannot be changed after matrix entries exist. Matrix entry requires an open purchase order, an item purchase line, the required Fashion item setup, and a configured user.

Matrix Lifecycle

  1. Opening the matrix validates the purchase line and user setup, creates a recording lock, and initializes matrix headers for the assigned colours.
  2. The module loads existing matrix headers, lines, and entries into temporary records. If no lines exist yet, it generates them from item variants or item lots.
  3. The user selects locations or a location group and records, copies, or calculates quantities.
  4. Save Changes writes the entered quantities to purchase lines and persists the matrix headers, lines, and entries. Unsaved changes can also be saved when the matrix page closes.
  5. Closing the page removes the recording lock.
  6. Complete Matrix Input optionally creates and stores Fashion item distributions, deletes the persisted working matrix data, and marks Matrix Input Completed on the purchase order. This action cannot be undone.
  7. A purchase order with remaining matrix entries cannot be released. The entries must first be completed or deliberately reset through the provided actions.

How to Use and Extend the Module

How to Use

  1. Open Purchase Order Matrix Setup and review the reset behavior, distribution storage, sliding mode, and item-distribution mappings.
  2. Configure Allow Matrix Recording, Matrix Recording Type, Max. Matrix Column Count, and, where required, Release Matrix Lock Allowed for each user on User Setup.
  3. Create or open a purchase order and set its location, distribution direction, and matrix recording type.
  4. Add an item line and choose Matrix or press Alt+M.
  5. Select locations with Get Locations or Get Location Group.
  6. Enter quantities directly or use the copy and distribution actions. Weighted distribution is available through the Weight (Location) distribution type.
  7. Choose Save Changes to update the purchase lines and retain the matrix for later editing.
  8. Choose Complete Matrix Input on the purchase order when entry is finished. The module creates item distributions when required, clears the working matrix records, and marks matrix input as completed.
  9. Use Matrix Headers, Matrix Lines, and Matrix Entries to inspect persisted matrix data. Use Delete Matrix Data or Release Matrix Lock only when the corresponding recovery action is intentionally required.
  10. To rebuild a matrix from existing item purchase lines, use Create Matrix Data from Lines.

How to Extend

To add another matrix distribution algorithm:

  1. Create a codeunit that implements IMatrixDistribution.
  2. Implement quantity distribution and clearing for both item-colour and item-lot data.
  3. Extend Matrix Distribution Type with a new value and assign the codeunit as its implementation.
  4. Add tests for calculation, rounding or remainder handling, clearing, and both supported matrix layouts where applicable.

To add another matrix recording and item-distribution creation path:

  1. Extend Matrix Recording Type with the new recording mode.
  2. Implement ICreateMatrixData to reconstruct temporary matrix data from purchase lines.
  3. Implement IFillDistributionFromMatrix to create, populate, and optionally store Fashion item distributions.
  4. Extend Item Distr. Creation Type with a value that maps both interfaces to the new implementations.
  5. Add the recording-type-to-creation-type mapping through Item Distr. Creation Type.InsertDistributionType(...), normally from a subscriber to its initialization event.
  6. Extend the matrix page and processing logic only where the new recording layout requires behavior beyond the existing size-run and item-lot paths.
  7. Add tests for initialization, saving, recreation from purchase lines, completion, and release blocking.

To support another matrix source record:

  1. Create an implementation of IPurchMatrixSourceType that applies the source-specific filters for locks, headers, lines, and entries.
  2. Extend Purch Matrix Source Type and assign the new implementation.
  3. Verify lock creation and release, existence checks, and cascading cleanup for the new source.

Prefer the module’s published integration events when only a step in the existing workflow must be adjusted. Events are available around item-distribution mapping initialization, matrix processing, purchase-order release checks, and distribution record creation.