Home >Documents >Plugins Programmers Guide

Plugins Programmers Guide

Date post:04-Jun-2018
Category:
View:225 times
Download:0 times
Share this document with a friend
Transcript:
  • 8/14/2019 Plugins Programmers Guide

    1/44

    Retail Pro8 SeriesPlugins Programmers Guide

    Retail Pro3252 Holiday CourtLa Jolla, CA 92037 USA

    USA 1-800-738-2457International +1-858-550-3355www.retailpro.com

  • 8/14/2019 Plugins Programmers Guide

    2/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    ii

    About this GuideThis 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 tocontact us at [email protected]

    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 CourtLa 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 trademarksor service marks are the property of their respective owners and should be treated as such.

  • 8/14/2019 Plugins Programmers Guide

    3/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    iii

    Table of ContentsAbout 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.......................................................................................... 4Make 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........................................................................................... 94.4.2 Preferences Method ........................................................................................... 9

    Print Method ............................................................................................................. 10

    Base Classes in Detail..................................................................................................11

    TValidate................................................................................................................... 11

    TAfterAssign............................................................................................................. 13TOnUpdate................................................................................................................ 14

    TItemAddRemove..................................................................................................... 15

    TSideButton .............................................................................................................. 17TTenderChanged....................................................................................................... 19

    TCustomField ........................................................................................................... 21TOnPrint ................................................................................................................... 24

    Creating a Plugin................................................................................................................26

    Create a New Package Project .....................................................................................26

    Add the plugin design-time packages to your code.................................................. 26Create a plugin class ................................................................................................. 27

    Select table for the plugin ......................................................................................... 27

    Export the plugin class.............................................................................................. 27

  • 8/14/2019 Plugins Programmers Guide

    4/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    iv

    Compile the plugin package...................................................................................... 27

    Appendix A Retail Pro API Code...................................................................................28

    Appendix B Example Code Listing................................................................................30

    Invoice Item Change....................................................................................................30

    InvoiceItemChange.dpk............................................................................................ 30uInvoiceItemChange.pas........................................................................................... 30

    PrintInvoice..................................................................................................................33

    PrintInvoice.dpk........................................................................................................ 33

    uPrintInvoice............................................................................................................. 33

    InvoiceButton...............................................................................................................35

    InvoiceButton.dpk..................................................................................................... 35

    uInvoiceButton.pas ................................................................................................... 35

    InvoiceField .................................................................................................................38

    InvoiceField.dpk ....................................................................................................... 38uInvoiceField.pas ...................................................................................................... 39

  • 8/14/2019 Plugins Programmers Guide

    5/44

  • 8/14/2019 Plugins Programmers Guide

    6/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    2

    IntroductionRetail Pro 8 Series enables you to use customplugins 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

  • 8/14/2019 Plugins Programmers Guide

    7/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    3

    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 willfind 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 StructureAdd 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.

  • 8/14/2019 Plugins Programmers Guide

    8/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    4

    Development EnvironmentImportant: 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 Noif 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 RDA21. 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 Libraryon 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.

  • 8/14/2019 Plugins Programmers Guide

    9/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    5

    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:\ProgramFiles\Borland\Delphi5\Projects\Bpl.

    Or

    1. Copy the files to another location and add that directory to Delphis search path. The Searchpath 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 theInstallbutton on the package dialog window. This will compile the RPRO_API andplace the results in Delphis search path.

    3. Note: To be sure you compile your plugins against the same version of the RPRO_API asRetail Pro uses to run it you should find the RPRO_API.bpl file you just compilednormally

    located in C:\Program Files\Borland\Delphi5\Projects\bpldirectoryto the base directory of

    your Retail Pro installation (the same directory in which you will find RPro8.exe, for

    example C:\Retail).

  • 8/14/2019 Plugins Programmers Guide

    10/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    6

    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 functionRproClassesAvaliable.

    procedure RProCl assesAvai l abl e(RProCl assAr r ayProc: TRProCl assAr r ayProc);begin

    RProCl assAr r ayProc([ TMyRProPl ugi n] ) ;end;

    exportsRProCl assesAvai l abl e;

    This function has one argument of type TRProClassArrayProcin which you specify which

    classes your package contains. In the above example the package contains one plugin class called

    TMyRProPlugin.

  • 8/14/2019 Plugins Programmers Guide

    11/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    7

    Common Methods

    All base classes have common setup methods that must be implemented in each plugin derived

    from it.

    Initialize Method

    TheInitializemethod is common to all base classes.

    Initialize procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual;abstract;

    Description 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 theTable function.

    RProApp This is a reference from Retail Pro to an object of type TRProAPP (alsodefined in the RProAPI unit). This object provides access to the root of theRDA2 data to the plugin. TRProAPPs single method CreateTableByID is thesame as that of the IRdaDB interface and can be used to access any tablewithout having to create a new instance of RDA2.

    Doc An IRdaDocument object that will point to the current document. Thedocument is of the type appropriate for the table you specified in the tablefunction.

    Note that the plugin only get a reference to the document in the Initializefunction. The reference must be kept by the plugin and will automatically be

    updated to always point to the document for which the plugins functions arecalled.

    Preconditions None.

    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. Anyconstruction code should be put in this method.

    There is no corresponding de-initialize function in the base classes. A regulardestructor can be added to the plugin if necessary, but do not forget to callinherited from within it.

  • 8/14/2019 Plugins Programmers Guide

    12/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    8

    Table Method

    The Tablemethod is common to all classes except the TSideButtonclass.

    Table class function Table: integer; virtual; abstract;

    Description Since the base classes are generic and can work on any table or nesteddocument, a plugin must implement the Table function to tell Retail Pro whatspecific table this plugin will work on.

    Return Value The function must return an integer value that is the RDA2 table ID, ornested document ID.

    Preconditions This is a class function it may, and will, be called by Retail Pro before anyobjects of the class has been instantiated. You cannot reference any regularmembers from a class function.

    Post conditions None.

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

  • 8/14/2019 Plugins Programmers Guide

    13/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    9

    The TRProApp Class

    TRPr oApp = classfunction Cr eat eTabl eByI D( Tabl eI D: I nt eger) : I RdaTabl e; virtual;

    abstract;function Pref er ences: I XMLDOMDocument ; virtual; abstract;procedure Pr i nt ( const Desi gnName, Pri nt erName: string;

    Suppr essPr i nt erDi al og: bool ean) ; virtual; abstract;end;

    A reference to a TRProAppobject is provided by Retail Pro in theInitializemethod 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 theDocparameter of

    theInitializemethod).

    The TRProAppmakes 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 functionCreateTableByID(TableID: Integer): IRdaTable; virtual;abstract;

    Description The CreateTableByIDmethod can return a IRdaTable reference to any tableaccessible by RDA2.

    TableID An integer that corresponds to the field IDs set up in RDA2.

    Return Value 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 functionPreferences: IXMLDOMDocument; virtual; abstract;

    Description This method gives you some access to the Retail Pro preferences from withina plugin. Not that all preferences are not accessible, and the ones that are,are mostly read-only. See the RDA documentation for information andexamples of the XML preferences.

    Return Value An XML DOM Document object that holds information about the current RetailPro preferences.

  • 8/14/2019 Plugins Programmers Guide

    14/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    10

    Print Method

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

    Description This function can be called from within a plugin to force printing of thecurrent document. Use the TOnPrintplugin to intercept and modify theinformation to be printed if necessary.

    DesignName 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.

    PrinterName A string containing the printer name of the destination printer. If the printerdialog is displayed, it will default to this printer.

    SuppressPrinterDialog 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, ifthat is not set the default system printer will be used.

  • 8/14/2019 Plugins Programmers Guide

    15/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    11

    Base Classes in Detail

    TValidateTVal i date = class

    class function Tabl e: integer; virtual; abstract;class function Fi el d: integer; virtual; abstract;procedure I ni t i al i ze( RProApp: TRProApp; Doc: I RdaDocument ) ; virtual;

    abstract;function Val i dat e( var Val ue: var i ant ) : boolean; virtual; abstract;

    end;

    With the TValidateplugin 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 Tablemethod this class has another initialization method called Field:

    Validate class function Field: integer; virtual; abstract;

    Description Use this function to tell Retail Pro for which field you want to trap the input.

    Field An integer that corresponds to the field IDs set up in RDA2. Retail Pro willcall the Validate function for all input destined for the field whos ID isreturned by this function.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked.

    Post conditions None.

    Comments This method is only called when a field is updated by a manual entry, notinternally by Retail Pro itself.

  • 8/14/2019 Plugins Programmers Guide

    16/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    12

    Validate Event Method

    Validate function Validate(var Value: variant): boolean; virtual; abstract;

    Description This class only has one event-method. It is called before the value of any fieldin the selected table (or nested document) is updated.

    Note: the Doc reference obtained in the Initialize procedure will always pointto the current document.

    Value A variant that holds the new value proposed for the field.

    Return Value If the function returns the Boolean value True, the value in the Valueparameter will be assigned to the Retail Pro field. (Note that Retail Pro alsodoes its own input validation and not all values might be accepted). If returnvalue is False, the input operation will be cancelled and the field will keep itsprevious value.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked.

    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, notinternally by Retail Pro itself.

  • 8/14/2019 Plugins Programmers Guide

    17/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    13

    TAfterAssignTAf t er Ass i gn = class

    class function Tabl e: integer; virtual; abstract;procedure I ni t i al i ze ( RProApp: TRProApp; Doc: I RdaDocument ) ; virtual;

    abstract;procedure Execute( const F i el dI D: 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. ItsExecutefunction 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 procedure Execute(const FieldID: integer); virtual; abstract;

    Description This class only has one event-method. It is called when the value of any fieldin the selected table (or nested document) is updated.

    Note: to get the particular document that was updated use the Doc referenceobtained in the Initialize procedure. It will always point to the currentdocument.

    FieldID An integer holding the RDA2 field ID of the field that was updated.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked.

    Post Conditions None.

    Comments This method is only called when a field is updated by a manual entry, notinternally by Retail Pro itself.

  • 8/14/2019 Plugins Programmers Guide

    18/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    14

    TOnUpdateTOnUpdat e = class

    class function Tabl e: integer; virtual; abstract;procedure I ni t i al i ze ( RProApp: TRProApp; Doc: I RdaDocument ) ; virtual;

    abstract;

    function Bef oreUpdate: boolean; virtual; abstract;procedure Af t erUpdate; 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 yieldunpredictable results and cause lock-up of Retail Pro.

    BeforeUpdate Event Method

    BeforeUpdate function BeforeUpdate: boolean; virtual; abstract;

    Description Like the name implies, the BeforeUpdate function is called right before adocument of the selected table is updated. From the plugin it can be decidedwhether the document should actually be updated or not.

    Return Value 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 beforethe update event was triggered.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked. The Doc reference is pointing to the document about to be updated.

    Post Conditions Return value is a valid Boolean value.

    AfterUpdate Event Method

    AfterUpdate procedure AfterUpdate; virtual; abstract;

    Description This procedure is called by Retail Pro right after a document of the selectedtable has been saved.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked. The Doc reference is pointing to the document that was just

    updated.

    Post conditions None

  • 8/14/2019 Plugins Programmers Guide

    19/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    15

    TItemAddRemoveTI t emAddRemove = class

    class function Tabl e: integer; virtual; abstract;procedure I ni t i al i ze ( RProApp: TRProApp; Doc: I RdaDocument ) ; virtual;

    abstract;function I t emBef or eRemove: boolean; virtual; abstract;function I t emBef oreAdd( I t emNo: integer) : boolean; virtual; abstract;procedure I t emAf t erAdd; 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 Tablefunction

    should return the ID number of the Invoice table.

    Note that theDocreference received in theInitializestill points to the current document in theselected table (the document which is having nested documents added or removed). To access the

    nested document which is being added or removed use theNestedDocByID orNestedDocByName

    methods of theDocreference.

    ItemBeforeRemove Event Method

    ItemBeforeRemove function ItemBeforeRemove: boolean; virtual; abstract;

    Description This function is called right before an item is to be removed. The plugin candecide whether to allow it being removed or not.

    Return Value Returning the Boolean value True will allow Retail Pro to remove this item.The value False will force Retail Pro to keep the item.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked. There must be at east one item (nested document) added to thecurrent document.

    Post Conditions Return value is a valid Boolean value.

    ItemBeforeAdd Event Method

    ItemBeforeAdd function ItemBeforeAdd(ItemNo: integer): boolean; virtual; abstract;

    Description This function is called right before an item is to be added. The plugin candecide whether to allow Retail Pro to add it or not.

    ItemNo This is the Retail Pro item number of the item that is about to be added.

  • 8/14/2019 Plugins Programmers Guide

    20/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    16

    Return Value If the function returns True, Retail Pro will add the item, if False the item willbe discarded.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked.

    Post Conditions Return value is a valid Boolean value.

    Comments Since this is called before the item (nested document) is actually added to thedocument there is not a valid IRdaDocument representation of the item.

    ItemAfterAdd Event Method

    ItemAfterAdd procedure ItemAfterAdd; virtual; abstract;

    Description This is called immediately after an item (nested document) has been added to

    a document in the selected table.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked.

    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 ifthe quantity of the added item is larger than one.

  • 8/14/2019 Plugins Programmers Guide

    21/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    17

    TSideButtonTSi deBut t on = class

    class function Menu: TSi deMenu; virtual; abstract;procedure I ni t i al i ze( RProApp: TRProApp; Doc: I RdaDocument ) ; virtual; abstract;class function Capt i on: str i ng; virtual; abstract;class function Pi ctureFi l eName: st r i ng; virtual; abstract;function Execut e: TAct i onRequest Set ; virtual; abstract;function Enabl ed: boolean; virtual; abstract;

    end;

    This plugin enables you to add a custom button to a context (side) menu in Retail Pro.

    In addition to theInitialize method, this class has four other initialization methods:Menu,

    Caption, PictureFileName, andEnabled.

    Menu Method

    Menu class function Menu: TSideMenu; virtual; abstract;

    Description This function controls to which context menu the button should be added.

    Return Value A value of type TSideMenu that tells Retail Pro to which menu the buttonshould be added. Currently the following values are possible:smDepartmentssmVendorssmCustomerssmInventorysmReceiptssmReceiptListsmVoucherssmVoucherList

    smMemossmMemoListsmSlipsmSlipListsmSOsmSOListsmPOsmPOListsmTOsmTOListsmTender

    Note: for screens where Form view and List view have different menus thereare TSideMenu types for both menus respectively. For example, smReciptscorresponds to the menu for Receipts in Form view, and smReceiptList to themenu for Receipts in List view.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked.

    Post conditions Return value is a TSideMenu value.

  • 8/14/2019 Plugins Programmers Guide

    22/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    18

    Caption Method

    Caption class function Caption: string; virtual; abstract;

    Description This function tells Retail Pro what the caption of the custom button should be.

    Return Value Return the desired Caption for the button as a string.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked. There must be at east one item (nested document) added to thecurrent document.

    Post conditions Return value is a valid string.

    PictureFileName Method

    PictureFileNameclass function PictureFileName: string; virtual; abstract

    Description Use this function to add a bitmap (.bmp) to the custom button.

    Return Value 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 /Pluginsdirectory.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked. There must be at east one item (nested document) added to thecurrent document.

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

    Enabled Method

    Enabled function Enabled: boolean; virtual; abstract;

    Description Tells Retail Pro whether the button is enabled or disabled (grayed out). RetailPro calls this function periodically when it is idle so unlike the other propertiesof the button (Caption, Bitmap) Enabled can be changed at any time duringexecution.

    Return Value Return True for the button to be enabled, False for disabled.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked. There must be at east one item (nested document) added to thecurrent document.

    Post conditions Return value is a valid Boolean value.

  • 8/14/2019 Plugins Programmers Guide

    23/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    19

    Execute Event Method

    Execute function Execute: TActionRequestSet; virtual; abstract;

    Description This function is called from Retail Pro when the user clicked the custombutton.

    Return Value The return value is of type TactionRequestSet, currently the options in thisset are:arRefreshDocumentarRefreshList

    The return value forces Retail Pro to update the view of the current documentor list to make sure any changes made during the execute method aredisplayed.

    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 beinvoked. There must be at east one item (nested document) added to thecurrent document.

    Post conditions Return value is a valid TactionRequestSet value.

    TTenderChangedTTender Changed = classprocedure I ni t i al i ze( RProApp: TRPr oApp;

    Doc: I RdaDocument) ; virtual; abstract;

    procedure TenderScreenEntered; virtual; abstract;procedure Changed; virtual; abstract;end;

    The TTenderChangedplugin 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: TenderScreenEnteredand Changed.

    TenderScreenEntered Event Method

    TenderScreenEntered procedureTenderScreenEntered; virtual; abstract;

    Description Is called by Retail Pro whenever the user enters the Tender screen, forexample when tendering a new invoice.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked.

    Post conditions None.

  • 8/14/2019 Plugins Programmers Guide

    24/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    20

    Changed Event Method

    Changed procedureChanged; virtual; abstract;

    Description Is called by Retail Pro whenever the user changes the information on thetender screen. When a tender line is added or deleted.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked.

    Post conditions None.

  • 8/14/2019 Plugins Programmers Guide

    25/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    21

    TCustomFieldTCust omFi el d = class

    class function Tabl e: i nt eger ; virtual; abstract;procedure I ni t i al i ze( RPr oApp: TRPr oApp;

    Doc: I RdaDocument ) ; vi r t ual ; abst r act ;class function Fi el dType: TCustomFi el dType; virtual; abstract;class function Fi el dLabel : str i ng; virtual; abstract;class function Fi el dDescri pt i on: string; virtual; abstract;function MaxChars : i nt eger; virtual; abstract; / / 0 f or unl i mi tedfunction I sReadOnl y: bool ean; virtual; abstract;function GetData: var i ant ; virtual; abstract;procedure Set Dat a( Val ue: var i ant ) ; virtual; abstract;function LookupLi st : 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 withInitializeand Tablethis plugin class has 8 setup related methods: FieldType,FieldLabel, FieldDescription,MaxChars,IsReadOnly, andLookupList. The event methods are

    GetDataand SetData.

    FieldType Method

    FieldType classfunctionFieldType: TCustomFieldType; virtual; abstract;

    Description Tells Retail Pro what type of field this is so it can be formatted correctly onscreen.

    Return Value Return a value of the type TCustomFieldType. This type can have thefollowing values are possible:

    cftStringcftIntegercftDoublecftQuantitycftCurrencycftDatecftTimecftDateTime

    Preconditions This is a class function it may, and will, be called by Retail Pro before anyobjects of the class has been instantiated. You cannot reference any regularmembers from this function.

    Post conditions The return value is a valid TCustomFieldTypeValue.

  • 8/14/2019 Plugins Programmers Guide

    26/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    22

    FieldLabel Method

    FieldLabel classfunctionFieldLabel: string; virtual; abstract;

    Description Tells Retail Pro what the label to display for the field.

    Return Value Return a string value containing the desired label.

    Preconditions This is a class function it may, and will, be called by Retail Pro before anyobjects of the class has been instantiated. You cannot reference any regularmembers from this function.

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

    FieldDescription Method

    FieldDescription classfunctionFieldDescription: string; virtual; abstract;

    Description Tells Retail Pro what the description is for the field. The description isdisplayed in the Tool Tips window when the cursor is placed over the fieldfor a specified amount of time.

    Return Value Return a string value containing the desired description.

    Preconditions This is a class function it may, and will, be called by Retail Pro before anyobjects of the class has been instantiated. You cannot reference any regularmembers from this function.

    Post conditions The return value is a valid string.

    MaxChars Method

    MaxChars function MaxChars: integer; virtual; abstract;

    Description Sets the maximum number of characters that retail pro will allow to beentered in the custom field.

    Return Value Return an integer value representing the maximum number of characters.Return zero to set an unlimited field length.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked.

    Post conditions The return value is a valid integer value.

  • 8/14/2019 Plugins Programmers Guide

    27/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    23

    IsReadOnly Method

    IsReadOnly functionIsReadOnly: boolean; virtual; abstract;

    Description If this function is set to true, Retail Pro will not allow the user to edit thisfield.

    Return Value Return an bolean value of true to disallow editing of the field.

    Preconditions Retail Pro must have called Initialize on this class before this method can beinvoked.

    Post conditions The return value is a valid boolean value.

    LookupList Method

    LookupList functionLookupList: string; virtual; abstract;

    Description If you want to have certain pre-selected values available for the field througha drop down list, you can set up the list of values with this function.

    Return Value Return a string of comma-separated values that you want to appear in thedrop down list. If an empty string is returned there will be no drop down listfor the field.

    Preconditions Retail Pro must have called Initializeon this class before this method can beinvoked.

    Post conditions The return value is a valid string value.

    GetData Event Method

    GetData functionGetData: variant; virtual; abstract;

    Description This function is called when Retail Pro is going to display the content of thecustom field. This function supplies the value that should be displayed toRetail Pro.

    Return Value Return a variant type with the value that Retail Pro should display.

    Preconditions Retail Pro must have called Initializeon this class before this method can beinvoked.

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

  • 8/14/2019 Plugins Programmers Guide

    28/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    24

    SetData Event Method

    SetData procedureSetData(Value: variant); virtual; abstract;

    Description This function is called when Retail Pro is going to set the value of the customfield. 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 GetDataimmediately after this method is finished so if the new value is not saved (forexample because it did not pass validation) the old value will overwrite thenew value.This method will never be called if the field is set to read-only.

    Value A parameter of variant type that contains the new value that the userentered/selected.

    Preconditions Retail Pro must have called Initializeon this class before this method can beinvoked.

    Post conditions None.

    TOnPrintTOnPr i nt = class

    class function Tabl e: i nt eger; virtual; abstract;procedure I ni t i al i ze( RPr oApp: TRPr oApp;

    Doc: I RdaDocument ) ; virtual; abstract;procedure Bef orePr i nt ( XMLDoc: I XMLDOMDocument) ; virtual; abstract;procedure Af terPr i nt ; virtual; abstract;

    end;

    The TOnPrintclass can be used to intercept when a document is about to be printed or after it is

    printed. With theBeforePrintmethod 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 theDocument Printer XML to print custom documents.

    BeforePrint Event Method

    BeforePrint procedureBeforePrint(XMLDoc: IXMLDOMDocument); virtual; abstract;

    Description Called just before a document is printed.

    XMLDoc A XML DOM Document containing the information that will be sent to theDocument Printer. This information may be modified to produce a customizedprint out. If nothing is changed in the XMLDoc, the document will be printed

    in normal fashion.

    Preconditions Retail Pro must have called Initializeon this class before this method can beinvoked.The XMLDoc parameter references a valid XML Dom Document objectcontaining the document information to be printed.

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

  • 8/14/2019 Plugins Programmers Guide

    29/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    25

    AfterPrint Event Method

    AfterPrint procedureAfterPrint; virtual; abstract;

    Description Called just after a document is printed.

    Preconditions Retail Pro must have called Initializeon this class before this method can beinvoked.

    Post conditions None.

    TTaxRate

    TTaxRat e = classprocedure I ni t i al i ze( RPr oApp: TRPr oApp) ; virtual; abstract;function GetTaxRate( TaxCode: i nt eger;

    const TaxAr ea: st r i ng;Pr i ce: doubl e;Quant i t y: doubl e;var DoSt andardTax: bool ean): doubl e; virtual;

    abstract;

    GetTaxRate Event Method

    GetTaxRate function GetTaxRate(TaxCode: integer; const TaxArea: string; Price: double;Quantity: double; var DoStandardTax: boolean): double; virtual; abstract

    Return Value The tax percentage to be used for the item. 2.5% = 2.5 (not .025)

    Description Called any time Retail Pro calculates tax for a line item. For example, addingan item to a receipt, changing price, changing quantity, etc.

    TaxCode The Tax Code assigned to the item. (This is the integer value of the TaxCode, not the string description as seen in Preferences).

    TaxArea The TaxArea assigned to the item.

    Price The unit price of the item.

    Quantity The quantity of the item.

    DoStandardTax A boolean value that tells Retail Pro whether or not to calculate tax using thestandard tax routines. Set DoStandardTax to True to have Retail Pro calculatethe tax. Set DoStandardTax to False to use the tax percent returned by the

    function.

    Preconditions Retail Pro must have called Initializeon this class before this method can beinvoked.

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

  • 8/14/2019 Plugins Programmers Guide

    30/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    26

    Creating a PluginThe 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 theNew Itemsdialog box, make sure you

    have the tab labeledNewselected and double-click on the Packageicon.

    When the new package is open select File->Save Alland select a location and name for your

    project files.

    Add the plugin design-time packages to your code

    AddRProAPIandRDA2_TLBto the usesclause of your code.

  • 8/14/2019 Plugins Programmers Guide

    31/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    27

    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

    TI nvcUpdat e = class( TOnUpdat e)private

    f I nvoi ce: I RdaDocument ;public

    class function Tabl e: integer; override;procedure I ni t i al i ze( RProApp: TRPr oApp;

    Doc: I RdaDocument) ; override;function Bef oreUpdat e: boolean; override;procedure Af t erUpdate; override;end;

    Select table for the plugin

    The Tablefunction tells Retail Pro when to call a certain plugin. In this example it will be calledfor the Invoices table.

    class function TI nvcUpdate. Tabl e: integer;begin

    Resul t : = t bl I nvoi ces;end;

    Export the plugin class

    Each plugin package must export anRproClassesAvaliableprocedure. This procedure tells Retail

    Pro what classes are available inside the package.

    procedure RProCl assesAvai l abl e(RProCl assAr r ayProc:TRPr oCl assAr r ayPr oc) ;

    begin

    RProCl assAr r ayProc([ TI nvcUpdate] ) ;end;

    Compile the plugin package

    To compile a Delphi package you must click the Compilebutton on the package manager window

    rather than using the Compilecommand off the main menu.

    Place the resulting .bpl file in the plugins directory under the Retail Pro directory.

  • 8/14/2019 Plugins Programmers Guide

    32/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    28

    Appendix A Retail Pro API Code(For Reference ONLY DO NOT COPY THIS CODE.)

    unit RProAPI ;

    interface

    usesRDA2_TLB;

    constAl l Fi el ds = - 100;csCl assesAvai l abl eName = ' RProCl assesAvai l abl e' ;

    typeTRPr oCl assAr r ayPr oc =procedure( Cl asses: array of TCl ass);TRPr oCl assesAvai l abl ePr oc =procedure( RProCl assAr r ayProc: TRProCl assAr r ayProc);

    TSi deMenu = ( smDepart ment s, smVendor s, smCust omer s, smI nvent or y,smRecei pt s, smRecei pt Li st ,

    smVoucher s, smVoucher Li st ,smMemos, smMemoLi st ,smSl i p, smSl i pLi st,smSO, smSOLi st ,smPO, smPOLi st ,smTO, smTOLi st ,smTender) ;

    TAct i onRequest = ( ar Ref r eshDocument , ar Ref r eshLi st ) ;TAct i onRequest Set = set of TAct i onRequest ;

    TCust omFi el dType = ( cf t St r i ng, cf t I nt eger , cf t Doubl e, cf t Quant i t y, cf t Cur r ency,cf t Date, cf t Ti me, cf t Dat eTi me) ;

    TRPr oApp = classfunction Cr eat eTabl eByI D( Tabl eI D: Integer) : I RdaTabl e; virtual; abstract;

    function Preferences: IXMLDOMDocument; virtual; abstract;

    procedure Print(const DesignName, PrinterName:string; SuppressPrinterDialog:

    boolean); virtual; abstract;

    end;

    TVal i dateCl ass = class of TVal i dat e;TVal i date = class

    class function Tabl e: integer; virtual; abstract;class function Fi el d: integer; virtual; abstract;procedure I ni t i al i ze( RProApp: TRPr oApp;

    Doc: I RdaDocument) ; virtual; abstract;function Val i date(var Val ue: var i ant ) : bool ean; virtual; abstract;

    end;

    TAf t er Assi gnCl ass = class of TAf t er Assi gn;TAf t er Assi gn = class

    class function Tabl e: i nt eger ; virtual; abstract;procedure I ni t i al i ze( RPr oApp: TRPr oApp;

    Doc: I RdaDocument) ; virtual; abstract;procedure Execute( const F i el dI D: integer) ; virtual; abstract;

    end;

    TOnUpdat eCl ass = class of TOnUpdate;TOnUpdat e = class

    class function Tabl e: integer; virtual; abstract;procedure I ni t i al i ze( RPr oApp: TRPr oApp;

    Doc: I RdaDocument) ; virtual; abstract;function Bef oreUpdat e: bool ean; virtual; abstract;procedure Af t erUpdate; virtual; abstract;

    end;

  • 8/14/2019 Plugins Programmers Guide

    33/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    29

    TI t emAddRemoveCl ass = class of TI t emAddRemove;TI t emAddRemove = class

    class function Tabl e: integer; virtual; abstract;procedure I ni t i al i ze( RProApp: TRPr oApp;

    Doc: I RdaDocument) ; virtual; abstract;function I t emBef oreRemove: bool ean; virtual; abstract;function I t emBef oreAdd( I t emNo: integer) : bool ean; virtual; abstract;

    procedure I t emAf t erAdd; virtual; abstract;end;

    TSi deBut t onCl ass = class of TSi deBut t on;TSi deBut t on = class

    class function Menu: TSi deMenu; virtual; abstract;procedure I ni t i al i ze( RPr oApp: TRPr oApp;

    Doc: I RdaDocument ) ; virtual; abstract;class function Capt i on: str i ng; virtual; abstract;class function Pi ctureFi l eName: st r i ng; virtual; abstract;function Execut e: TAct i onRequest Set ; virtual; abstract;/ / Enabl ed i s cal l ed const ant l y (when RPro i s i dl e) ,/ / so i t shoul dn' t be ti me- consumi ngfunction Enabl ed: bool ean; virtual; abstract;

    end;

    TTender ChangedCl ass = class of TTenderChanged;

    TTender Changed = classprocedure I ni t i al i ze( RPr oApp: TRProApp;

    Doc: I RdaDocument) ; virtual; abstract;procedure TenderScreenEnter ed; virtual; abstract;procedure Changed; virtual; abstract;

    end;

    TOnPr i nt Cl ass = class of TOnPri nt ;TOnPr i nt = class

    class function Tabl e: i nt eger; virtual; abstract;procedure I ni t i al i ze( RPr oApp: TRProApp;

    Doc: I RdaDocument ) ; virtual; abstract;procedure Bef or ePr i nt ( XMLDoc: I XMLDOMDocument) ; virtual; abstract;

    end;

    TCust omFi el dCl ass = class of TCustomFi el d;TCust omFi el d = class

    class function Tabl e: i nt eger; virtual; abstract;procedure I ni t i al i ze( RPr oApp: TRProApp;

    Doc: I RdaDocument ) ; virtual; abstract;class function Fi el dType: TCust omFi el dType; virtual; abstract;class function Fi el dLabel : string; virtual; abstract;class function Fi el dDescr i pt i on: string; virtual; abstract;

    function MaxChars : i nt eger; virtual; abstract; / / 0 f or unl i mi t edfunction I sReadOnl y: bool ean; virtual; abstract;function Get Dat a: var i ant ; virtual; abstract;

    procedure Set Dat a( Val ue: var i ant ) ; virtual; abstract;function LookupLi st : string; virtual; abstract;

    end;

    implementation

    initializationend.

  • 8/14/2019 Plugins Programmers Guide

    34/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    30

    Appendix B Example Code Listing

    Invoice Item Change

    InvoiceItemChange.dpkpackage I nvoi ceI t emChange;

    {$R *. RES}{$ALI GN ON}{$ASSERTI ONS ON}{$BOOLEVAL OFF}{$DEBUGI NFO ON}{$EXTENDEDSYNTAX ON}{$I MPORTEDDATA ON}{$I OCHECKS ON}{$LOCALSYMBOLS ON}{$LONGSTRI NGS ON}{$OPENSTRI NGS ON}

    {$OPTI MI ZATI ON OFF}{$OVERFLOWCHECKS OFF}{$RANGECHECKS OFF}{$REFERENCEI NFO ON}{$SAFEDI VI DE OFF}{$STACKFRAMES OFF}{$TYPEDADDRESS OFF}{$VARSTRI NGCHECKS ON}{$WRI TEABLECONST OFF}{$MI NENUMSI ZE 1}{$I MAGEBASE $400000}{$RUNONLY}{$I MPLI CI TBUI LD OFF}

    requires

    vcl 50,RPRO_API ;

    contains

    uI nvoi ceI t emChange;

    end.

    uInvoiceItemChange.pasunit uI nvoi ceI t emChange;

    interface

    uses

    RProAPI , RDA2_TLB, Di al ogs, SysUt i l s;

    type

    TI nvcI t emNumAss i gned = class( TAf t er Assi gn)private

    f I nvoi ce: I RdaDocument ;f I nvoi ceI t em: I RdaDocument ;f Cust omers : I RdaTabl e;

    public

    class function Tabl e: integer; override;procedure I ni t i al i ze( RProApp: TRPr oApp;

    Doc: I RdaDocument) ; override;procedure Execut e( const F i el dI D: integer) ; override;

    end;

  • 8/14/2019 Plugins Programmers Guide

    35/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    31

    TI nvcI t emAddRemove = class( TI t emAddRemove)private

    f I nvoi ce: I RdaDocument ;f I nvoi ceI t em: I RdaDocument ;

    public

    class function Tabl e: integer; override;procedure I ni t i al i ze( RProApp: TRPr oApp;

    Doc: I RdaDocument) ; override;function I t emBef or eRemove: boolean; override;function I t emBef oreAdd( I t emNo: integer) : boolean; override;procedure I t emAf t erAdd; override;

    end;

    TI nvcI t emNumVal i date = class( TVal i dat e)privatepublic

    class function Tabl e: integer; override;class function Fi el d: integer; override;procedure I ni t i al i ze( RPr oApp: TRPr oApp;

    Doc: I RdaDocument) ; override;function Val i date(var Val ue: var i ant ) : bool ean; override;

    end;

    implementation

    procedure RProCl assesAvai l abl e(RProCl assAr r ayProc: TRProCl assAr r ayProc);begin

    RProCl assArr ayPr oc( [ TI nvcI t emNumAssi gned, TI nvcI t emAddRemove , TI nvcI t emNumVal i dat e] ) ;end;

    exportsRProCl assesAvai l abl e;

    { TI nvcI t emNumAss i gned }

    class function TI nvcI t emNumAssi gned. Tabl e: integer;begin

    Resul t : = nt bl I nvoi ceI t ems;end;

    procedure TI nvcI t emNumAssi gned. I ni t i al i ze( RProApp: TRProApp; Doc: I RdaDocument ) ;

    beginf I nvoi ce : = Doc;f I nvoi ceI t em : = f I nvoi ce. NestedDocByI D[ nt bl I nvoi ceI t ems];f Cust omers : = RProApp. Cr eat eTabl eByI D( t bl Cust omers ) ;f Cust omers. Open;f Cust omers. Act i veI ndexI D : = i dxCust SI D;

    end;

    procedure TI nvcI t emNumAss i gned. Execut e( const F i el dI D: integer) ;var

    I sNul l : Wor dBool ;begin

    if F i el dI D = f i dQty thenf I nvoi ceI t em. Set Doubl e( f I nvoi ceI t em. Get Doubl e( f i dQt y, I sNul l ) + 1, f i dQt y);

    if f Customer s. Fi nd( f I nvoi ce. Get St r i ng( f i dBi l l ToCustSI D, I sNul l ) , t r ue) thenShowMessage(f Customers . Document . GetSt r i ng( f i dFul l Name , I sNul l ) ) ;

    end;

    { TI nvcI t emAddRemove }

    class function TI nvcI t emAddRemove. Tabl e: integer;begin

    Resul t := tbl I nvoi ces;end;

    procedure TI nvcI t emAddRemove. I ni t i al i ze( RProApp: TRProApp;Doc: I RdaDocument) ;

    beginf I nvoi ce : = Doc;

  • 8/14/2019 Plugins Programmers Guide

    36/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    32

    f I nvoi ceI t em : = f I nvoi ce. NestedDocByI D[ nt bl I nvoi ceI t ems];end;

    function TI nvcI t emAddRemove. I t emBef oreRemove: bool ean;var

    I sNul l : Wor dBool ;I t emNo: i nt eger;

    beginI t emNo : = f I nvoi ceI t em. Get I nt eger ( f i dI t emNo, I sNul l ) ;Resul t : = tr ue;if I t emNo = 2 thenbegin

    Resul t : = f al se;ShowMessage(For mat ( ' I t em# %d cannot be r emoved' , [ I t emNo]) ) ;

    endelse

    ShowMessage(For mat ( ' I t em# %d i s removed' , [ I t emNo] ) ) ;end;

    function TI nvcI t emAddRemove. I t emBef oreAdd( I t emNo: integer) : boolean;begin

    Resul t : = tr ue;if I t emNo = 3 thenbegin

    Resul t : = f al se;ShowMessage(For mat ( ' I t em# %d cannot be added' , [ I t emNo] ) ) ;

    end;end;

    procedure TI nvcI t emAddRemove. I t emAf t er Add;var

    I sNul l : Wor dBool ;begin

    ShowMessage(Format( ' I t em# %d i s added' , [ f I nvoi ceI t em. GetI nt eger( f i dI t emNo,I sNul l ) ] ) ) ;end;

    { TI nvcI t emNumVal i date }

    class function TI nvcI t emNumVal i date. Tabl e: integer;begin

    Resul t : = nt bl I nvoi ceI t ems;end;

    class function TI nvcI t emNumVal i date. Fi el d: integer;begin

    Resul t : = f i dI t emLookup;end;

    procedure TI nvcI t emNumVal i dat e. I ni t i al i ze( RProApp: TRProApp; Doc: I RdaDocument ) ;beginend;

    function TI nvcI t emNumVal i date. Val i dat e(var Val ue: var i ant ) : bool ean;begin

    Resul t : = tr ue;case Val ue of

    4:begin

    Resul t : = f al se;ShowMessage( ' I t em# 4 r ej ected' ) ;

    end;5:begin

    Val ue := 6;ShowMessage( ' I t em# 5 r epl aced wi t h I t em # 6' ) ;

    end;end;

    end;end.

  • 8/14/2019 Plugins Programmers Guide

    37/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    33

    PrintInvoice

    PrintInvoice.dpkpackage Pri nt I nvoi ce;

    {$R *. RES}{$ALI GN ON}{$ASSERTI ONS ON}{$BOOLEVAL OFF}{$DEBUGI NFO ON}{$EXTENDEDSYNTAX ON}{$I MPORTEDDATA ON}{$I OCHECKS ON}{$LOCALSYMBOLS ON}{$LONGSTRI NGS ON}{$OPENSTRI NGS ON}{$OPTI MI ZATI ON OFF}{$OVERFLOWCHECKS OFF}{$RANGECHECKS OFF}{$REFERENCEI NFO ON}

    {$SAFEDI VI DE OFF}{$STACKFRAMES OFF}{$TYPEDADDRESS OFF}{$VARSTRI NGCHECKS ON}{$WRI TEABLECONST OFF}{$MI NENUMSI ZE 1}{$I MAGEBASE $400000}{$I MPLI CI TBUI LD OFF}

    requires

    vcl 50,RPRO_API ;

    contains

    uPr i nt I nvoi ce;

    end.

    uPrintInvoiceunit uPr i nt I nvoi ce;

    interface

    uses

    Wi ndows, RProAPI , RDA2_TLB, Di al ogs, SysUt i l s, MSXML_TLB, Shel l API ;

    type

    TI nvcUpdat e = class( TOnUpdat e)private

    f I nvoi ce: I RdaDocument ;public

    classfunction

    Tabl e: i nt eger;override

    ;procedure I ni t i al i ze( RProApp: TRPr oApp;Doc: I RdaDocument) ; override;

    function Bef oreUpdate: bool ean; override;procedure Af t erUpdate; override;

    end;

    TI nvoi cePr i nt = class( TOnPr i nt )private

    f I nvoi ce: I RdaDocument ;public

    class function Tabl e: i nt eger; override;

  • 8/14/2019 Plugins Programmers Guide

    38/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    34

    procedure I ni t i al i ze( RProApp: TRPr oApp;Doc: I RdaDocument) ; override;

    procedure Bef or ePr i nt ( XMLDoc: I XMLDOMDocument ) ; override;end;

    implementation

    procedure RProCl assesAvai l abl e(RProCl assAr r ayProc: TRProCl assAr r ayProc);begin

    RProCl assAr r ayProc([ TI nvcUpdate] ) ;end;

    exportsRProCl assesAvai l abl e;

    { TI nvcUpdat e }

    class function TI nvcUpdate. Tabl e: integer;begin

    Resul t := tbl I nvoi ces;end;

    procedure TI nvcUpdate. I ni t i al i ze( RProApp: TRProApp; Doc: I RdaDocument ) ;begin

    f I nvoi ce : = Doc;end;

    function TI nvcUpdate. Bef oreUpdat e: boolean;var

    I sNul l : wordbool ;begin

    if f I nvoi ce. Get Doubl e( f i dTot al , I sNul l ) > 100 thenbegin

    Resul t : = f al se;ShowMessage( ' Recei pt s > $100 are not al l owed' ) ;

    endelse

    Resul t : = tr ue;end;

    procedure TI nvcUpdate. Af t erUpdat e;

    varXMLI nvoi ce: I XMLDOMDocument ;

    beginXMLI nvoi ce : = f I nvoi ce. XMLDOMDocument ( f al se) ;XMLI nvoi ce. save( ' i nvoi ce. xml ' ) ;Shel l Execut e(0, ' open' , ' i nvoi ce. xml ' , ' ' , ' ' , SW_SHOWNORMAL) ;Del eteFi l e( ' i nvoi ce. xml ' ) ;

    end;

    { TI nvoi cePri nt }

    class function TI nvoi cePri nt . Tabl e: i nt eger ;begin

    Resul t : = tbl I nvoi ces ;end;

    procedure TI nvoi cePri nt . I ni t i al i ze(RPr oApp: TRProApp; Doc: I RdaDocument ) ;beginf I nvoi ce : = Doc;

    end;

    procedure TI nvoi cePri nt . Bef orePri nt ( XMLDoc: I XMLDOMDocument ) ;begin

    XMLDoc. document El ement . setAt t r i but e(' PI ' , 3. 14) ;end;

    end.

  • 8/14/2019 Plugins Programmers Guide

    39/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    35

    InvoiceButton

    InvoiceButton.dpkpackage I nvoi ceBut t on;

    {$R *. RES}{$ALI GN ON}{$ASSERTI ONS ON}{$BOOLEVAL OFF}{$DEBUGI NFO ON}{$EXTENDEDSYNTAX ON}{$I MPORTEDDATA ON}{$I OCHECKS ON}{$LOCALSYMBOLS ON}{$LONGSTRI NGS ON}{$OPENSTRI NGS ON}{$OPTI MI ZATI ON OFF}{$OVERFLOWCHECKS OFF}{$RANGECHECKS OFF}{$REFERENCEI NFO ON}{$SAFEDI VI DE OFF}

    {$STACKFRAMES OFF}{$TYPEDADDRESS OFF}{$VARSTRI NGCHECKS ON}{$WRI TEABLECONST OFF}{$MI NENUMSI ZE 1}{$I MAGEBASE $400000}{$RUNONLY}{$I MPLI CI TBUI LD OFF}

    requires

    vcl 50,RPRO_API ;

    contains

    uI nvoi ceBut t on;

    end.

    uInvoiceButton.pasunit uI nvoi ceBut t on;

    interface

    usesWi ndows, RProAPI , RDA2_TLB, SysUt i l s;

    typeTI nvoi ceBut t on = class( TSi deBut t on)Private

    f RProApp: TRProApp;f I nvoi ce: I RdaDocument ;

    publicclass function Menu: TSi deMenu; override;procedure I ni t i al i ze( RProApp: TRPr oApp;

    Doc: I RdaDocument) ; override;class function Capt i on: str i ng; override;class f uncti on Pi ctureFi l eName: st r i ng; override;function Execut e: TAct i onRequest Set ; override;function Enabl ed: bool ean; override;

    end;TTender But t on = class( TSi deBut t on)private

    f I nvoi ce: I RdaDocument ;

  • 8/14/2019 Plugins Programmers Guide

    40/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    36

    public

    class function Menu: TSi deMenu; override;procedure I ni t i al i ze( RProApp: TRPr oApp;

    Doc: I RdaDocument) ; override;class function Capt i on: string; override;class function Pi ct ur eFi l eName: string; override;function Execut e: TAct i onRequest Set ; override;

    function Enabl ed: bool ean; override;end;

    TTender Moni t or = class( TTender Changed)private

    f Tender: I RdaTender;public

    procedure I ni t i al i ze( RProApp: TRPr oApp;Doc: I RdaDocument) ; override;

    procedure TenderScreenEnter ed; override;procedure Changed; override;

    end;

    implementation

    procedure RProCl assesAvai l abl e(RProCl assAr r ayProc: TRProCl assAr r ayProc);begin

    RPr oCl assAr r ayPr oc( [ TI nvoi ceBut t on] ) ;end;

    exportsRProCl assesAvai l abl e;

    { TI nvoi ceBut t on }

    class function TI nvoi ceButt on. Menu: TSi deMenu;begin

    Resul t : = smRecei pt s;end;

    class function TI nvoi ceBut t on. Capt i on: st r i ng;begin

    Resul t : = ' CustomButt on' ;end;

    procedure TI nvoi ceBut t on. I ni t i al i ze(RProApp: TRProApp; Doc: I RdaDocument ) ;begin

    f RProApp : = RproApp;f I nvoi ce : = Doc;

    end;

    function TI nvoi ceButt on. Execut e: TAct i onRequest Set ;begin

    / / \ \ CORDELI A\ RD1f RProApp. Pr i nt ( ' Recei pt , Let t er ' , ' ' , f al se) ;f I nvoi ce. SetSt r i ng( ' Cust omComment ' , f i dI nvcComment 1) ;Resul t : = [ arRefr eshDocument ] ;

    end;

    class function TI nvoi ceBut t on. Pi ctureFi l eName: st r i ng;begin

    Resul t : = ' gl obal di scount . bmp' ;end;

    function TI nvoi ceBut t on. Enabl ed: bool ean;var

    h, m, sec, msec: word;begin

    DecodeTi me(Ti me, h, m, sec, msec) ;Resul t : = sec < 50;

    end;

    { TTender But t on }

  • 8/14/2019 Plugins Programmers Guide

    41/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    37

    class function TTender But t on. Menu: TSi deMenu;begin

    Resul t : = smTender;end;

    class function TTenderBut t on. Capt i on: string;begin

    Resul t : = ' Credi t 2 Dol l ars ' ;end;

    procedure TTenderBut t on. I ni t i al i ze( RProApp: TRProApp; Doc: I RdaDocument ) ;begin

    f I nvoi ce : = Doc;end;

    function TTenderBut t on. Execut e: TAct i onRequest Set ;var

    Tender : I RdaTender ;Card: I RdaCr edi t Card;

    TndrI t em: I Di spat ch;begin

    Tender : = f I nvoi ce. Cust omI nt er f ace as I RdaTender ;TndrI t em : = Tender . AddI t em( t t Cr edi t Car d) ;Car d : = Tndr I t em as I RdaCr edi t Car d;

    / / Card. Amount : = 2;Car d. Car dType : = ' VI SA' ;Card. CardNumber : = ' 12345' ;Card. ExpMont h : = 9;Card. ExpYear : = 03;Resul t : = [ arRefr eshDocument ] ;

    end;

    class function TTenderBut t on. Pi ct ur eFi l eName: string;begin

    Resul t : = ' gl obal di scount . bmp' ;end;

    function TTenderBut t on. Enabl ed: boolean;begin

    Resul t : = tr ue;end;

    { TTenderMoni t or }

    procedure TTenderMoni t or. I ni t i al i ze( RProApp: TRProApp; Doc: I RdaDocument ) ;begin

    f Tender : = Doc. Cust omI nt erf ace as I RdaTender;end;

    procedure TTenderMoni t or . Tender ScreenEnter ed;begin

    ShowMessage( ' Tender s ent ered' ) ;end;

    procedure TTender Moni t or . Changed;var

    I t em: I Unknown;f c: I RdaFC;

    begin

    ShowMessage( I ntToSt r ( f Tender. Tender I t ems. l engt h)) ;if f Tender. Undefi ned < 0 thenbegin

    I t em : = f Tender . AddI t em( t t FC) ;f c : = I temas I RdaFC;f c. Amount : = f Tender. Undef i ned;f c. FCAmount : = 1000;f c. FCName : = ' ROUBLES' ;

    end;end;end.

  • 8/14/2019 Plugins Programmers Guide

    42/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    38

    InvoiceField

    InvoiceField.dpkpackage I nvoi ceFi el d;

    {$R *. RES}{$ALI GN ON}{$ASSERTI ONS ON}{$BOOLEVAL OFF}{$DEBUGI NFO ON}{$EXTENDEDSYNTAX ON}{$I MPORTEDDATA ON}{$I OCHECKS ON}{$LOCALSYMBOLS ON}{$LONGSTRI NGS ON}{$OPENSTRI NGS ON}{$OPTI MI ZATI ON OFF}{$OVERFLOWCHECKS OFF}{$RANGECHECKS OFF}{$REFERENCEI NFO ON}{$SAFEDI VI DE OFF}

    {$STACKFRAMES OFF}{$TYPEDADDRESS OFF}{$VARSTRI NGCHECKS ON}{$WRI TEABLECONST OFF}{$MI NENUMSI ZE 1}{$I MAGEBASE $400000}{$I MPLI CI TBUI LD OFF}

    requires

    vcl 50,RPRO_API ;

    contains

    uI nvoi ceFi el d;

    end.

  • 8/14/2019 Plugins Programmers Guide

    43/44

    Retail Pro8 Plugins Programmers Guide

    Copyright 2008 Retail Pro. All rights reserved.

    39

    uInvoiceField.pasunit uI nvoi ceFi el d;

    interface

    uses

    Wi ndows, Cl asses, RProAPI , RDA2_TLB, Di al ogs, SysUt i l s, MSXML_TLB, Shel l API ;

    type

    TI nvcWr appi ngKi nd = class( TCust omFi el d)private

    f I nvoi ce: I RdaDocument ;f Dat a: TSt r i ngLi st;

    public

    class f uncti on Tabl e: i nt eger ; override;procedure I ni t i al i ze( RProApp: TRPr oApp;

    Doc: I RdaDocument) ; override;destructor Destr oy; override;class function Fi el dType: TCust omFi el dType; override;class function Fi el dLabel : string; override;class function Fi el dDescri pt i on: string; override;function MaxChars : i nt eger; override;function I sReadOnl y: bool ean; override;function Get Dat a: var i ant ; override;procedure SetData(Val ue: vari ant ) ; override;function LookupLi st: str i ng; override;

    end;

    implementation

    const

    csFi l eName = ' wr appi ngs. t xt' ;

    procedure RProCl assesAvai l abl e(RProCl assAr r ayProc: TRProCl assAr r ayProc);begin

    RProCl assAr r ayProc([ TI nvcWr appi ngKi nd] ) ;end;

    exports

    RProCl assesAvai l abl e;

    { TI nvcWr appi ngKi nd }

    class function TI nvcWr appi ngKi nd. Tabl e: i nt eger;begin

    Resul t : = tbl I nvoi ces ;end;

    procedure TI nvcWr appi ngKi nd. I ni t i al i ze( RProApp: TRProApp; Doc: I RdaDocument ) ;begin

    f I nvoi ce : = Doc;f Data : = TSt r i ngLi st . Create;try

    f Data. LoadFromFi l e(csFi l eName);except

    end;

    end;

    destructor TI nvcWr appi ngKi nd. Dest r oy;begin

    f Data. SaveToFi l e(csFi l eName);f Data. Free;inherited;

    end;

    class function TI nvcWr appi ngKi nd. Fi el dLabel : string;begin

    Resul t : = ' Wrappi ng' ;

  • 8/14/2019 Plugins Programmers Guide

    44/44

    Retail Pro8 Plugins Programmers Guide

    end;

    class function TI nvcWr appi ngKi nd. Fi el dDescr i pt i on: string;begin

    Resul t : = ' Wr appi ng type used for t he Recei pt ' ;end;

    class function TI nvcWr appi ngKi nd. Fi el dType: TCust omFi el dType;begin

    Resul t : = cf tSt r i ng;end;

    function TI nvcWr appi ngKi nd. I sReadOnl y: bool ean;var

    I sNul l : Wor dBool ;begin

    Resul t : = f I nvoi ce. Get I nt eger( f i dBi l l ToCustI D, I sNul l ) = 0; / / al l ow onl y Recei pt s wi t hcust omerend;

    function TI nvcWr appi ngKi nd. MaxChar s: i nt eger;begin

    Resul t : = 0;end;

    function TI nvcWr appi ngKi nd. GetData: var i ant ;var

    I sNul l : Wor dBool ;begin

    Resul t : = f Dat a. Val ues[I nt ToSt r ( f I nvoi ce. Get I nt eger( f i dI nvcNum, I sNul l ) ) ] ;end;

    procedure TI nvcWr appi ngKi nd. SetData( Val ue: var i ant ) ;var

    I sNul l : Wor dBool ;begin

    f Dat a. Val ues[I nt ToSt r( f I nvoi ce. Get I nt eger( f i dI nvcNum, I sNul l ) ) ] : = Val ue;end;

    function TI nvcWr appi ngKi nd. LookupLi st : string;begin

    Resul t : = ' Bi r t hday, Chri stmas, Val ent i ne' ;end;

    end.

Embed Size (px)
Recommended