Line item matching in accounting ensures that invoice processing goes smoothly - for example, that no incorrect amounts are paid to suppliers.
Depending on the company, different types of invoice matching are available. Three-way matching for example, checks invoices against two other documents, such as the delivery note and the purchase order. If the line items in all three documents match, payment can be released. Only goods that arrive at the company complete and undamaged are paid for.
The following configuration example shows step-by-step how to configure a three-way match in the DocuWare Workflow Designer. The instructions are based on an invoice, a delivery note and a purchase order using the table data matching function that is included in DocuWare Workflow Manager version 7.8 and higher.
Prerequisites
To recreate the steps from this workflow in your own DocuWare, first store three documents in a DocuWare file cabinet:
purchase order with document number and the line items in an index table – see also file cabinet example "Line Items" below
delivery note with order number and the line items in an index table – see also file cabinet example "Line Items" below
invoice with order number and the line items in an index table – see also file cabinet example "Line Items" below

You need a file cabinet with at least following database fields:
Document Type (Text)
Document Number (Text)
Order Number (Text)
Status (Text)
Line Items (Table) with columns:
ID (Text)
Name (Text)
Quantity (Decimal)
Unit Price (Decimal)
Amount (Decimal)
In addition, you need the following columns for the matching in the workflow. PO means purchase prder and DN means delivery note.
PO Unit Price (Decimal)
PO Quantity (Decimal)
DN Quantity (Decimal)
Amount Deviation (Decimal)
Quantity Deviation (Decimal)
Match Status (Text)
This is how it looks like in the file cabinet configuration: :

All line items to be used for three-way matching must be stored in these columns for each invoice, purchase order and delivery note:
ID (Text)
Name (Text)
Quantity (Decimal)
Unit Price (Decimal)
Amount (Decimal)
Workflow configuration
You configure the three-way-match in DocuWare with the Workflow Designer. For that a file cabinet configuration as described in the chapter Prequisites is needed. The names of the index fields, tables and parameters in the description below refer to the names listed there.
For orientation purposes, you can first see an overview of the fully configured workflow here:
I. Define trigger
Choose a start condition that will trigger the workflow when a new Invoice is stored.

II. Create activity for retrieving the order number
Create a global variable "GV_myPONumber" of type Text first.

Then create an activity Assign Data with the name "Get PO Number".
In this activity, you save the global variable with the index entry Order Number. This means that the purchase order number is read out for each new invoice and is available in the workflow. The order number can be used to clearly assign the invoice, delivery note and purchase order.

III. Configure matching of order and delivery note with invoice
In another activity Assign Data the actual three-way match is defined:
Get unit price and quantity from the purchase order, match by document number (which is the order number here)
Get quantity from the delivery note, match by order number
Compare of quantity and price for each line
Derive matching status
Set the document status of the invoice
After these steps, the Assign Data dialog looks like this - the definition of the eight lines is now described in detail.

Line 1: Get unit price and quantity from the purchase order
As the first line in the dialog of the Assign data activity, select Index Table - Multiple Columns, for field/variable Line items and as entry type Index table.
Open the data assignment dialog for the table field using the pencil icon. Specify the source the file cabinet you created in the previous step Prequisites and select your index table, in this example it is Line items.
Add following WHERE clause:
DW_DOCUMENT_TYPE = 'Purchase Order Out' AND DW_DOCUMENTNO = 'GV_myPONumber'
This allows you to get from the file cabinet the purchase order for the invoice currently in the workflow.

Now assign the data from the order to the same data from the invoice. Switch to the Rows tab and activate Compose rows by Matchcode.
Select the column "Line Items[ID]" as matchcode and for sorting.

Go to Columns tab and assign the destination and source columns:

Line 2: Match unit price and quantity with invoice amount
In the dialog of the Assign data activity, add a new line to calculate whether the data on unit price and quantity from the purchase order match the invoice: Invoice amount - (unit price of the order * quantity of the order).
Enter as destination Index table - Single column > Line Items - Match Amount > Arithmetic Expression
Add the following expression:
DW_LINE_ITEMS[LINE__LINE_AMOUNT]-
(DW_LINE_ITEMS[LINE__PO_QUANTITY]*DW_LINE_ITEMS[LINE__PO_UNIT_PRICE])
This will return either "0" if the amount matches, or the difference if the amount doesn't match.

Line 3: Get quantity from the delivery note
Add the third line. Destination is Index table – Single Column > Line Items – DN Quantity > Index table.
Open the data assignment dialog for the table field via the pencil icon. Specify the source file cabinet and the Line Items table.
Add the following WHERE clause:
DW_DOCUMENT_TYPE = 'Delivery Note In' AND DW_ORDER_NUMBER = 'GV_myPONumber'
This gets the appropriate delivery note.

Switch to tab Rows and activate Compose rows by Matchcode. Select column Line Items[ID] as matchcode and for sorting:

Go to tab Columns and assign the destination and source column.

Line 4: Compare data of the delivery note with the invoice
Add a new data assignment and check if one of the combinations does not match:
Quantity of invoice does not equal quantity of the purchase order
Quantity of invoice does not equal quantity of delivery note
Quantity of purchase order does not equal quantity of delivery note
For this select as destination: Index table – Single Column > Line Items – Match Quantity > Arithmetic Expression
Add the following expression:
iif(DW_LINE_ITEMS[LINE__QUANTITY]<>DW_LINE_ITEMS[LINE__PO_QUANTITY],DW_LINE_ITEMS[LINE__QUANTITY]-DW_LINE_ITEMS[LINE__PO_QUANTITY],iif(DW_LINE_ITEMS[LINE__QUANTITY]<>DW_LINE_ITEMS[LINE__DN_QUANTITY], DW_LINE_ITEMS[LINE__QUANTITY]-DW_LINE_ITEMS[LINE__DN_QUANTITY],iif(DW_LINE_ITEMS[LINE__PO_QUANTITY]<>DW_LINE_ITEMS[LINE__DN_QUANTITY],DW_LINE_ITEMS[LINE__PO_QUANTITY]-DW_LINE_ITEMS[LINE__DN_QUANTITY],0)))
This will return either "0" if the quantity matches, or the difference of the combination which doesn't match.

Lines 5,6 and 7: Derive status of invoice
Add three new data assignments. Select as destination Index table - Single Column > Line Items - Match Status > Fixed entry and enter the match status for each line as shown:

Use the Filter to find and write to the correct lines:
✓ OK
Amount Deviation!
Quantity Deviation!
Line 8: Set document status "Review"
The last data assignment sets the document status of the invoice to Review by default if a discrepancy is detected during matching.

IV. Evaluation of the matching
Add a Condition activity to evaluate if all lines match or not.
For this the values in column Match Status are counted, basically is counted how often is there "Amount Deviation!" and "Quantity Deviation!". If the count equals "0" it means that all line items match.
It is important that you use the exact same spelling for the parameters here as above.
Add the following expression:
Count(Filter(DW_LINE_ITEMS[LINE__MATCH_STATUS], "Amount Deviation!")) = 0 AND Count(Filter(DW_LINE_ITEMS[LINE__MATCH_STATUS], "Quantity Deviation!")) = 0

Route all Invoices which do not match to a task activity Review Invoice.
Route all other Invoices to an Assign Data activity where you set the Document Status to Approved, which means the Invoices are cleared to be paid.
