>Hi Hillmar,
>would you like explain to me step by step, how can i print my invoice via your text report class ?
>
>TIA
OK, I already sent a basic outline, but I will give you more details here, including the usual debugging process. Please ask again if anything is not clear, or if you need additional options.
1) Create a class based on the Text Report class. Let's assume you call it cInvoice.
2) The user will probably interact with the system with some form. From this form, invoke the class like this:
CreateObject("cInvoice", lnDestination, lnInvoice)
where lnDestination indicates the destination (preview, print, and some other options - see the example included in the download),
and lnInvoice is the primary key of your invoice. Note that the CreateObject() will run the class immediately. I had planned to change this, to make it more object-oriented, but this is the way it works now.
3) Accept the parameter in your cInvoice class, in the Init() method. Save the invoice number to a property, which you have to add. For example:
lparameters tnDestination, tnInvoice
This.nInvoice = tnInvoice
...
DoDefault(tnDestination)
4) Prepare the data in the .Select() method. This may be one SELECT - SQL command, several of them, or any other command which you would use to create a table. For example:
select InvoiceId, InvoiceNumber, Date;
from Invoice;
where InvoiceId = This.nInvoice;
into cursor TempReport;
nofilter
select TempReport.*, id.Product, id.Quantity, id.Price;
from TempReport join InvoiceDetail id;
on TempReport.InvoiceId = id.InvoiceId;
into cursor TempReport
browse normal
cancel
5) Eliminate the last two commands from the .Select() method, and print the line details. The .Detail() method will execute once for each record. In the .Detail() method, use commands like:
.PrintLine(Product, transform(Quantity, "###,###.##"),;
transform(Price, "###,###.##"))
Notes:
The comma will insert an additional space, just like the "?" and "??" commands.
You can also concate strings with "+", but it is better to include separate fields as separate parameters; this way, the output to Excel (which is also supported by the class) will work correctly.
You should NOT use the ? and ?? commands. If you do, several details won't work. For a start, the class will not know how the line and column position. Also, I was planning to change to LLFF eventually, to avoid certain problems. Use the wrapper functions (.Print() and .PrintLine()) instead.
Test your results so far.
6) Add commands to the .PageHeader(), for the invoice header and the column headers. For example:
This.Print("Invoice # ...")
This.PrintLine("Date: ", Date)
This.PrintLine()
This.PrintLine("Product", "Quantity", "Price")
This.PrintLine()
Try it, and adjust the spacing.
HTH,
Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)