Beruflich Dokumente
Kultur Dokumente
Programmers Guide
Table of Contents
1.0 INTRODUCTION................................................................................................................... 3
2.0 ENVIRONMENT .................................................................................................................... 3
2.1 RUNNING RETAIL PRO WITH PLUGINS............................................................................................ 3
2.1.1 Version ................................................................................................................................ 3
2.1.2 Files .................................................................................................................................... 3
2.2 DIRECTORY STRUCTURE................................................................................................................ 3
3.0 DEVELOPMENT ENVIRONMENT.......................................................................................... 4
3.1 WHAT YOU NEED ....................................................................................................................... 4
3.2 SETTING UP YOUR DEVELOPMENT ENVIRONMENT ........................................................................... 4
3.2.1 Install and set up Delphi ......................................................................................................... 4
3.2.2 Install and Register RDA2 ...................................................................................................... 4
3.3.3 Make Packages Available to Delphi............................................................................................ 4
4.0 ANATOMY OF A PLUGIN ...................................................................................................... 6
4.1 OVERVIEW ................................................................................................................................. 6
4.2 THE PACKAGE FILE...................................................................................................................... 6
4.3 COMMON METHODS .................................................................................................................... 6
4.3.1 Initialize Method ................................................................................................................... 6
4.3.2 Table Method ........................................................................................................................ 7
4.4 THE TRPROAPP CLASS ................................................................................................................ 8
4.4.1 CreateTableByID Method ........................................................................................................ 8
4.4.2 Preferences Method ................................................................................................................ 8
4.4.3 Print Method ........................................................................................................................ 9
4.5 BASE CLASSES IN DETAIL ............................................................................................................ 10
4.5.1 TValidate............................................................................................................................ 10
4.5.1.1 Field Method ............................................................................................................... 10
4.5.1.2 Validate Event Method................................................................................................. 11
4.5.2 TAfterAssign ...................................................................................................................... 12
4.5.2.1 Execute Event Method ................................................................................................. 12
4.5.3 TOnUpdate ........................................................................................................................ 12
4.5.3.1 BeforeUpdate Event Method......................................................................................... 13
4.5.3.1 AfterUpdate Event Method .......................................................................................... 13
4.5.4 TItemAddRemove ................................................................................................................ 13
4.5.4.1 ItemBeforeRemove Event Method................................................................................. 14
4.5.4.2 ItemBeforeAdd Event Method ...................................................................................... 14
4.5.4.3 ItemAfterAdd Event Method ........................................................................................ 14
4.5.5 TSideButton ....................................................................................................................... 15
4.5.5.1 Menu Method.............................................................................................................. 15
4.5.5.2 Caption Method........................................................................................................... 16
4.5.5.3 PictureFileName Method.............................................................................................. 16
4.5.5.4 Enabled Method .......................................................................................................... 16
4.5.5.5 Execute Event Method ................................................................................................. 17
4.5.6 TTenderChanged ................................................................................................................. 17
1.0 Introduction
A new feature in Retail Pro version 8 is the ability to use custom plugins to improve functionality and
usability of Retail Pro. Plugins for Retail Pro version 8 is comparable to Custom DLLs for version 7.
Custom plugins can be obtained through contract with RTIs Custom Programming department. However,
since the plug-in API is open, anyone with sufficient knowledge about Delphi programming and Retail Pro
can create plug-ins.
This document is intended to give an overview of how set up the development environment and create
custom plugins.
Before you start programming plugins you should be familiar with the following subjects:
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. See separate documentation of
RDA2.
2.0 Environment
2.1 Running Retail Pro With Plugins
2.1.1 Version
You must have Retail Pro version 8.22 or above to use plug-ins. New plug-in classes become available
from time to time. In order to ensure complete compatibility with Retail Pro, it is recommended that you
always use the latest Retail Pro update and associated files.
2.1.2 Files
The files are located in the base level of the Retail Pro installation (i.e. the same level you will find
RPro8.exe).
RPro8.exe Version 8.22 or above.
RDA2.dll
RPRO_API.bpl
ms_ie_d5.bpl
vcl50.bpl
vclie50.bpl
Or
2) 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).
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.
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 the Table function.
RProApp
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.
Doc
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.
Post Conditions The plugin class is instantiated and ready for its other methods to be called.
Comments
Description
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.
Return Value
The function must return an integer value that is the RDA2 table ID, or nested
document ID.
Preconditions
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.
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.
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.
Description
TableID
Return Value
Description
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.
Return Value
An XML DOM Document object that holds information about the current Retail Pro
preferences.
Description
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.
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 printer dialog 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, if that is not
set the default system printer will be used.
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.
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 will call the
Validate function for all input destined for the field whos ID is returned by this
function.
Preconditions
Retail Pro must have called Initialize on this class before this method can be invoked.
This method is only called when a field is updated by a manual entry, not internally by
Retail Pro itself.
Description
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
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 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.
Preconditions
Retail Pro must have called Initialize on this class before this method can be invoked.
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.
4.5.2 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.
Description
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
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 be invoked.
This method is only called when a field is updated by a manual entry, not internally by
Retail Pro itself.
4.5.3 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.
Description
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.
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 before the update
event was triggered.
Preconditions
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.
Description
This procedure is called by Retail Pro right after a document of the selected table has
been saved.
Preconditions
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.
4.5.4 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.
This function is called right before an item is to be removed. The plugin can decide
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 be invoked.
There must be at east one item (nested document) added to the current document.
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.
ItemNo
This is the Retail Pro item number of the item that is about to be added.
Return Value
If the function returns True, Retail Pro will add the item, if False the item will be
discarded.
Preconditions
Retail Pro must have called Initialize on this class before this method can be invoked.
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.
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 be invoked.
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.
4.5.5 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.
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 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.
Description
This function tells Retail Pro what the caption of the custom button should be.
Return Value
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.
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 /Plugins directory.
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 string pointing to a valid bitmap file.
Description
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 Value
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.
Description
This function is called from Retail Pro when the user clicked the custom button.
Return Value
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.
4.5.6 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.
Description
Is called by Retail Pro whenever the user enters the Tender screen, for example when
tendering a new invoice.
Preconditions
Retail Pro must have called Initialize on this class before this method can be invoked.
Description
Is called by Retail Pro whenever the user changes the information on the tender
screen. When a tender line is added or deleted.
Preconditions
Retail Pro must have called Initialize on this class before this method can be invoked.
4.5.7 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.
Description
Tells Retail Pro what type of field this is so it can be formatted correctly on screen.
Return Value
Return a value of the type TCustomFieldType. This type can have the following values
are possible:
cftString
cftInteger
cftDouble
cftQuantity
cftCurrency
cftDate
cftTime
cftDateTime
Preconditions
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.
Description
Tells Retail Pro what the label to display for the field.
Return Value
Preconditions
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.
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 Value
Preconditions
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.
Description
Sets the maximum number of characters that retail pro will allow to be entered 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 be invoked.
Description
If this function is set to true, Retail Pro will not allow the user to edit this field.
Return Value
Preconditions
Retail Pro must have called Initialize on this class before this method can be invoked.
Description
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 Value
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.
Preconditions
Retail Pro must have called Initialize on this class before this method can be invoked.
Description
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 Value
Return a variant type with the value that Retail Pro should display.
Preconditions
Retail Pro must have called Initialize on this class before this method can be invoked.
Post conditions The return value is a valid variant value with a variant type that can be converted and
displayed according to the FieldType.
Description
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.
Value
A parameter of variant type that contains the new value that the user
entered/selected.
Preconditions
Retail Pro must have called Initialize on this class before this method can be invoked.
4.5.8 TOnPrint
TOnPrint = class
class function Table: integer; virtual; abstract;
procedure Initialize(RProApp: TRProApp;
Doc: IRdaDocument); virtual; abstract;
procedure BeforePrint(XMLDoc: IXMLDOMDocument); virtual; abstract;
end;
The TOnPrint class can be used to intercept when a document is about to b printed, from its event
method BeforePrint 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.
Description
XMLDoc
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.
Preconditions
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.
Post conditions The XMLDoc parameter references a valid XML Dom Document object containing the
document information to be printed.
When the new package is open select File->Save All and select a location and name for your project files.
After a successful compilation, place the resulting .bpl file in the plugins directory under the Retail Pro
directory.
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;
TInvcItemAddRemove = class(TItemAddRemove)
private
fInvoice: IRdaDocument;
fInvoiceItem: IRdaDocument;
public
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.
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;
procedure Initialize(RProApp: TRProApp;
Doc: IRdaDocument); override;
procedure BeforePrint(XMLDoc: IXMLDOMDocument); override;
end;
implementation
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;
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 }
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.
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.
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';
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.