Edit

UpdateOrderLines (orderSeq, prod_qty_array [, linktoInvSeq])

Return type:  a status code, and the array is modified

Definition:  Use this function to programmatically process an order for which you have imported or otherwise created a corresponding invoice, or to just update intended ship quantities (this latter use would only be for Sales Orders where you want to programmatically allocate new stock to backorders).

Identify the order to be updated by specifying its sequence number in orderSeq.

Pass an associative array of quantities, where the array keys are product codes.

Optionally pass the sequence number of a posted invoice that SHOULD correspond to the products/quantities being updated (however, agreement with the invoice is not enforced).

If you pass an invoice sequence number, the order lines will have the specified quantities transferred from backordered to previously shipped. In the event that all lines on the order are completed, the order will be marked as complete. The invoice will be updated to link back to the order (via the originatingOrderSeq field). See also special cases below.

If no invoice sequence is specified, the function will just update the Ship Qty column, and the order can then be processed manually.

The prod_qty_array quantities will be adjusted downward by the quantity "used" by the order. If the quantity specified is greater than the backorder quantity for the product on the order, the remaining quantity will be left in the array. Otherwise the used element will be deleted from the array when its quantity is fully "used". Array elements whose key does not match an ordered product on the order will be ignored. Thus on exit, the array will contain unprocessed products/quantities. This means in the simple case (no invoice sequence) you could pass the same array of newly received stock quantities to subsequent invocations for a series of orders, and the stock will be allocated in the order the orders are processed, until it is depleted.

Special cases for linktoInvSeq:

  • If the order is completed (i.e. there remain no backordered items), and the linktoInvSeq is specified as -1, the order will be marked as completed (so will appear in the Bought/Sold list).
  • Set the linktoInvSeq to -2 to force the order to be completed.

The function will return 0 on successful completion. If there is an error, a non-zero status will be returned. Further information on the error can be obtained from GetLastErrorMessage().

Availability:  available within MWScript handlers in MoneyWorks 9 and later