Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print receipt? 3

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
578
PH
Hi everyone... i want to print a receipt everytime a customer pay just like POS... with these codes I've done, it shows all transaction in a day, may i just ask help if how am i going to print directly to printer each transaction? and without preview... Thanks...

code...
code....

DO CASE
CASE UPPER(This.Parent.cboSFBBU.List(This.Parent.cboSFBBU.ListIndex,1)) = "Miscellaneous" AND this.parent.cbopp1.VALUE = 1

Kumperm = MESSAGEBOX("Please click OK button to confirm PAYMENT of " + CHR(13) + ;
"Miscellaneous!" + " for " + ALLTRIM(tsulat.sname) + ", " + ALLTRIM(tsulat.fname) + CHR(13) + ;
"Php " + ALLTRIM(TRANSFORM(this.parent.text14.value, "###,###,###.##")),1+32+4096,"Information!")

IF kumperm = 1

SELECT trans
IF FLOCK()
APPEND BLANK
REPLACE IDNUM WITH csrDemo.idnum;
transcode WITH "MS";
transtype WITH "PAYMENT";
TRANSAMT WITH this.parent.text14.value;
DEYT WITH DATETIME();
IN trans

REPLACE tsulat.Misc WITH tsulat.Misc + this.Parent.text14.value IN tsulat

*------------------------------------------------------------------------------------------- &&

SELECT trans

Select * From trans INTO CURSOR resibo

REPORT FORM receipt FOR resibo.deyt =< DATE() TO PRINTER PROMPT PREVIEW
WAIT



*------------------------------------------------------------------------------------------- &&

*MESSAGEBOX("Payment " + ALLTRIM(TRANSFORM(this.parent.text14.value, "###,###,###.##")) + " Recorded!",0+64,"Information!")


WITH This
.Enabled = .F.
.Refresh()
ENDWITH

UNLOCK IN trans

-------------------------------------------------------------------- &&

ELSE
WAIT WINDOW 'Unable to open MISCELLANEOUS Table; try again later!' NOWAIT
ENDIF
ELSE
RETURN
ENDIF
 
Hi

First thing I see...

Code:
CASE UPPER(This.Parent.cboSFBBU.List(This.Parent.cboSFBBU.ListIndex,1)) = "Miscellaneous" AND this.parent.cbopp1.VALUE = 1

Can never be true, your "Miscellaneous" is mixed case and you are specifying UPPER( in the line to the left of it, thus that needs to be

Code:
CASE UPPER(This.Parent.cboSFBBU.List(This.Parent.cboSFBBU.ListIndex,1)) = "MISCELLANEOUS" AND this.parent.cbopp1.VALUE = 1


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
I think this is what you are looking for?

Code:
REPORT FORM receipt FOR resibo.deyt =< DATE() .and. IDNUM = csrDemo.idnum TO PRINTER NOCONSOLE

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Hi Griff... thanks for your answer... but what happen all transaction were in the report during the date... i only want to print the single transaction... just like in POS... after paying it should print a receipt... thanks griff.
 
Well, Mandy...

...which records do you want to print? That's what you need to be able to specify and we can't help you with that not knowing what limits the data.

Griff has already made the guess that adding the condition .and. IDNUM = csrDemo.idnum would limit the data printed.

There is something that seems not right to me at this point:
Code:
[highlight #FCE94F]Select * From trans INTO CURSOR resibo[/highlight]

REPORT FORM receipt FOR resibo.deyt =< DATE() TO PRINTER PROMPT PREVIEW
This selects all records of trans into the report cursor resibo. If you only want to print the last record you added above with...
Code:
APPEND BLANK
REPLACE IDNUM WITH csrDemo.idnum;
transcode WITH "MS";
transtype WITH "PAYMENT";
TRANSAMT WITH this.parent.text14.value;
DEYT WITH DATETIME();
IN trans
...then the condition IDNUM= csrDemo.idnum should limit the printing to exactly that new record. If it doesn't then it seems the IDNUM stays the same for many records. Then there is something wrong with creating sequential or otherwise unique non-repeating IDNUM values earlier in the code that sets crsDemo.idnum.

Besides that, it's very ineffective to copy all data into the report cursor resibo when you don't want to print all data. The least you could do is use the FOR condition of the REPORT FORM command and already limit the records you copy to the cursor resibo by using it as the WHERE clause of the select:

Code:
Select * From trans [highlight #FCE94F]WHERE trans.deyt =< DATE()[/highlight] INTO CURSOR resibo

REPORT FORM receipt [s]FOR resibo.deyt =< DATE()[/s] TO PRINTER PROMPT PREVIEW

That does not change anything to the amount of printed data, but it is a first step. You need a more restrictive condition here. The condition =<DATE() means all data of today or any earlier day. Which usually is all data because you won't have records from future days. There's just one detail to recognize here: The deyt field is a datetime field and you store DATETIME() into records you create. Then the condition Deyt=<DATE() selects all records except all records of today. The condition resibo.deyt > DATE() would be more to the point, but it would still be all data from today, not just the last sale.

What I can't tell you is which condition limits the data to what you want to print. The best idea for it still is using the IDNUM for that. What needs to be fixed then is generating an IDNUM already in crsDemo where it comes from. And if it shouldn't come from there, then don't copy it over in your REPLACE IDNUM WITH csrDemo.idnum.

If that becomes unique you can select that one new record with
Code:
Select * From trans [highlight #FCE94F]WHERE trans.idnum = crsDemo.idnum[/highlight] INTO CURSOR resibo

If the data to print is multiple records, then what you need is a field in trans that identifies all records that belong into one sale, i.e. all items of that sale, with one unique identifier that can be used to only select this data.

One more usual way to do a POS sale is to collect all current sales data into a new cursor and print that. Only after that's paid and the receipt is printed, you add that sales data into the transactions table to finish the sale, not beforehand. Then it's far easier to know what records belong into the receipt, it's simply all data of that new sales cursor. All data that didn't yet go into trans.dbf and are new, therefore. That also works when there are multiple cash registers working in parallel as every session has it's own separate sales data cursor.

Chriss
 
Mandy,

You also asked how to print without a preview. That's easy. Just leave out the PREVIEW keyword in your REPORT FORM command. And also add NOCONSOLE to prevent the report appearing on the background screen:

[tt]REPORT FORM receipt FOR resibo.deyt =< DATE() ;
TO PRINTER PROMPT PREVIEW NOCONSOLE[/tt]

Also, you might want to leave out the PROMPT clause. That will prevent the user seeing a "choose printer" dialogue, assuming that you will always print to your receipt printer.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks so much Chriss!!! What I did is created a temp cursor, appended blank and populated my form from the temp cursor.... and guala! i have it!!! Thanks for teaching me always! Gdo bless!
 
Thanks Mike! Yes I did that also Mike... Thank you very much.... God Bless!
 
The REPORT command already was TO PRINTER and without PREVIEW.

There's yet another way to print just the current record of a table, instead of any FOR clause use
Code:
REPORT FORM yourreport.frx [highlight #FCE94F]NEXT 1[/highlight]

I don't know your report, if report controls in it have expressions addressing an alias name like resibo you always need to have such a workarea as currently selected. If the report addresses fields merely by their name your workarea can be anything that has the same fields necessary to print or you could print the current record of trans with NEXT 1, just don't create resibo at all and don't select anything else, after APPEND BLANK you stay on the new record unless you would do something that moves the record pointer.

Clauses like TO PRINTER are optional at least in VFP, as - by default - printing goes to the default printer or a printer you specify by SET PRINTER TO NAME printername or it goes to the printer embedded in the report as printer environment, if you save that during the design.

So all in all you could get away without an additional cursor, depends on how the report is designed. From what we can see from here it could well be that the report design is specific to the alias name resibo. No need to change that, if it works now, but it's worth knowing.

On the other hand, if you want things as easy as they can be, there are two major ways of printing: You either make your report without any data environment in itself and control it from outside by providing the data in a report cursor you generate ahead of printing it, which is what this looks like. So you already did that, you just didn't limit the data correctly.

Or you make the report completely independent from any outside influence and let the report data environment get the necessary data. It often isn't capable to know what portion of data you want, so there still is the need to pass in information about which records to print, but that doesn't need to be a FOR clause or other scope like the NEXT 2 records or a WHILE clause (well, look into the help, there are many optional clauses). The report itself and its dataenvironment runs in the scope of the method calling it, so you can access any variables in scope, also local variables. On top of being able to define report variables and define how they are intialised and what calculation is made in them (count, sum, etc.) from row to row of a report detail band.

Chriss
 
Hi Chriss... thank you so much for that substantial explanation... I know i am just a beginner, but with all your help here i am able to go on with my project... thanks and God bless
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top