Purchase Orders

It is important to note that Purchase Orders is only available with the TASLink/TASflex Plus product. So, you need to ensure adequate error trapping for situations where this feature has not been enabled in the end-user runtime environment.

Purchase Orders are held within the TAS Books Purchase Order Ledger.

They can be accessed through the PurchaseOrderHeadersPurchaseOrderHeaderPurchaseOrderLines and PurchaseOrderLine  objects. The PurchaseOrderHeaders and PurchaseOrderLines objects expose standard TASLink Collection properties and methods which are used to navigate the collection and retrieve the PurchaseOrderHeader and PurchaseOrderLine objects which we require.

First create a valid data connection (see Setup and Login for the TASLink Object).

Now create a reference to a PurchaseOrderHeader object and set it to the PurchaseOrderLines object exposed through the TASLink object model.

Dim oPurchaseOrderHeaders As TASLink.PurchaseOrderHeaders
Dim oPurchaseOrderHeader As TASLink.PurchaseOrderHeader
Dim oPurchaseOrderLine As TASLink.PurchaseOrderLine

Set oPurchaseOrderHeader = oSDK.PurchaseOrderHeader

Creating Purchase Orders

Having created and set your reference as described above, you must first add information to the PurchaseOrderHeader object:

If Not oPurchaseOrderHeader.SetHeaderInfo(PurchaseOrderType_Invoice, "B C S") Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If

You must then add at least one body line to the Purchase order; here we add two lines:

If Not oPurchaseOrderHeader.AddPurchaseOrderProductLine("product01", 2, , 0, , 5) Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If

If Not oPurchaseOrderHeader.AddPurchaseOrderProductLine("product02", 2, , 0, 10, 5) Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If

You can also add text lines, like this one:

If Not oPurchaseOrderHeader.AddPurchaseOrderTextLine("Goods supplied on our standard Terms & Conditions") Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If

Then save the Purchase Order:

If oPurchaseOrderHeader.Save() = True Then
	MsgBox "Purchase Order Number = " & oPurchaseOrderHeader.PurchaseOrderNumber
Else
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If

Retrieving Purchase Orders

Having created and set your reference as described above, you can retrieve PurchaseOrderHeader objects from the PurchaseOrderHeaders collection:

Dim LineCounter As Long
Set oPurchaseOrderHeaders = oSDK.PurchaseOrderHeaders

The first thing to do is sort the Purchase Orders.

oPurchaseOrderHeaders.SortBy = PurchaseOrderNumber

You can then provide a lookup to allow the user to select a particular Purchase Order:

Set oPurchaseOrderHeader = oPurchaseOrderHeaders.ProvideUserLookup()

or you can specify a particular Purchase Order to retrieve, in this case 200101:

Set oPurchaseOrderHeader = oPurchaseOrderHeader("200101")

Now you can retrieve body lines by using the PurchaseOrderLine object:

For LineCounter = 1 To oPurchaseOrderHeader.CountOfPurchaseOrderLines
	'retrieve the current line
	Set oPurchaseOrderLine = oPurchaseOrderHeader.GetPurchaseOrderLine(LineCounter)
Next

Updating Purchase Orders

Having retrieved a Purchase Order as described in the previous section, you can edit it provided that it has not been fully received by following the 4 steps set out in this section.

1 – Check if the order is posted

If the order has been posted no changes can be made, so this should be checked first.

If oPurchaseOrderHeader.Complete = True
	MsgBox "You cannot edit a completed order"
	Exit Sub
End If

2 – Check if existing lines need to be added

This must be called in case the order has been part-received (i.e. more than one purchase invoice is to be created off the same purchase order):

'check if all the existing lines need to be added back in
If oPurchaseOrderHeader.UserMustAddExistingPurchaseOrderLines = True Then
        
	'add the existing lines back into the purchase order
    If oPurchaseOrderHeader.AddExistingPurchaseOrderLines = False Then
        MsgBox oSDK.Status.userReadableDescription
        GoTo freeResources
    End If
Else    '' There is no need to retain the existing order lines... 
	If Not oPurchaseOrderHeader.AddExistingPurchaseOrderLines Then
		MsgBox oSDK.Status.userReadableDescription
		GoTo freeResources
    End If
    
	'add any lines you want as though it was a new order
    
End If

3 – Add new lines or Edit existing lines

Now you can add new lines to the order or edit existing lines as required, e.g.:

'set the order quantity = 4
If Not oPurchaseOrderHeader.EditExistingLineDetail(3, PurchaseOrderLineEditableProperty_OrderQuantity, "4") Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If

4 – Save

Finally, save the amended order:

If oPurchaseOrderHeader.Save() = True Then
	MsgBox "Successfully updated purchase Order Number = " & oPurchaseOrderHeader.PurchaseOrderNumber
Else
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If

Receiving Purchase Orders

Having retrieved a Purchase Order as described in the previous section, and checked to see if existing lines need to be added you can then receive the products on it – in whole or in part. For part receiving products, when you receive the balance of the goods you need to use a different GMV reference.

'Set GMV Number
If Not oPurchaseOrderHeader.ReceivePurchaseOrder("MAR1616B") Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If
 
'Set PO Receive Lines
If Not oPurchaseOrderHeader.ReceivePurchaseOrderLine(1, 1) Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If
 
If Not oPurchaseOrderHeader.ReceivePurchaseOrderLine(2, 1) Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If
 
'Save Receive PO
If Not oPurchaseOrderHeader.SaveReceivePurchaseOrder Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
Else
	MsgBox "PO Successfully Received"
End If

Invoicing Purchase Orders

Having retrieved a Purchase Order and received the products on the order, it can then be invoiced.

'Set Invoice Details
If Not oPurchaseOrderHeader.invoicePurchaseOrder("9998", , "Test") Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If
    
'Set Invoice Line Details
If Not oPurchaseOrderHeader.invoicePurchaseOrderLine(1, 5) Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If
    
If Not oPurchaseOrderHeader.invoicePurchaseOrderLine(2, 5) Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If
    
'Save Invoice
If Not oPurchaseOrderHeader.SaveinvoicePurchaseOrder Then        
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources        
Else
	MsgBox "PO Successfully Invoiced"
End If