Below is described all the facilities available through the Interface object passed to the functions listed in How is the interface organised.

Useful Constants

m.yes = m.flag('Yes')
m.no = m.flag('No')
m.emptystr = m.str('')
m.null = m.void()
m.zero = m.real(0)

Interface:LoadDefaults(CusSup)

Load the customer or supplier specific defaults for the customer or supplier defined by CusSup.

Interface:UnLoadDefaults()

Un-load the last set of customer/supplier defaults loaded. This is automatic if the script terminates or returns.

v1,v2,…vN = Interface:GetProperties(p1,p2,…pN)

Get one or more properties associated with the accounts centre involved. The parameters p1,p2,…pN is an arbitrary list of property names to get. The results v1,v2,…vN will be the value of those properties, they are returned in the same order as they were requested.

Properties are either predefined as part of the accounts centre record (i.e. CSA fields) or user defined as qualfiers. Attempting to get a property that is not defined will cause a user dialog to be shown to define it.

Each property can be specified in one of three ways:

just as their name, e.g. 'version',

as a table with a field=value pair, e.g. {version=6},

as a table with name=field,value=expr, e.g. {name='version',value=6}

When a table is used, in either form, it can also have description=, validate= and ask= entries. If a value is given it defines a default value to use if the property has not got a value or is undefined. If a 'description' entry is given, it is used to describe the property if it is created due to it not being defined. If a 'validate' entry is given it is a function to call to validate the property. The function is given the current value as a parameter and must return nil if it is valid or a message describing what is wrong. If 'ask' is given and true, then the user is given a dialog to set the properties. The user is always asked to define property values that do not exist or are invalid.

f1,f2,…,fN = Interface:Open(mode,fn1,fn2,…fnN)

Open a set of files, either in isolation or in a transaction. mode is either 'r' (read) or 'w' (write), if mode is 'w' the files are opened in a transaction.

The file buffers are cleared and populated with defaults, so the caller can be sloppy.

fn1,fn2,…fnN specifies the files to be opened (e.g. m.csh, m.csc to open the customer/supplier file and the contacts file).

f1,f2,…fN are open file handles for the files requested. They are returned in the same order as requested.

Interface:Load(file,object,watch)

Like m.load but aborts on error (so you don't have to worry about catching errors).

CusSup = Interface:Add(type)

Add the CSH currently in the file buffer. The type specifies a customer (m.csTypeCustomer) or a supplier (m.csTypeSupplier) is being added. If no type is given, then the same as last time is used. If csh.CusSup in the file buffer clashes with an existing record, it will be changed to a non-clashing value.

It returns the CusSup created on success or aborts on failure.

Contact = Interface:AddCon(type,CusSup,rank,nodef)

Add the CSC currently in the file buffer and create a default contact unless directed not to (by setting nodef to true). If no type, CusSup or rank is given, then that of the last add/get/put is used.

It returns the Contact created on success, nil if the contact already exists or aborts on failure.

CusSup = Interface:Get(type,AccountRef)

Attempt to get a cus/sup account via the given AccountRef. Set type to m.csTypeCustomer to get a customer or m.csTypeSupplier to get a supplier.

It returns the CusSup found if it exists or nil if it doesn't.

Contact = Interface:GetCon(type,CusSup,rank)

Attempt to get a contact for the given CusSup via the given rank. Set type to m.csTypeCustomer to get a customer contact or m.csTypeSupplier to get a supplier contact. If no type, CusSup or rank is given, then that of the last add/get/put is used.

It returns the Contact if exists or nil if it doesn't.

CusSup = Interface:Put()

Put the current CSH file buffer into the file.It returns the CusSup on success or aborts on failure.

Contact = Interface:PutCon()

Put the current CSC file buffer into the file.

It returns the Contact on success or aborts on failure.

Interface:Close()

Close all files and transactions previously opened with Interface:Open.

If a transaction is closed and it fails, the script aborts.

String = Interface:Join(lines)

Joins strings together as lines with trailing spaces clipped.

lines is a table containing the strings to be joined. Each entry is concatenated with the previous with a newline sequence. Trailing spaces from each entry are removed.

ExportTable = Interface:NewExportTable(Name,Description,Separator)

Create a new table to be exported. This creates an object with name 'Name' to encapsulate the information to be exported. The 'Description' is purely for documentation purposes. The ‘Separator’ specifies the field separator character to be used in the output CSV file. If omitted, the default is a comma. It should be a single character.

The object created here implements various helper functions for use by the interface specific code. A property in the interface of the table name must exist, and be populated, that is a PathNam unless the given table name starts with '@' in which case it's interpreted as the file name itself.

If the interface table name property does not exist, the user is asked to define it (see Interface:GetProperties).

See Export Table Reference, for the functions available through this object.

ImportTable = Interface:NewImportTable(Name,Description)

Create a new table to be imported. This creates an object with name 'Name' to encapsulate the control of the import process. The 'Description' is purely for documentation purposes.

The object created here implements various helper functions for use by the interface specific code. A property in the interface of the table name must exist, and be populated, that is a PathNam unless the given table name starts with '@' in which case it's interpreted as the file name itself.

If the interface table name property does not exist, the user is asked to defined it (see Interface:GetProperties).

See Import Table Reference, for the functions available through this object.