Demo

* Demo Program for ITRDS

* This program steps through some of the basic functions
* you may want to carry out using the ITRDS in order to get you started

* LOADING THE ITRDS OBJECT

* The ITRDS can be loaded using the following syntax

loITRDS = Createobject("ITRDS.RP_CLIENT")

* Of course the syntax will vary depending on the development language
* you are using but it will be similar.

* THE ITRDS OBJECT MODEL

* Once loaded the general structure of the ITRDS is as follows

* FOR Visual Rams
* loITRDS.OCUSTOMERS - Customer Table
* loITRDS.OPROFILEREXTRA - Profiler EXT_CUS (cleanaway specific)
* loITRDS.OCHARGES - Charge Table
* loITRDS.OROUTES - Routes Table
* loITRDS.OROUTE - Route Table
* loITRDS.OBATCH - Batch Table
* loITRDS.OBATCHLOG - BatchLog Table
* loITRDS.OINVOICES - Invoice Table
* loITRDS.OINVOICEMEMBERS - Transaction Table
* loITRDS.OCOMMENTS - Comments Table
* loITRDS.OWorkOrders - WorkOrdr Table
* loITRDS.OWorkOrdercomment - WorkOrdercomment Table
* loITRDS.OWorkOrderCharge - WorkOrderCharge Table
* loITRDS.OWorkOrderContainer - WorkOrderContainer Table
* loITRDS.OWorkOrderlog - WorkOrderlog Table
* loITRDS.OWorkOrderDateTime - WorkOrderDateTime Table
* loITRDS.OTABLE - General Table Object

* FOR Dos Rams
* loITRDS.OCUSTOMERS - Customer Table
* loITRDS.OPROFILEREXTRA - Profiler EXT_CUS (cleanaway specific)
* loITRDS.OCHARGES - Charge Table
* loITRDS.OROUTES - Routes Table
* loITRDS.OINVOICES - Invoice Table
* loITRDS.OINVOICEMEMBERS - Transaction Table
* loITRDS.OCOMMENTS - Comments Table
* loITRDS.OWORKORDERS - Workordr Table
* loITRDS.OTABLE - General Table Object


* Each one of these objects gives you access to the respective table.
* In additin to these objects there are two others which can be used
* to simplify data access. These are;

* loITRDS.OCONNECTIONS - Connections Table
* loITRDS.OSYSTEMS - Systems Table

* Currently it is compulsory that you use these objects and hence
* servers must be configured with all required settings for these.

* USING THE CONNECTION OBJECT

* The connection object is used to set the communication method to use when
* communicating with the Rams Pro system. Connections must be pre configured
* on the client using the client configuration tool.
* Once the connection is configured you simply issue the "SetConnection" command for the
* connection you want. In the below example the connection "LOCAL" has already
* been configured on the client.

lSuccess = loITRDS.SetConnection("LOCAL")

* This will return true if successful. If not it will return False and an
* error message can be found in the ErrorMsg property. For example the following
* will return an error;

lSuccess = loITRDS.SetConnection("INVALIDCODE")

* To view quickly in foxpro try
Wait Window lSuccess

* Load the correct connection again before continuing.

lSuccess = loITRDS.SetConnection("LOCAL")

* Now all properties required for communicating to this system are set. All
* you need to do is use the ITRDS as required. The connection settings will
* stay active until the ITRDS is unloaded or reset.

* SETTING A RAMS SYSTEM

* Once a connection is set you need to specify the Rams system you want to use
* on this connection. The systems available will be whatever has been setup
* on the server. To get avaliable systems you can use the LoadTable command
* as below;

lnRecords = loITRDS.osystem.LoadTable(,,,,31)

* This will load the table into a collection object for easy access.
* For example;

For ln = 1 to loITRDS.osystem.oRows.count
loRecord = loITRDS.osystem.oRows.Item[ln]
Wait WINDOW loRecord.Code
Wait WINDOW loRecord.Descript
EndFor


* Alternatively we could also have specified an XML result mode by specifiying a return
* coded of 1. This would then put an xml version of the table into the property
* cResultXML. You can view this via XML as follows;

lnRecords = loITRDS.osystem.LoadTable(,,,,1)

* Note that we could have used the query method as well however using the
* LoadTable method gets the ITRDS to load index information
* as well and hence by using the following method we can get an exact copy
* of the table including indexes.

* If you want to look at the format in your browser save this string to a file
* with the extension of XML abd then open using your browser. For example in
* FoxPro;

lcXML = loITRDS.osystem.cResultXML
strtofile(lcXML,"C:\ITRDS.XML")

* The paramter lcXML will now hold the xml version of avaialble systems. You can
* use the utility object "IT_DataConvert" to convert this to a local cursor. The
* following example shows this. NB you must have the "IT_DATACONVERT" class in the
* available class libraries for foxpro users.

loDataConvert = Createobject("IT_Dataconvert")
lGetIndexes = .t.
lSuccess = loDataconvert.xmlwithschematocursor(lcXML,"table",,lGetIndexes)

* This will create a cursor locally with indexes if there were any. To know
* the name of the cursor created it will be in the property;

lcSystemCursor = loITRDS.osystem.cLocalTableName

* This table will hold a list of all available Rams systems on this connection.
* To set a system for use issue the SetSystem command

lSuccess = loITRDS.SetSystem('6230')

* Now both connection and system are set you can read and write data to the system

* LOADING AN INDIVIDUAL RECORD

* To load an individual record from a table you use the Load command with the
* appropriate PK value. For example to load a customer;

llSuccess = loITRDS.OCUSTOMERS.Load("2744262")

* The return value will be either True for success or False for not found. The resulting
* record will be in oData and data can be accessed as follows;

lcBillingName = loITRDS.OCUSTOMERS.oData.Name

Wait Window lcBillingName

* If you want you can get an XML version of this by issuing the MakecData command as follows;

loITRDS.OCUSTOMERS.MakecData()
lcXML = loITRDS.OCUSTOMERS.cData

* then

strtofile(lcXML,"C:\ITRDS.XML")

* EDITING THE LOADED RECORD

* Once the record is loaded you can edit values in the object. For example say that you
* wanted to change the billing name, you would carry out the following;

llSuccess = loITRDS.OCUSTOMERS.Load("2744262")
lcNewBillingName = "Bill Harris"

loITRDS.OCUSTOMERS.ADDFIELDVALUE("Name",lcNewBillingName)

* YOU MUST USE THE ADDFIELDVALUE METHOD TO EDIT AND ADD VALUES! The reason
* for this is that the ADDFIELDVALUE method will ensure two things. First that the
* data type you are assigning is correct for the table. That is so that you don't
* assign numbers to character fields etc and secod it will format the data in the
* corrcet format. For example add leading spaces if required. By using the ADDFIELDVALUE
* method this logic is carried out on the client for quicker validation. As this may return
* an error you may want to check each time. For example the above code should read;

If not loITRDS.OCUSTOMERS.ADDFIELDVALUE("Name",lcNewBillingName)
* Error handling
EndIf

* To save this modification we need to issue the save command as follows;

lSuccess = loITRDS.OCUSTOMERS.Save()

* Again you should check for errors
If loITRDS.OCUSTOMERS.lError
* Error handling
EndIf

* CREATING NEW RECORDS

* To create a new record you need to issue the new command. For example to create
* a new work order

lSuccess = loITRDS.OWORKORDERS.New()

* This will place a blank object in oData and provide a valide PK value. All
* the user needs to do is populate the fields with values as follows;

If not loITRDS.OWORKORDERS.ADDFIELDVALUE("wo_type","S")
* Error
EndIf
If not loITRDS.OWORKORDERS.ADDFIELDVALUE("Level","1")
* Error
EndIf
If not loITRDS.OWORKORDERS.ADDFIELDVALUE("Department","OPS")
* Error
EndIf

* Then issue the save command
lSuccess = loITRDS.OWORKORDERS.Save()

* What will happen at the server is that each field will be validated. If one of the entered
* fields is not valid then an error will be issued. To get this error look at the property
* lError and the error message property cErrorMsg as follows;

If loITRDS.OWORKORDERS.lError
lcErrorMessage = loITRDS.OWORKORDERS.cErrorMsg
Wait Window lcErrorMessage
Endif

* QUERYING MULTIPLE RECORDS

* Another commonly used feature is being able to query multiple records from a table. For instance
* say that we want to pull all work orders for account "1234134". To do this we can use
* either the LoadTable command if we want indexes as well or simply the query command (reccomended).
* For example;

lnRecords = loITRDS.OWORKORDERS.query("select * where account = ' 1234134'",'',1)

* We can now retrieve the XML and if required convert to XML

lcXML = loITRDS.OWORKORDERS.cResultXML

loDataConvert = Createobject("IT_Dataconvert")

lSuccess = loDataconvert.xmlwithschematocursor(lcXML,"table")

* This will create a cursor called "TQUERY" with the records inserted.

* Alternatively to use the loadtable command;

lnRecords = loITRDS.OWORKORDERS.LoadTable("account = ' 1234134'")

* This will also query but with indexes. Hence we can create the table using;

lcXML = loITRDS.OWORKORDERS.cResultXML
lSuccess = loDataconvert.xmlwithschematocursor(lcXML)


* CUSTOMER PAYMENTS - ITRDS FOR VISUAL RAMS ONLY

* One of the most powereful features of the ITRDS is the ability to post payments against customers.
* This opens the a simple path for creating on line payment systems.
* In essence what this does is post an entry into a batch for the customer. This batch can be
* either a new batch or you can specify to find an unprocessed one if there or even specify the
* batch number. The following is an example of posting a payment.

loITRDS.oBatch.New()
loITRDS.oBatch.addfieldvalue("ACCOUNT","1234134")
loITRDS.oBatch.addfieldvalue("AMOUNT","100.34")
loITRDS.oBatch.addfieldvalue("CODE","PAYCOD")
loITRDS.oBatch.addfieldvalue("Date",{01/04/2004})
loITRDS.oBatch.lPosttofirstunprocessed = .t.
loITRDS.oBatch.cType = "P"
loITRDS.oBatch.Save()

* What this will do is as follows

* Find a "PAYMENT" batch (unprocessed) because the cType is set to "P";
* If possible it will find for the current user number
* IF not found then any user
* If still not found it will create a payment batch under the current user


* Then it will add this entry to the batch and validate all entries.
* Another way to do this is by specifying the batch number as follows

loITRDS.oBatch.New()
loITRDS.oBatch.addfieldvalue("ACCOUNT","1234134")
loITRDS.oBatch.addfieldvalue("AMOUNT","100.34")
loITRDS.oBatch.addfieldvalue("CODE","PAYCOD")
loITRDS.oBatch.addfieldvalue("Date",{01/04/2004})
loITRDS.oBatch.lPosttounprocessed = .t.
loITRDS.oBatch.cBatchNumber = "12121"

* This will simply add the entry to that batch. If the batch doesn't exist then
* an error will occur

* Thus if you wanted to write a routine for importing payments into batches it would look something
* like as follows

* First get the list of payemnts to be made. Here we assume that there is a foxpro
* cursor called "curPayments" which holds the list.

* First create a payment batch
loITRDS.oBatchLog.New()
loITRDS.oBatchLog.ADDFIELDVALUE("TYPE","PAYMENT")
loITRDS.oBatchLog.Save()

If loITRDS.oBatchlog.lError
* Handle error
EndIf

* Get the batch number
lcBatchNumber = loITRDS.oBatchLog.oData.Number

* Lock the batch
If not loITRDS.oBatchLog.LockBatch(lcBatchNumber)
* Handle error
EndIf

* Now go through the payemnts and save
Select "curPayments"
Go top
Scan
lcAccount = curPayments.Account
ldDate = Iif(Empty(curPayments.Date),Date(),curPayments.Date)
lcInvoice = curPayments.Invoice &&(note that if this is blank it will carry out the normal rules
&& to determine which invoice to post against or leave blank)
lnAmount = curPayments.Amount
lcPaymentServiceCode = "999900"

* Now place record
loITRDS.oBatch.New()
loITRDS.oBatch.addfieldvalue("ACCOUNT",lcAccount)
loITRDS.oBatch.addfieldvalue("UNITS",1)
loITRDS.oBatch.addfieldvalue("UNIT_AMOUNT",lnAmount)
loITRDS.oBatch.addfieldvalue("INVOICE",lcInvoice)
loITRDS.oBatch.addfieldvalue("CODE",lcPaymentServiceCode)
loITRDS.oBatch.addfieldvalue("DATE",ldDate)
loITRDS.oBatch.addfieldvalue("BATCH",lcBatchNumber)
* Once a batch is locked by the itrds you need to keep passing the lock code
loITRDS.oBatch.cBatchLockCode = loITRDS.oBatchLog.cBatchLockCode
llSuccess = loITRDS.oBatch.Save()
If NOT llSuccess
* Handle error. Don't forget to either delete or unlock the batch
Return .f.
EndIf
EndScan

* Unlock Batch
If not loITRDS.oBatchLog.UnLockBatch(lcBatchNumber)
* Handle error
EndIf


Last Updated: 20/05/2004