Sales Orders

It is important to note that Sales 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.

Sales Orders are held within the TAS Books Sales Order Ledger. There are 4 different types of order, as set out in this table:

#Sales Order TypeNotes
1QuotationDoes not affect Stock Quantity values. Can be amended at any time. Can be converted to a Proforma Invoice or to a Sales Order.
2Proforma InvoiceDoes not affect Stock Quantity values. Can be amended at any time. Can be converted to a Sales Order.
3Sales Order (Invoice)Does affect Stock Quantity values. Can be amended at any time until fully posted. Cannot be be converted to a Credit Order or back a Proforma Invoice or Quotation. When fully “printed and posted” it cannot be amended.
4Credit Order (Note)Can (optionally) affect Stock Quantity values, i.e. where goods are being returned to Stock for resale. Can be amended at any time until fully posted. Cannot be converted to any other Sales Order Type. When fully “printed and posted” it cannot be amended.

They can be accessed through the SalesOrderHeadersSalesOrderHeaderSalesOrderLines and SalesOrderLine objects. The SalesOrderHeaders and SalesOrderLines objects expose standard TASLink Collection properties and methods which are used to navigate the collection and retrieve theSalesOrderHeader and SalesOrderLine objects which we require.

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

Now create a reference to a SalesOrderHeader object and set it to the SalesOrderLines object exposed through the TASLink object model.

Dim oSalesOrderHeaders As TASLink.SalesOrderHeaders
Dim oSalesOrderHeader As TASLink.SalesOrderHeader
Dim oSalesOrderLine As TASLink.SalesOrderLine

Set oSalesOrderHeader = oSDK.SalesOrderHeader

Creating Sales Orders

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

If Not oSalesOrderHeader.SetHeaderInfo(SalesOrderType_Invoice, "A C S") Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If

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

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

If Not oSalesOrderHeader.AddSalesOrderProductLine("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 oSalesOrderHeader.AddSalesOrderTextLine("Goods supplied on our standard Terms & Conditions") Then
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If

Then save the Sales Order:

If oSalesOrderHeader.Save() = True Then
	MsgBox "Sales Order Number = " & oSalesOrderHeader.SalesOrderNumber
Else
	MsgBox oSDK.Status.userReadableDescription
	GoTo freeResources
End If

Cashflow Forecast Reporting

With the advent of FirstBooks and TASBooks in 2009, TAS introduced Cashflow Forecast reporting. To achieve this, a new property, ExpectedPaymentDate, has been included in SalesOrderHeader. When you create a Sales Order you may wish to include a value – optionally, because TASLink populates it with a default value if you do not.

Retrieving Sales Orders

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

Dim LineCounter As Long
Set oSalesOrderHeaders = oSDK.SalesOrderHeaders

The first thing to do is sort the Sales Orders.

oSalesOrderHeaders.SortBy = SalesOrderNumber

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

Set oSalesOrderHeader = oSalesOrderHeaders.ProvideUserLookup()

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

Set oSalesOrderHeader = oSalesOrderHeader("200101")

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

For LineCounter = 1 To oSalesOrderHeader.CountOfSalesOrderLines
	'retrieve the current line
	Set oSalesOrderLine = oSalesOrderHeader.GetSalesOrderLine(LineCounter)
Next

Updating Sales Orders

Having retrieved a Sales Order as described in the previous section, you can edit it provided that it has not been fully posted 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 oSalesOrderHeader.PrintingPostingStatusFlag = PrintedCompleted
	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-posted (i.e. more than one invoice is to be created off the same order):

If oSalesOrderHeader.UserMustAddExistingSalesOrderLines = True then
	'add the existing lines
	oSalesOrderHeader.AddExistingSalesOrderLines()
Else
	'not part posted/printed so user can either add existing lines OR start from scratch
	If DeveloperWantsToStartFromScratch = True Then
		'add some lines
	Else
		'add the existing lines
		oSalesOrderHeader.AddExistingSalesOrderLines()
	End If
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 = 2
If Not oSalesOrderHeader.EditExistingLineDetail(1, SalesOrderLineEditableProperty_OrderQuantity, "2") Then
	MsgBox oSDK.Status.userReadableDescription
    GoTo freeResources      
End If

4 – Save

Finally, save the amended order:

If oSalesOrderHeader.Save() = True Then
	MsgBox "Sales Order Number = " & oSalesOrderHeader.SalesOrderNumber
Else
	MsgBox oSDK.Status.userReadableDescription
	Exit Sub
End If