Plugins Programmers Guide

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

Retail Pro 8 Series

Plugins Programmers Guide

Retail Pro 3252 Holiday Court La Jolla, CA 92037 USA USA 1-800-738-2457 International +1-858-550-3355 www.retailpro.com

Retail Pro 8 Plugins Programmers Guide

About this Guide


This document explains how to program plugins to work with Retail Pro. If you believe the information presented here is incomplete or inaccurate, we encourage you to contact us at emanuals@retailpro.com.

The software described herein is furnished under a license agreement. Retail Pro 3252 Holiday Court La Jolla, CA 92037 USA USA 1-800-738-2457) International +1-858-550-3355 www.retailpro.com

Copyright Copyright 2008 Intuit, Inc. All rights reserved. Redistributed by Retail Pro under license. Retail Pro 3252 Holiday Court La Jolla, CA 92037 U.S.A. Trademarks Retail Pro and the Retail Pro logo are registered trademarks and/or registered service marks in the United States and other countries. Oracle and Oracle 9i are registered trademarks and/or registered service marks of Oracle Corporation. All rights reserved. Other parties trademarks or service marks are the property of their respective owners and should be treated as such.

Copyright 2008 Retail Pro. All rights reserved. ii

Retail Pro 8 Plugins Programmers Guide

Table of Contents
About this Guide ................................................................................................................. ii Introduction..........................................................................................................................2 Environment.........................................................................................................................3 Running Retail Pro With Plugins...................................................................................3 Version........................................................................................................................ 3 Files............................................................................................................................. 3 Directory Structure.........................................................................................................3 Development Environment ..................................................................................................4 What You Need..............................................................................................................4 Setting Up Your Development Environment.................................................................4 Install and set up Delphi ............................................................................................. 4 Install and Register RDA2 .......................................................................................... 4 Make Packages Available to Delphi ........................................................................... 5 Anatomy of a Plugin ............................................................................................................6 Overview........................................................................................................................6 The Package File............................................................................................................6 Common Methods..........................................................................................................7 Initialize Method......................................................................................................... 7 Table Method .............................................................................................................. 8 The TRProApp Class .....................................................................................................9 CreateTableByID Method........................................................................................... 9 4.4.2 Preferences Method ........................................................................................... 9 Print Method ............................................................................................................. 10 Base Classes in Detail..................................................................................................11 TValidate................................................................................................................... 11 TAfterAssign............................................................................................................. 13 TOnUpdate................................................................................................................ 14 TItemAddRemove..................................................................................................... 15 TSideButton .............................................................................................................. 17 TTenderChanged....................................................................................................... 19 TCustomField ........................................................................................................... 21 TOnPrint ................................................................................................................... 24 Creating a Plugin................................................................................................................26 Create a New Package Project .....................................................................................26 Add the plugin design-time packages to your code .................................................. 26 Create a plugin class ................................................................................................. 27 Select table for the plugin ......................................................................................... 27 Export the plugin class.............................................................................................. 27
Copyright 2008 Retail Pro. All rights reserved. iii

Retail Pro 8 Plugins Programmers Guide

Compile the plugin package...................................................................................... 27 Appendix A Retail Pro API Code...................................................................................28 Appendix B Example Code Listing ................................................................................30 Invoice Item Change ....................................................................................................30 InvoiceItemChange.dpk ............................................................................................ 30 uInvoiceItemChange.pas........................................................................................... 30 PrintInvoice..................................................................................................................33 PrintInvoice.dpk........................................................................................................ 33 uPrintInvoice............................................................................................................. 33 InvoiceButton...............................................................................................................35 InvoiceButton.dpk..................................................................................................... 35 uInvoiceButton.pas ................................................................................................... 35 InvoiceField .................................................................................................................38 InvoiceField.dpk ....................................................................................................... 38 uInvoiceField.pas ...................................................................................................... 39

Copyright 2008 Retail Pro. All rights reserved. iv

Retail Pro 8 Plugins Programmers Guide

Introduction
Retail Pro 8 Series enables you to use custom plugins to improve functionality and usability of Retail Pro. Plugins for Retail Pro 8 Series are comparable to custom dynamic link libraries (DLLs) for version 7. Custom plugins can be obtained by contacting the Custom Programming department. However, since the plugin API is open, anyone with sufficient knowledge of Delphi programming and Retail Pro can create plugins. This document gives an overview of how to set up the development environment and create custom plugins. Before you start programming plugins, you should be familiar with the following subjects:

Delphi Plugins must be written in Borlands Delphi IDE. Object Oriented Programming Retail Data Access (RDA2) Retail Pros data is made available to the plugins through RDA2. A thorough understanding of RDA2 and its object model is necessary. Reference: RDA2 Programming Guide. Retail Pro 8 Series

Copyright 2008 Retail Pro. All rights reserved. 2

Retail Pro 8 Plugins Programmers Guide

Environment
Running Retail Pro With Plugins
Version
You must have Retail Pro version 8.22 or later to use plugins. New plug-in classes become available from time to time. Tto ensure complete compatibility with Retail Pro, always use the latest Retail Pro files.

Files
The files are located in the base level of the Retail Pro installation (i.e. the same level you will find RPro8.exe, typically \Retail).

RPro8.exe Version 8.22 or above. RDA2.dll RPRO_API.bpl ms_ie_d5.bpl vcl50.bpl vclie50.bpl

Directory Structure
Add a directory called \plugins to the base of the Retail Pro directory tree (Example: \Retail\Plugins). Retail Pro will only find and use plugin packages in this directory.

Copyright 2008 Retail Pro. All rights reserved. 3

Retail Pro 8 Plugins Programmers Guide

Development Environment
Important: Sometimes when you open the Delphi package project files (.dpk) mentioned here, the following message displays: This package appears to be in an older format. Would you like to convert it to the new format?. You should always select No if you see this message.

What You Need


Borlands Delphi 5 Main development environment. RDA2 Retail Data Access version 2; a COM object library from RTI (RDA2.DLL). RPRO_API.dpk and RproAPI.pas Package and source code for the Retail Pro API. ms_ie_d5.bpl and .dcp Other run and design-time packages needed.

Setting Up Your Development Environment


Install and set up Delphi
See product documentation from Borland for instructions on how to install Delphi.

Install and Register RDA2


1. Copy the file to a local directory on your computer, for example: C:\Retail\RPro\. Note: The RDA2.dll is automatically installed in the \Retail\RPro folder when you install Retail Pro. RDA2.dll updates are provided in the Retail Pro update zip files. If the RDA2.dll is already installed on your system, you will still need to register it: 2. Run the regsvr32 program on the rda2.dll from a command prompt: Regsvr32 C:\Retail\RPro\Rda2\RDA2.dll 3. Start Delphi and import the RDA2 type library. To do this click on Projects->Import Type Library on Delphis main menu. Select the RDA2 Library (Version x.x) from the list of available libraries. Make sure the box Generate Component Wrapper is un-checked and click on Create Unit. This generates the file RDA2_TLB.pas which contains Delphi-stubs for the methods contained in the RDA2.dll. Note: You should repeat this step whenever you upgrade the rda2.dll. Copyright 2008 Retail Pro. All rights reserved. 4

Retail Pro 8 Plugins Programmers Guide

Make Packages Available to Delphi


The run and design time packages must be available to Delphi in order to compile Retail Pro plugins. This can be done in several ways: For ms_ie_d5: 1. Copy the ms_ie_d5 .bpl and .dcp files into the Delphi Bpl directory. Typically C:\Program Files\Borland\Delphi5\Projects\Bpl.

Or
1. Copy the files to another location and add that directory to Delphis search path. The Search path is set through Project->Options->Directories/Conditionals.

For RPRO_API: 1. Open the file RPRO_API.dpk in Delphi. This should bring up the Package dialog. NOTE: sometimes the Package dialog may be hidden behind other Delphi windows (such as the code window), minimize these windows to find the package dialog. 2. Click the Install button on the package dialog window. This will compile the RPRO_API and place the results in Delphis search path. 3. Note: To be sure you compile your plugins against the same version of the RPRO_API as Retail Pro uses to run it you should find the RPRO_API.bpl file you just compilednormally located in C:\Program Files\Borland\Delphi5\Projects\bpl directoryto the base directory of your Retail Pro installation (the same directory in which you will find RPro8.exe, for example C:\Retail).

Copyright 2008 Retail Pro. All rights reserved. 5

Retail Pro 8 Plugins Programmers Guide

Anatomy of a Plugin
Overview
A plug-in is a special class contained in compiled Delphi-package (.BPL) files. There can be one or more plug-in classes in a package file. All plug-in classes must be derived from one of the abstract base classes in the Retail Pro API (RProAPI) unit. Currently the following base classes are defined in the Retail Pro API: TValidate Catches input before it is assigned to a field in Retail Pro. TAfterAssign Is invoked after the user assigns a new value to a field. TOnUpdate Is triggered when a document is saved to disk. TItemAddRemove Is triggered when an item is added or removed from a document. TSideButton Is used to add a custom button to a context (side) menu. TTenderChanged Is called when the tender screen is entered or tender information is changed. TCustomField Add a custom field to a Retail Pro screen. TOnPrint Can be used to add custom information to a printed receipt or other document. Plugins typically have two kinds of methods: setup methods (prepares the plugin for work and tells Retail Pro when to call it), and event methods (called by Retail Pro when a certain event happens).

The Package File


The package file is created as a regular Delphi package. After compilation, the resulting .bpl file is the only file that needs to be distributed to the users of that plugin (assuming their Retail Pro environment is set up for plugins). As mentioned, a package file can contain one or more plugin classes, to tell Retail Pro what classes are available; the package exports the function RproClassesAvaliable.
procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc); begin RProClassArrayProc([TMyRProPlugin]); end; exports RProClassesAvailable;

This function has one argument of type TRProClassArrayProc in which you specify which classes your package contains. In the above example the package contains one plugin class called TMyRProPlugin.

Copyright 2008 Retail Pro. All rights reserved. 6

Retail Pro 8 Plugins Programmers Guide

Common Methods
All base classes have common setup methods that must be implemented in each plugin derived from it.

Initialize Method
The Initialize method is common to all base classes.
Initialize Description procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; This procedure is called when Retail Pro loads and instantiates this plugin. When this is done depends on what table is specified for the plugin in the Table function. This is a reference from Retail Pro to an object of type TRProAPP (also defined in the RProAPI unit). This object provides access to the root of the RDA2 data to the plugin. TRProAPPs single method CreateTableByID is the same as that of the IRdaDB interface and can be used to access any table without having to create a new instance of RDA2. An IRdaDocument object that will point to the current document. The document is of the type appropriate for the table you specified in the table function. Note that the plugin only get a reference to the document in the Initialize function. The reference must be kept by the plugin and will automatically be updated to always point to the document for which the plugins functions are called. Preconditions None.

RProApp

Doc

Post Conditions The plugin class is instantiated and ready for its other methods to be called. Comments Use of constructors in plugins is not reliable and is not recommended. Any construction code should be put in this method. There is no corresponding de-initialize function in the base classes. A regular destructor can be added to the plugin if necessary, but do not forget to call inherited from within it.

Copyright 2008 Retail Pro. All rights reserved. 7

Retail Pro 8 Plugins Programmers Guide

Table Method
The Table method is common to all classes except the TSideButton class.
Table Description class function Table: integer; virtual; abstract; Since the base classes are generic and can work on any table or nested document, a plugin must implement the Table function to tell Retail Pro what specific table this plugin will work on. The function must return an integer value that is the RDA2 table ID, or nested document ID. This is a class function it may, and will, be called by Retail Pro before any objects of the class has been instantiated. You cannot reference any regular members from a class function.

Return Value Preconditions

Post conditions None. Comments Note that even though you can specify a plugin should be called for any Retail Pro table, not all plugin types are appropriate for all tables. What tables a plugin is valid for is listed in each base class detailed description below.

Copyright 2008 Retail Pro. All rights reserved. 8

Retail Pro 8 Plugins Programmers Guide

The TRProApp Class


TRProApp = class function CreateTableByID(TableID: Integer): IRdaTable; virtual; abstract; function Preferences: IXMLDOMDocument; virtual; abstract; procedure Print(const DesignName, PrinterName: string; SuppressPrinterDialog: boolean); virtual; abstract; end;

A reference to a TRProApp object is provided by Retail Pro in the Initialize method of the plugin classes that it loads. The TRPRoAPP object is the link to Retail Pro functions and data other than the document that the plugin works directly on (which is usually supplied in the Doc parameter of the Initialize method). The TRProApp makes it possible to access other Retail Pro information through its methods.

CreateTableByID Method
This method is the same as the method with the same name in the IRdaDB interface of RDA2. Refer to the RDA2 documentation for more information.
CreateTableByID Description TableID Return Value function CreateTableByID(TableID: Integer): IRdaTable; virtual; abstract; The CreateTableByID method can return a IRdaTable reference to any table accessible by RDA2. An integer that corresponds to the field IDs set up in RDA2. An IRdaTable reference to the RDA table given by the TableID.

4.4.2 Preferences Method


This method is the same as the method with the same name in the IRdaDB interface of RDA2. Refer to the RDA2 documentation for more information.
Preferences Description function Preferences: IXMLDOMDocument; virtual; abstract; This method gives you some access to the Retail Pro preferences from within a plugin. Not that all preferences are not accessible, and the ones that are, are mostly read-only. See the RDA documentation for information and examples of the XML preferences. An XML DOM Document object that holds information about the current Retail Pro preferences.

Return Value

Copyright 2008 Retail Pro. All rights reserved. 9

Retail Pro 8 Plugins Programmers Guide

Print Method
Print Description procedure Print(const DesignName, PrinterName: string; SuppressPrinterDialog: boolean); virtual; abstract; This function can be called from within a plugin to force printing of the current document. Use the TOnPrint plugin to intercept and modify the information to be printed if necessary. A string containing the design name to be printed, if an empty string is given, Retail Pro will display the Design Selection dialog before printing. A string containing the printer name of the destination printer. If the printer dialog is displayed, it will default to this printer. If this value is set to true the printer dialog will not be displayed. The print job will be sent to the printer given by PrinterName, if that is not set the default system printer will be used.

DesignName PrinterName

SuppressPrinterDialog

Copyright 2008 Retail Pro. All rights reserved. 10

Retail Pro 8 Plugins Programmers Guide

Base Classes in Detail


TValidate
TValidate = class class function Table: integer; virtual; abstract; class function Field: integer; virtual; abstract; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; function Validate(var Value: variant): boolean; virtual; abstract; end;

With the TValidate plugin class you can make plugins that can capture input and validate it before it reaches Retail Pro. This class can be used on any table or nested document. Field Method

In addition to the Table method this class has another initialization method called Field:
Validate Description Field class function Field: integer; virtual; abstract; Use this function to tell Retail Pro for which field you want to trap the input. An integer that corresponds to the field IDs set up in RDA2. Retail Pro will call the Validate function for all input destined for the field whos ID is returned by this function. Retail Pro must have called Initialize on this class before this method can be invoked.

Preconditions

Post conditions None. Comments This method is only called when a field is updated by a manual entry, not internally by Retail Pro itself.

Copyright 2008 Retail Pro. All rights reserved. 11

Retail Pro 8 Plugins Programmers Guide Validate Event Method


Validate Description function Validate(var Value: variant): boolean; virtual; abstract; This class only has one event-method. It is called before the value of any field in the selected table (or nested document) is updated. Note: the Doc reference obtained in the Initialize procedure will always point to the current document. Value Return Value A variant that holds the new value proposed for the field. If the function returns the Boolean value True, the value in the Value parameter will be assigned to the Retail Pro field. (Note that Retail Pro also does its own input validation and not all values might be accepted). If return value is False, the input operation will be cancelled and the field will keep its previous value. Retail Pro must have called Initialize on this class before this method can be invoked.

Preconditions

Post conditions The Return Value must hold a valid Boolean value. Comments This method is only called when a field is updated by a manual entry, not internally by Retail Pro itself.

Copyright 2008 Retail Pro. All rights reserved. 12

Retail Pro 8 Plugins Programmers Guide

TAfterAssign
TAfterAssign = class class function Table: integer; virtual; abstract; procedure Initialize (RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; procedure Execute(const FieldID: integer); virtual; abstract; end;

Plugins derived from this class will be able to act on a change in any field of the selected table or nested document. Its Execute function will be called after a new value is assigned to any field. This class can be used on any table or nested document.

Execute Event Method


Execute Description procedure Execute(const FieldID: integer); virtual; abstract; This class only has one event-method. It is called when the value of any field in the selected table (or nested document) is updated. Note: to get the particular document that was updated use the Doc reference obtained in the Initialize procedure. It will always point to the current document. FieldID Preconditions An integer holding the RDA2 field ID of the field that was updated. Retail Pro must have called Initialize on this class before this method can be invoked.

Post Conditions None. Comments This method is only called when a field is updated by a manual entry, not internally by Retail Pro itself.

Copyright 2008 Retail Pro. All rights reserved. 13

Retail Pro 8 Plugins Programmers Guide

TOnUpdate
TOnUpdate = class class function Table: integer; virtual; abstract; procedure Initialize (RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; function BeforeUpdate: boolean; virtual; abstract; procedure AfterUpdate; virtual; abstract; end;

Plugins based on this class will be called when a document is saved to disk (for example when an invoice is printed (or updated). OnUpdate plugins should only be used for tables; using it on a nested document may yield unpredictable results and cause lock-up of Retail Pro. BeforeUpdate Event Method
BeforeUpdate Description function BeforeUpdate: boolean; virtual; abstract; Like the name implies, the BeforeUpdate function is called right before a document of the selected table is updated. From the plugin it can be decided whether the document should actually be updated or not. A Boolean value. Return True if Retail Pro is allowed to update the document. If the returned value is False, Retail Pro will go back to where it was before the update event was triggered. Retail Pro must have called Initialize on this class before this method can be invoked. The Doc reference is pointing to the document about to be updated.

Return Value

Preconditions

Post Conditions Return value is a valid Boolean value.

AfterUpdate Event Method


AfterUpdate Description Preconditions procedure AfterUpdate; virtual; abstract; This procedure is called by Retail Pro right after a document of the selected table has been saved. Retail Pro must have called Initialize on this class before this method can be invoked. The Doc reference is pointing to the document that was just updated.

Post conditions None

Copyright 2008 Retail Pro. All rights reserved. 14

Retail Pro 8 Plugins Programmers Guide

TItemAddRemove
TItemAddRemove = class class function Table: integer; virtual; abstract; procedure Initialize (RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; function ItemBeforeRemove: boolean; virtual; abstract; function ItemBeforeAdd(ItemNo: integer): boolean; virtual; abstract; procedure ItemAfterAdd; virtual; abstract; end;

This class is used to create plugins that are aware of when items (nested documents) are added or removed from a document. This plugin class is valid for all tables that can have items as nested documents (Invoices, SOs, POs, etc.). The return value of the Table function should be the ID of the RDA2 table whose documents nested document adding and removing you want to trap. For example, if you want a plugin to be called whenever an item is added to, or removed from, an invoice, the plugins Table function should return the ID number of the Invoice table. Note that the Doc reference received in the Initialize still points to the current document in the selected table (the document which is having nested documents added or removed). To access the nested document which is being added or removed use the NestedDocByID or NestedDocByName methods of the Doc reference. ItemBeforeRemove Event Method
ItemBeforeRemove function ItemBeforeRemove: boolean; virtual; abstract; Description Return Value Preconditions This function is called right before an item is to be removed. The plugin can decide whether to allow it being removed or not. Returning the Boolean value True will allow Retail Pro to remove this item. The value False will force Retail Pro to keep the item. Retail Pro must have called Initialize on this class before this method can be invoked. There must be at east one item (nested document) added to the current document.

Post Conditions Return value is a valid Boolean value.

ItemBeforeAdd Event Method


ItemBeforeAdd function ItemBeforeAdd(ItemNo: integer): boolean; virtual; abstract; Description ItemNo This function is called right before an item is to be added. The plugin can decide whether to allow Retail Pro to add it or not. This is the Retail Pro item number of the item that is about to be added.

Copyright 2008 Retail Pro. All rights reserved. 15

Retail Pro 8 Plugins Programmers Guide


Return Value Preconditions If the function returns True, Retail Pro will add the item, if False the item will be discarded. Retail Pro must have called Initialize on this class before this method can be invoked.

Post Conditions Return value is a valid Boolean value. Comments Since this is called before the item (nested document) is actually added to the document there is not a valid IRdaDocument representation of the item.

ItemAfterAdd Event Method


ItemAfterAdd Description Preconditions procedure ItemAfterAdd; virtual; abstract; This is called immediately after an item (nested document) has been added to a document in the selected table. Retail Pro must have called Initialize on this class before this method can be invoked.

Post Conditions None. Comments Even though this method is called when the item has already been added, some fields (for example Qty, P$, and C$) may not yet have been updated if the quantity of the added item is larger than one.

Copyright 2008 Retail Pro. All rights reserved. 16

Retail Pro 8 Plugins Programmers Guide

TSideButton
TSideButton = class class function Menu: TSideMenu; virtual; abstract; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; class function Caption: string; virtual; abstract; class function PictureFileName: string; virtual; abstract; function Execute: TActionRequestSet; virtual; abstract; function Enabled: boolean; virtual; abstract; end;

This plugin enables you to add a custom button to a context (side) menu in Retail Pro. In addition to the Initialize method, this class has four other initialization methods: Menu, Caption, PictureFileName, and Enabled. Menu Method
Menu Description Return Value class function Menu: TSideMenu; virtual; abstract; This function controls to which context menu the button should be added. A value of type TSideMenu that tells Retail Pro to which menu the button should be added. Currently the following values are possible: smDepartments smVendors smCustomers smInventory smReceipts smReceiptList smVouchers smVoucherList smMemos smMemoList smSlip smSlipList smSO smSOList smPO smPOList smTO smTOList smTender Note: for screens where Form view and List view have different menus there are TSideMenu types for both menus respectively. For example, smRecipts corresponds to the menu for Receipts in Form view, and smReceiptList to the menu for Receipts in List view. Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

Post conditions Return value is a TSideMenu value.

Copyright 2008 Retail Pro. All rights reserved. 17

Retail Pro 8 Plugins Programmers Guide Caption Method


Caption Description Return Value Preconditions class function Caption: string; virtual; abstract; This function tells Retail Pro what the caption of the custom button should be. Return the desired Caption for the button as a string. Retail Pro must have called Initialize on this class before this method can be invoked. There must be at east one item (nested document) added to the current document.

Post conditions Return value is a valid string.

PictureFileName Method
PictureFileName class function PictureFileName: string; virtual; abstract Description Return Value Use this function to add a bitmap (.bmp) to the custom button. Return the desired filename of the bitmap for the button as a string. If no path is given Retail Pro will look for the bitmap in the /Plugins directory. Retail Pro must have called Initialize on this class before this method can be invoked. There must be at east one item (nested document) added to the current document.

Preconditions

Post conditions Return value is a valid string pointing to a valid bitmap file.

Enabled Method
Enabled Description function Enabled: boolean; virtual; abstract; Tells Retail Pro whether the button is enabled or disabled (grayed out). Retail Pro calls this function periodically when it is idle so unlike the other properties of the button (Caption, Bitmap) Enabled can be changed at any time during execution. Return True for the button to be enabled, False for disabled. Retail Pro must have called Initialize on this class before this method can be invoked. There must be at east one item (nested document) added to the current document.

Return Value Preconditions

Post conditions Return value is a valid Boolean value.

Copyright 2008 Retail Pro. All rights reserved. 18

Retail Pro 8 Plugins Programmers Guide Execute Event Method


Execute Description Return Value function Execute: TActionRequestSet; virtual; abstract; This function is called from Retail Pro when the user clicked the custom button. The return value is of type TactionRequestSet, currently the options in this set are: arRefreshDocument arRefreshList The return value forces Retail Pro to update the view of the current document or list to make sure any changes made during the execute method are displayed. Return arRefreshList if your button is on a list menu, and arRefreshDocument if your button is on a regular menu. Preconditions Retail Pro must have called Initialize on this class before this method can be invoked. There must be at east one item (nested document) added to the current document.

Post conditions Return value is a valid TactionRequestSet value.

TTenderChanged
TTenderChanged = class procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; procedure TenderScreenEntered; virtual; abstract; procedure Changed; virtual; abstract; end;

The TTenderChanged plugin allows you to trap when the tender screen is entered and when the tender information is changed (for example when a tender line is added or deleted to the tender screen). This class has two event methods: TenderScreenEntered and Changed. TenderScreenEntered Event Method
TenderScreenEntered Description Preconditions procedure TenderScreenEntered; virtual; abstract;

Is called by Retail Pro whenever the user enters the Tender screen, for example when tendering a new invoice. Retail Pro must have called Initialize on this class before this method can be invoked.

Post conditions None.

Copyright 2008 Retail Pro. All rights reserved. 19

Retail Pro 8 Plugins Programmers Guide Changed Event Method


Changed Description Preconditions procedure Changed; virtual; abstract; Is called by Retail Pro whenever the user changes the information on the tender screen. When a tender line is added or deleted. Retail Pro must have called Initialize on this class before this method can be invoked.

Post conditions None.

Copyright 2008 Retail Pro. All rights reserved. 20

Retail Pro 8 Plugins Programmers Guide

TCustomField
TCustomField = class class function Table: integer; virtual; abstract; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; class function FieldType: TCustomFieldType; virtual; abstract; class function FieldLabel: string; virtual; abstract; class function FieldDescription: string; virtual; abstract; function MaxChars: integer; virtual; abstract; // 0 for unlimited function IsReadOnly: boolean; virtual; abstract; function GetData: variant; virtual; abstract; procedure SetData(Value: variant); virtual; abstract; function LookupList: string; virtual; abstract; end;

With this plugin you can add a custom field to a Retail Pro screen, for example an invoice. It can be used on both regular and nested documents. The value of the field is not stored in the Retail Pro database so it is up to the plugin itself to save and retrieve values and associate them with the correct document if necessary. Along with Initialize and Table this plugin class has 8 setup related methods: FieldType, FieldLabel, FieldDescription, MaxChars, IsReadOnly, and LookupList. The event methods are GetData and SetData. FieldType Method
FieldType Description Return Value class function FieldType: TCustomFieldType; virtual; abstract; Tells Retail Pro what type of field this is so it can be formatted correctly on screen. Return a value of the type TCustomFieldType. This type can have the following values are possible: cftString cftInteger cftDouble cftQuantity cftCurrency cftDate cftTime cftDateTime This is a class function it may, and will, be called by Retail Pro before any objects of the class has been instantiated. You cannot reference any regular members from this function.

Preconditions

Post conditions The return value is a valid TCustomFieldType Value.

Copyright 2008 Retail Pro. All rights reserved. 21

Retail Pro 8 Plugins Programmers Guide FieldLabel Method


FieldLabel Description Return Value Preconditions class function FieldLabel: string; virtual; abstract; Tells Retail Pro what the label to display for the field. Return a string value containing the desired label. This is a class function it may, and will, be called by Retail Pro before any objects of the class has been instantiated. You cannot reference any regular members from this function.

Post conditions The return value is a valid, non-empty string.

FieldDescription Method
FieldDescription class function FieldDescription: string; virtual; abstract; Description Tells Retail Pro what the description is for the field. The description is displayed in the Tool Tips window when the cursor is placed over the field for a specified amount of time. Return a string value containing the desired description. This is a class function it may, and will, be called by Retail Pro before any objects of the class has been instantiated. You cannot reference any regular members from this function.

Return Value Preconditions

Post conditions The return value is a valid string.

MaxChars Method
MaxChars Description Return Value Preconditions function MaxChars: integer; virtual; abstract; Sets the maximum number of characters that retail pro will allow to be entered in the custom field. Return an integer value representing the maximum number of characters. Return zero to set an unlimited field length. Retail Pro must have called Initialize on this class before this method can be invoked.

Post conditions The return value is a valid integer value.

Copyright 2008 Retail Pro. All rights reserved. 22

Retail Pro 8 Plugins Programmers Guide IsReadOnly Method


IsReadOnly Description Return Value Preconditions function IsReadOnly: boolean; virtual; abstract; If this function is set to true, Retail Pro will not allow the user to edit this field. Return an bolean value of true to disallow editing of the field. Retail Pro must have called Initialize on this class before this method can be invoked.

Post conditions The return value is a valid boolean value.

LookupList Method
LookupList Description Return Value function LookupList: string; virtual; abstract; If you want to have certain pre-selected values available for the field through a drop down list, you can set up the list of values with this function. Return a string of comma-separated values that you want to appear in the drop down list. If an empty string is returned there will be no drop down list for the field. Retail Pro must have called Initialize on this class before this method can be invoked.

Preconditions

Post conditions The return value is a valid string value.

GetData Event Method


GetData Description function GetData: variant; virtual; abstract; This function is called when Retail Pro is going to display the content of the custom field. This function supplies the value that should be displayed to Retail Pro. Return a variant type with the value that Retail Pro should display. Retail Pro must have called Initialize on this class before this method can be invoked.

Return Value Preconditions

Post conditions The return value is a valid variant value with a variant type that can be converted and displayed according to the FieldType.

Copyright 2008 Retail Pro. All rights reserved. 23

Retail Pro 8 Plugins Programmers Guide SetData Event Method


SetData Description procedure SetData(Value: variant); virtual; abstract; This function is called when Retail Pro is going to set the value of the custom field. I.e. when the user has entered a new value for the field. Note that the new value must not necessarily be saved; Retail Pro will call GetData immediately after this method is finished so if the new value is not saved (for example because it did not pass validation) the old value will overwrite the new value. This method will never be called if the field is set to read-only. A parameter of variant type that contains the new value that the user entered/selected. Retail Pro must have called Initialize on this class before this method can be invoked.

Value Preconditions

Post conditions None.

TOnPrint
TOnPrint = class class function Table: integer; virtual; abstract; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; procedure BeforePrint(XMLDoc: IXMLDOMDocument); virtual; abstract; procedure AfterPrint; virtual; abstract; end;

The TOnPrint class can be used to intercept when a document is about to be printed or after it is printed. With the BeforePrint method it is possible to change the information that will be printed. See the RTI document titled V8 Custom Documents for information about how to process the Document Printer XML to print custom documents. BeforePrint Event Method
BeforePrint Description XMLDoc procedure BeforePrint(XMLDoc: IXMLDOMDocument); virtual; abstract; Called just before a document is printed. A XML DOM Document containing the information that will be sent to the Document Printer. This information may be modified to produce a customized print out. If nothing is changed in the XMLDoc, the document will be printed in normal fashion. Retail Pro must have called Initialize on this class before this method can be invoked. The XMLDoc parameter references a valid XML Dom Document object containing the document information to be printed.

Preconditions

Post conditions The XMLDoc parameter references a valid XML Dom Document object containing the document information to be printed.

Copyright 2008 Retail Pro. All rights reserved. 24

Retail Pro 8 Plugins Programmers Guide AfterPrint Event Method


AfterPrint Description Preconditions procedure AfterPrint; virtual; abstract; Called just after a document is printed. Retail Pro must have called Initialize on this class before this method can be invoked.

Post conditions None.

TTaxRate
TTaxRate = class procedure Initialize(RProApp: TRProApp); virtual; abstract; function GetTaxRate(TaxCode: integer; const TaxArea: string; Price: double; Quantity: double; var DoStandardTax: boolean): double; virtual; abstract;

GetTaxRate Event Method


GetTaxRate Return Value Description TaxCode TaxArea Price Quantity function GetTaxRate(TaxCode: integer; const TaxArea: string; Price: double; Quantity: double; var DoStandardTax: boolean): double; virtual; abstract The tax percentage to be used for the item. 2.5% = 2.5 (not .025) Called any time Retail Pro calculates tax for a line item. For example, adding an item to a receipt, changing price, changing quantity, etc. The Tax Code assigned to the item. (This is the integer value of the Tax Code, not the string description as seen in Preferences). The TaxArea assigned to the item. The unit price of the item. The quantity of the item.

DoStandardTax A boolean value that tells Retail Pro whether or not to calculate tax using the standard tax routines. Set DoStandardTax to True to have Retail Pro calculate the tax. Set DoStandardTax to False to use the tax percent returned by the function. Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

Post conditions The items tax is calcualated based on DoStandardTax and the returned Tax Percent.

Copyright 2008 Retail Pro. All rights reserved. 25

Retail Pro 8 Plugins Programmers Guide

Creating a Plugin
The easiest way the create a plugin package is to simply copy one of the examples provided by RTI and modify them to suit your needs. However, if you want to create a plugin package from scratch, this is what you do:

Create a New Package Project


From Delphis main menu select File->New. From the New Items dialog box, make sure you have the tab labeled New selected and double-click on the Package icon.

When the new package is open select File->Save All and select a location and name for your project files.

Add the plugin design-time packages to your code


Add RProAPI and RDA2_TLB to the uses clause of your code.

Copyright 2008 Retail Pro. All rights reserved. 26

Retail Pro 8 Plugins Programmers Guide

Create a plugin class


All plugin classes must be inherited from one of the abstract base classes defined in the Retail Pro API (RProAPI) unit. These classes are described in detail later in this document. Make sure you override all of the abstract methods in the class. Example:
type TInvcUpdate = class(TOnUpdate) private fInvoice: IRdaDocument; public class function Table: integer; override; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); override; function BeforeUpdate: boolean; override; procedure AfterUpdate; override; end;

Select table for the plugin


The Table function tells Retail Pro when to call a certain plugin. In this example it will be called for the Invoices table.
class function TInvcUpdate.Table: integer; begin Result := tblInvoices; end;

Export the plugin class


Each plugin package must export an RproClassesAvaliable procedure. This procedure tells Retail Pro what classes are available inside the package.
procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc); begin RProClassArrayProc([TInvcUpdate]); end;

Compile the plugin package


To compile a Delphi package you must click the Compile button on the package manager window rather than using the Compile command off the main menu.

Place the resulting .bpl file in the plugins directory under the Retail Pro directory. Copyright 2008 Retail Pro. All rights reserved. 27

Retail Pro 8 Plugins Programmers Guide

Appendix A Retail Pro API Code


(For Reference ONLY DO NOT COPY THIS CODE.)
unit RProAPI; interface uses RDA2_TLB; const AllFields = -100; csClassesAvailableName = 'RProClassesAvailable'; type TRProClassArrayProc = procedure(Classes: array of TClass); TRProClassesAvailableProc = procedure(RProClassArrayProc: TRProClassArrayProc); TSideMenu = (smDepartments, smVendors, smCustomers, smInventory, smReceipts, smReceiptList, smVouchers, smVoucherList, smMemos, smMemoList, smSlip, smSlipList, smSO, smSOList, smPO, smPOList, smTO, smTOList, smTender); TActionRequest = (arRefreshDocument, arRefreshList); TActionRequestSet = set of TActionRequest; TCustomFieldType = (cftString, cftInteger, cftDouble, cftQuantity, cftCurrency, cftDate, cftTime, cftDateTime); TRProApp = class function CreateTableByID(TableID: Integer): IRdaTable; virtual; abstract; function Preferences: IXMLDOMDocument; virtual; abstract;

procedure Print(const DesignName, PrinterName: string; SuppressPrinterDialog: boolean); virtual; abstract;


end; TValidateClass = class of TValidate; TValidate = class class function Table: integer; virtual; abstract; class function Field: integer; virtual; abstract; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; function Validate(var Value: variant): boolean; virtual; abstract; end; TAfterAssignClass = class of TAfterAssign; TAfterAssign = class class function Table: integer; virtual; abstract; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; procedure Execute(const FieldID: integer); virtual; abstract; end; TOnUpdateClass = class of TOnUpdate; TOnUpdate = class class function Table: integer; virtual; abstract; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; function BeforeUpdate: boolean; virtual; abstract; procedure AfterUpdate; virtual; abstract; end;

Copyright 2008 Retail Pro. All rights reserved. 28

Retail Pro 8 Plugins Programmers Guide


TItemAddRemoveClass = class of TItemAddRemove; TItemAddRemove = class class function Table: integer; virtual; abstract; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; function ItemBeforeRemove: boolean; virtual; abstract; function ItemBeforeAdd(ItemNo: integer): boolean; virtual; abstract; procedure ItemAfterAdd; virtual; abstract; end; TSideButtonClass = class of TSideButton; TSideButton = class class function Menu: TSideMenu; virtual; abstract; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; class function Caption: string; virtual; abstract; class function PictureFileName: string; virtual; abstract; function Execute: TActionRequestSet; virtual; abstract; // Enabled is called constantly (when RPro is idle), // so it shouldn't be time-consuming function Enabled: boolean; virtual; abstract; end; TTenderChangedClass = class of TTenderChanged; TTenderChanged = class procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; procedure TenderScreenEntered; virtual; abstract; procedure Changed; virtual; abstract; end; TOnPrintClass = class of TOnPrint; TOnPrint = class class function Table: integer; virtual; abstract; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; procedure BeforePrint(XMLDoc: IXMLDOMDocument); virtual; abstract; end; TCustomFieldClass = class of TCustomField; TCustomField = class class function Table: integer; virtual; abstract; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract; class function FieldType: TCustomFieldType; virtual; abstract; class function FieldLabel: string; virtual; abstract; class function FieldDescription: string; virtual; abstract; function MaxChars: integer; virtual; abstract; // 0 for unlimited function IsReadOnly: boolean; virtual; abstract; function GetData: variant; virtual; abstract; procedure SetData(Value: variant); virtual; abstract; function LookupList: string; virtual; abstract; end; implementation initialization end.

Copyright 2008 Retail Pro. All rights reserved. 29

Retail Pro 8 Plugins Programmers Guide

Appendix B Example Code Listing


Invoice Item Change
InvoiceItemChange.dpk
package InvoiceItemChange; {$R *.RES} {$ALIGN ON} {$ASSERTIONS ON} {$BOOLEVAL OFF} {$DEBUGINFO ON} {$EXTENDEDSYNTAX ON} {$IMPORTEDDATA ON} {$IOCHECKS ON} {$LOCALSYMBOLS ON} {$LONGSTRINGS ON} {$OPENSTRINGS ON} {$OPTIMIZATION OFF} {$OVERFLOWCHECKS OFF} {$RANGECHECKS OFF} {$REFERENCEINFO ON} {$SAFEDIVIDE OFF} {$STACKFRAMES OFF} {$TYPEDADDRESS OFF} {$VARSTRINGCHECKS ON} {$WRITEABLECONST OFF} {$MINENUMSIZE 1} {$IMAGEBASE $400000} {$RUNONLY} {$IMPLICITBUILD OFF} requires vcl50, RPRO_API; contains uInvoiceItemChange; end.

uInvoiceItemChange.pas
unit uInvoiceItemChange; interface uses RProAPI, RDA2_TLB, Dialogs, SysUtils; type TInvcItemNumAssigned = class(TAfterAssign) private fInvoice: IRdaDocument; fInvoiceItem: IRdaDocument; fCustomers: IRdaTable; public class function Table: integer; override; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); override; procedure Execute(const FieldID: integer); override; end;

Copyright 2008 Retail Pro. All rights reserved. 30

Retail Pro 8 Plugins Programmers Guide


TInvcItemAddRemove = class(TItemAddRemove) private fInvoice: IRdaDocument; fInvoiceItem: IRdaDocument; public class function Table: integer; override; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); override; function ItemBeforeRemove: boolean; override; function ItemBeforeAdd(ItemNo: integer): boolean; override; procedure ItemAfterAdd; override; end; TInvcItemNumValidate = class(TValidate) private public class function Table: integer; override; class function Field: integer; override; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); override; function Validate(var Value: variant): boolean; override; end; implementation procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc); begin RProClassArrayProc([TInvcItemNumAssigned, TInvcItemAddRemove , TInvcItemNumValidate]); end; exports RProClassesAvailable; { TInvcItemNumAssigned } class function TInvcItemNumAssigned.Table: integer; begin Result := ntblInvoiceItems; end; procedure TInvcItemNumAssigned.Initialize(RProApp: TRProApp; Doc: IRdaDocument); begin fInvoice := Doc; fInvoiceItem := fInvoice.NestedDocByID[ntblInvoiceItems]; fCustomers := RProApp.CreateTableByID(tblCustomers); fCustomers.Open; fCustomers.ActiveIndexID := idxCustSID; end; procedure TInvcItemNumAssigned.Execute(const FieldID: integer); var IsNull: WordBool; begin if FieldID = fidQty then fInvoiceItem.SetDouble(fInvoiceItem.GetDouble(fidQty, IsNull) + 1, fidQty); if fCustomers.Find(fInvoice.GetString(fidBillToCustSID, IsNull), true) then ShowMessage(fCustomers.Document.GetString(fidFullName ,IsNull)); end; { TInvcItemAddRemove } class function TInvcItemAddRemove.Table: integer; begin Result := tblInvoices; end; procedure TInvcItemAddRemove.Initialize(RProApp: TRProApp; Doc: IRdaDocument); begin fInvoice := Doc;

Copyright 2008 Retail Pro. All rights reserved. 31

Retail Pro 8 Plugins Programmers Guide


fInvoiceItem := fInvoice.NestedDocByID[ntblInvoiceItems]; end; function TInvcItemAddRemove.ItemBeforeRemove: boolean; var IsNull: WordBool; ItemNo: integer; begin ItemNo := fInvoiceItem.GetInteger(fidItemNo, IsNull); Result := true; if ItemNo = 2 then begin Result := false; ShowMessage(Format('Item # %d cannot be removed', [ItemNo])); end else ShowMessage(Format('Item # %d is removed', [ItemNo])); end; function TInvcItemAddRemove.ItemBeforeAdd(ItemNo: integer): boolean; begin Result := true; if ItemNo = 3 then begin Result := false; ShowMessage(Format('Item # %d cannot be added', [ItemNo])); end; end; procedure TInvcItemAddRemove.ItemAfterAdd; var IsNull: WordBool; begin ShowMessage(Format('Item # %d is added', [fInvoiceItem.GetInteger(fidItemNo, IsNull)])); end; { TInvcItemNumValidate } class function TInvcItemNumValidate.Table: integer; begin Result := ntblInvoiceItems; end; class function TInvcItemNumValidate.Field: integer; begin Result := fidItemLookup; end; procedure TInvcItemNumValidate.Initialize(RProApp: TRProApp; Doc: IRdaDocument); begin end; function TInvcItemNumValidate.Validate(var Value: variant): boolean; begin Result := true; case Value of 4: begin Result := false; ShowMessage('Item # 4 rejected'); end; 5: begin Value := 6; ShowMessage('Item # 5 replaced with Item # 6'); end; end; end; end.

Copyright 2008 Retail Pro. All rights reserved. 32

Retail Pro 8 Plugins Programmers Guide

PrintInvoice
PrintInvoice.dpk
package PrintInvoice; {$R *.RES} {$ALIGN ON} {$ASSERTIONS ON} {$BOOLEVAL OFF} {$DEBUGINFO ON} {$EXTENDEDSYNTAX ON} {$IMPORTEDDATA ON} {$IOCHECKS ON} {$LOCALSYMBOLS ON} {$LONGSTRINGS ON} {$OPENSTRINGS ON} {$OPTIMIZATION OFF} {$OVERFLOWCHECKS OFF} {$RANGECHECKS OFF} {$REFERENCEINFO ON} {$SAFEDIVIDE OFF} {$STACKFRAMES OFF} {$TYPEDADDRESS OFF} {$VARSTRINGCHECKS ON} {$WRITEABLECONST OFF} {$MINENUMSIZE 1} {$IMAGEBASE $400000} {$IMPLICITBUILD OFF} requires vcl50, RPRO_API; contains uPrintInvoice; end.

uPrintInvoice
unit uPrintInvoice; interface uses Windows, RProAPI, RDA2_TLB, Dialogs, SysUtils, MSXML_TLB, ShellAPI; type TInvcUpdate = class(TOnUpdate) private fInvoice: IRdaDocument; public class function Table: integer; override; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); override; function BeforeUpdate: boolean; override; procedure AfterUpdate; override; end; TInvoicePrint = class(TOnPrint) private fInvoice: IRdaDocument; public class function Table: integer; override;

Copyright 2008 Retail Pro. All rights reserved. 33

Retail Pro 8 Plugins Programmers Guide


procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); override; procedure BeforePrint(XMLDoc: IXMLDOMDocument); override; end; implementation procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc); begin RProClassArrayProc([TInvcUpdate]); end; exports RProClassesAvailable; { TInvcUpdate } class function TInvcUpdate.Table: integer; begin Result := tblInvoices; end; procedure TInvcUpdate.Initialize(RProApp: TRProApp; Doc: IRdaDocument); begin fInvoice := Doc; end; function TInvcUpdate.BeforeUpdate: boolean; var IsNull: wordbool; begin if fInvoice.GetDouble(fidTotal, IsNull) > 100 then begin Result := false; ShowMessage('Receipts > $100 are not allowed'); end else Result := true; end; procedure TInvcUpdate.AfterUpdate; var XMLInvoice: IXMLDOMDocument; begin XMLInvoice := fInvoice.XMLDOMDocument(false); XMLInvoice.save('invoice.xml'); ShellExecute(0, 'open', 'invoice.xml', '', '', SW_SHOWNORMAL); DeleteFile('invoice.xml'); end; { TInvoicePrint } class function TInvoicePrint.Table: integer; begin Result := tblInvoices; end; procedure TInvoicePrint.Initialize(RProApp: TRProApp; Doc: IRdaDocument); begin fInvoice := Doc; end; procedure TInvoicePrint.BeforePrint(XMLDoc: IXMLDOMDocument); begin XMLDoc.documentElement.setAttribute('PI', 3.14); end; end.

Copyright 2008 Retail Pro. All rights reserved. 34

Retail Pro 8 Plugins Programmers Guide

InvoiceButton
InvoiceButton.dpk
package InvoiceButton; {$R *.RES} {$ALIGN ON} {$ASSERTIONS ON} {$BOOLEVAL OFF} {$DEBUGINFO ON} {$EXTENDEDSYNTAX ON} {$IMPORTEDDATA ON} {$IOCHECKS ON} {$LOCALSYMBOLS ON} {$LONGSTRINGS ON} {$OPENSTRINGS ON} {$OPTIMIZATION OFF} {$OVERFLOWCHECKS OFF} {$RANGECHECKS OFF} {$REFERENCEINFO ON} {$SAFEDIVIDE OFF} {$STACKFRAMES OFF} {$TYPEDADDRESS OFF} {$VARSTRINGCHECKS ON} {$WRITEABLECONST OFF} {$MINENUMSIZE 1} {$IMAGEBASE $400000} {$RUNONLY} {$IMPLICITBUILD OFF} requires vcl50, RPRO_API; contains uInvoiceButton; end.

uInvoiceButton.pas
unit uInvoiceButton; interface uses Windows, RProAPI, RDA2_TLB, SysUtils; type TInvoiceButton = class(TSideButton) Private fRProApp: TRProApp; fInvoice: IRdaDocument; public class function Menu: TSideMenu; override; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); override; class function Caption: string; override; class function PictureFileName: string; override; function Execute: TActionRequestSet; override; function Enabled: boolean; override; end; TTenderButton = class(TSideButton) private fInvoice: IRdaDocument;

Copyright 2008 Retail Pro. All rights reserved. 35

Retail Pro 8 Plugins Programmers Guide


public class function Menu: TSideMenu; override; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); override; class function Caption: string; override; class function PictureFileName: string; override; function Execute: TActionRequestSet; override; function Enabled: boolean; override; end; TTenderMonitor = class(TTenderChanged) private fTender: IRdaTender; public procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); override; procedure TenderScreenEntered; override; procedure Changed; override; end; implementation procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc); begin RProClassArrayProc([TInvoiceButton]); end; exports RProClassesAvailable; { TInvoiceButton } class function TInvoiceButton.Menu: TSideMenu; begin Result := smReceipts; end; class function TInvoiceButton.Caption: string; begin Result := 'Custom Button'; end; procedure TInvoiceButton.Initialize(RProApp: TRProApp; Doc: IRdaDocument); begin fRProApp := RproApp; fInvoice := Doc; end; function TInvoiceButton.Execute: TActionRequestSet; begin // \\CORDELIA\RD1 fRProApp.Print('Receipt, Letter', '', false); fInvoice.SetString('Custom Comment', fidInvcComment1); Result := [arRefreshDocument]; end; class function TInvoiceButton.PictureFileName: string; begin Result := 'global discount.bmp'; end; function TInvoiceButton.Enabled: boolean; var h, m, sec, msec: word; begin DecodeTime(Time, h, m, sec, msec); Result := sec < 50; end; { TTenderButton }

Copyright 2008 Retail Pro. All rights reserved. 36

Retail Pro 8 Plugins Programmers Guide


class function TTenderButton.Menu: TSideMenu; begin Result := smTender; end; class function TTenderButton.Caption: string; begin Result := 'Credit 2 Dollars'; end; procedure TTenderButton.Initialize(RProApp: TRProApp; Doc: IRdaDocument); begin fInvoice := Doc; end; function TTenderButton.Execute: TActionRequestSet; var Tender: IRdaTender; Card: IRdaCreditCard; TndrItem: IDispatch; begin Tender := fInvoice.CustomInterface as IRdaTender; TndrItem := Tender.AddItem(ttCreditCard); Card := TndrItem as IRdaCreditCard; // Card.Amount := 2; Card.CardType := 'VISA'; Card.CardNumber := '12345'; Card.ExpMonth := 9; Card.ExpYear := 03; Result := [arRefreshDocument]; end; class function TTenderButton.PictureFileName: string; begin Result := 'global discount.bmp'; end; function TTenderButton.Enabled: boolean; begin Result := true; end; { TTenderMonitor } procedure TTenderMonitor.Initialize(RProApp: TRProApp; Doc: IRdaDocument); begin fTender := Doc.CustomInterface as IRdaTender; end; procedure TTenderMonitor.TenderScreenEntered; begin ShowMessage('Tenders entered'); end; procedure TTenderMonitor.Changed; var Item: IUnknown; fc: IRdaFC; begin ShowMessage(IntToStr(fTender.TenderItems.length)); if fTender.Undefined < 0 then begin Item := fTender.AddItem(ttFC); fc := Item as IRdaFC; fc.Amount := fTender.Undefined; fc.FCAmount := 1000; fc.FCName := 'ROUBLES'; end; end; end.

Copyright 2008 Retail Pro. All rights reserved. 37

Retail Pro 8 Plugins Programmers Guide

InvoiceField
InvoiceField.dpk
package InvoiceField; {$R *.RES} {$ALIGN ON} {$ASSERTIONS ON} {$BOOLEVAL OFF} {$DEBUGINFO ON} {$EXTENDEDSYNTAX ON} {$IMPORTEDDATA ON} {$IOCHECKS ON} {$LOCALSYMBOLS ON} {$LONGSTRINGS ON} {$OPENSTRINGS ON} {$OPTIMIZATION OFF} {$OVERFLOWCHECKS OFF} {$RANGECHECKS OFF} {$REFERENCEINFO ON} {$SAFEDIVIDE OFF} {$STACKFRAMES OFF} {$TYPEDADDRESS OFF} {$VARSTRINGCHECKS ON} {$WRITEABLECONST OFF} {$MINENUMSIZE 1} {$IMAGEBASE $400000} {$IMPLICITBUILD OFF} requires vcl50, RPRO_API; contains uInvoiceField; end.

Copyright 2008 Retail Pro. All rights reserved. 38

Retail Pro 8 Plugins Programmers Guide

uInvoiceField.pas
unit uInvoiceField; interface uses Windows, Classes, RProAPI, RDA2_TLB, Dialogs, SysUtils, MSXML_TLB, ShellAPI; type TInvcWrappingKind = class(TCustomField) private fInvoice: IRdaDocument; fData: TStringList; public class function Table: integer; override; procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); override; destructor Destroy; override; class function FieldType: TCustomFieldType; override; class function FieldLabel: string; override; class function FieldDescription: string; override; function MaxChars: integer; override; function IsReadOnly: boolean; override; function GetData: variant; override; procedure SetData(Value: variant); override; function LookupList: string; override; end; implementation const csFileName = 'wrappings.txt'; procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc); begin RProClassArrayProc([TInvcWrappingKind]); end; exports RProClassesAvailable; { TInvcWrappingKind } class function TInvcWrappingKind.Table: integer; begin Result := tblInvoices; end; procedure TInvcWrappingKind.Initialize(RProApp: TRProApp; Doc: IRdaDocument); begin fInvoice := Doc; fData := TStringList.Create; try fData.LoadFromFile(csFileName); except end; end; destructor TInvcWrappingKind.Destroy; begin fData.SaveToFile(csFileName); fData.Free; inherited; end; class function TInvcWrappingKind.FieldLabel: string; begin Result := 'Wrapping';

Copyright 2008 Retail Pro. All rights reserved. 39

Retail Pro 8 Plugins Programmers Guide


end; class function TInvcWrappingKind.FieldDescription: string; begin Result := 'Wrapping type used for the Receipt'; end; class function TInvcWrappingKind.FieldType: TCustomFieldType; begin Result := cftString; end; function TInvcWrappingKind.IsReadOnly: boolean; var IsNull: WordBool; begin Result := fInvoice.GetInteger(fidBillToCustID, IsNull) = 0; //allow only Receipts with customer end; function TInvcWrappingKind.MaxChars: integer; begin Result := 0; end; function TInvcWrappingKind.GetData: variant; var IsNull: WordBool; begin Result := fData.Values[IntToStr(fInvoice.GetInteger(fidInvcNum, IsNull))]; end; procedure TInvcWrappingKind.SetData(Value: variant); var IsNull: WordBool; begin fData.Values[IntToStr(fInvoice.GetInteger(fidInvcNum, IsNull))] := Value; end; function TInvcWrappingKind.LookupList: string; begin Result := 'Birthday,Christmas,Valentine'; end; end.

Copyright 2008 Retail Pro. All rights reserved. 40

You might also like