report, how compute last page

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
dragancesu
Posts: 931
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

report, how compute last page

Post by dragancesu »

There is a small program in the attachment, it makes many pages of the report, but how to calculate how many pages there will be, I would like to show on each page

Page current_page / last_page

How did you do ?
Attachments
paging.zip
(30.85 KiB) Downloaded 118 times
User avatar
serge_girard
Posts: 3420
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: report, how compute last page

Post by serge_girard »

Dragan,

What I do is simple: perform all loops without printing and count pages. Then GO TOP and restart looping....

Serge
There's nothing you can do that can't be done...
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: report, how compute last page

Post by Rathinagiri »

If your report details can fit in a single line or equal to the same exactly for each record, then you can estimate the number of pages by finding the lines per page and total count of lines.

However, if the lines per record is different for each record, then I think Serge's idea may be the only solution.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
dragancesu
Posts: 931
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: report, how compute last page

Post by dragancesu »

thanks for advices

I usually use PREVIEV and that is my problem, it shows and I don't need it the first time
I had to "find" the command ABORT PRINTDOC to break the first loop
Attachments
REP_1.zip
(1.83 KiB) Downloaded 90 times
User avatar
serge_girard
Posts: 3420
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: report, how compute last page

Post by serge_girard »

412 PAGES
Perhaps you can skip a lot of variables in the counting and in hdr_8560....


Code: Select all

/*
 * This program is generated by HMGCASE
 * developed by Dragan Cizmarevic < dragancesu(at)gmail.com > 
 * created at 03.06.2021 13:29:17
 */
#include "hmg.ch"

Procedure MAIN // for test, usually Report_1

   SET BROWSESYNC ON
   SET NAVIGATION EXTENDED

   SET DATE GERMAN // for test
   SET CENTURY ON  // for test

   SET procedure to open_dbf // for test
   SET procedure to open_ntx // for test
   SET procedure to use_dbf // for test

   open_dbf() // for test
   open_ntx() // for test

   DEFINE WINDOW Rep_1 ;
      AT 0, 0 ;
      WIDTH 400 ;
      HEIGHT 400 ;
      TITLE "INVDET" ;
      MAIN  // for test, usually MODAL ;

      ON KEY ESCAPE ACTION Rep_1.Release 


   @ 150, 150 BUTTON PRINT_8558 ;
      CAPTION " Create report " ;
      ACTION rep_create_8558() ;
      WIDTH 100

   END WINDOW

   Rep_1.CENTER
   ACTIVATE WINDOW Rep_1

RETURN
*----------------------------------------*
PROCEDURE rep_create_8558

PRIVATE mPrinter, nCurLine:=300, nCurPage:=0, nPageSize:=280, /* := 180 */ nVMargin:=10, nHMargin:=10 
PRIVATE cFontName:="Verdana", nFontSize:=8, nFontHeight:=4, nCharWidth:=2 
PRIVATE LastPage := 0   // 100

use_inv()
use_cust()
use_product()
USE_INVDET()   // function from USE_DBF.prg 

brk_01    := INV_NO    
brk_on_01 := .F.
prt_01    := .T.
sum_01_05 := 0 

sumr_05 := 0 

mPrinter := GetPrinter()
IF Empty ( mPrinter )
   MsgExclamation( "Printer not selected" )
   dbcloseall()
   RETURN NIL
ENDIF

// counting number of pages

DBGOTOP()
DO WHILE .NOT. EOF()

   _inv_no = inv_no
   _product = product_id

   select inv
   seek _inv_no
   _customer = inv_cust

   select invdet

   sumr_05 := sumr_05 + TOTAL     

   IF brk_01 <> INV_NO    
      brk_on_01 := .T.
      prt_01    := .T.
   ENDIF

   IF brk_01 <> INV_NO .OR. brk_on_01

      nCurLine += nFontHeight
      nCurCol = nHMargin + 10
      nCurCol = nHMargin + 150
      nCurCol2 = nCurCol + 30

      nCurLine += nFontHeight
      nCurCol = nHMargin + 10
      nCurCol = nHMargin + 180
      nCurLine += nFontHeight

      brk_01 := INV_NO    
      brk_on_01 := .F.
      sum_01_05 := 0 

	   nCurLine := 300
	  	  
   ENDIF

   sum_01_05 := sum_01_05 + TOTAL     

   IF nCurLine > nPageSize
      hdr_8560()
   ENDIF
   
   select product
   seek _product
   _product_name = name 
   
   select invdet 
      
   nCurLine += nFontHeight
   nCurCol = nHMargin + 10
   nCurCol = nHMargin + 15
   nCurCol = nHMargin + 120
   nCurCol = nHMargin + 150
   nCurCol = nHMargin + 180

   DBSKIP()
ENDDO
LastPage := nCurPage
nCurPage := 0


// now real printing


SELECT PRINTER mPrinter ;
   ORIENTATION PRINTER_ORIENT_PORTRAIT ;  // PRINTER_ORIENT_LANDSCAPE ; 
   PAPERSIZE PRINTER_PAPER_A4 ;
   PREVIEW 

START PRINTDOC NAME "report" 


select invdet 

DBGOTOP()
DO WHILE .NOT. EOF()

   _inv_no = inv_no
   _product = product_id

   select inv
   seek _inv_no
   _customer = inv_cust

   select invdet

   sumr_05 := sumr_05 + TOTAL     

   IF brk_01 <> INV_NO    
      brk_on_01 := .T.
      prt_01    := .T.
   ENDIF

   IF brk_01 <> INV_NO .OR. brk_on_01

      nCurLine += nFontHeight
      nCurCol = nHMargin + 10
      @ nCurLine, nCurCol PRINT replicate("*",  6) FONT cFontName SIZE nFontSize 
      nCurCol = nHMargin + 150
      nCurCol2 = nCurCol + 30
      @ nCurLine+2, nCurCol PRINT LINE TO nCurLine+2, nCurCol2 PENWIDTH .1

      nCurLine += nFontHeight
      nCurCol = nHMargin + 10
      @ nCurLine, nCurCol PRINT "sum" FONT cFontName SIZE nFontSize
      nCurCol = nHMargin + 180
      @ nCurLine, nCurCol PRINT  TRANSFORM ( sum_01_05, "99999.99") FONT cFontName SIZE nFontSize RIGHT
      nCurLine += nFontHeight

      brk_01 := INV_NO    
      brk_on_01 := .F.
      sum_01_05 := 0 

	  nCurLine:=300
	  	  
   ENDIF

   sum_01_05 := sum_01_05 + TOTAL     

   IF nCurLine > nPageSize
      hdr_8558()
   ENDIF
   
   select product
   seek _product
   _product_name = name 
   
   select invdet 
      
   nCurLine += nFontHeight
   *IF prt_01
   *   nCurCol = nHMargin + 1 * nCharWidth + 6 * nCharWidth 
   *   @ nCurLine, nCurCol PRINT  TRANSFORM ( INV_NO, "999") FONT cFontName SIZE nFontSize RIGHT
   *   prt_01 := .F.
   *ENDIF
   nCurCol = nHMargin + 10
   @ nCurLine, nCurCol PRINT  TRANSFORM ( PRODUCT_ID, "999") FONT cFontName SIZE nFontSize RIGHT
   nCurCol = nHMargin + 15
   @ nCurLine, nCurCol PRINT  _product_name FONT cFontName SIZE nFontSize 
   nCurCol = nHMargin + 120
   @ nCurLine, nCurCol PRINT  TRANSFORM ( PRICE, "999.99") FONT cFontName SIZE nFontSize RIGHT
   nCurCol = nHMargin + 150
   @ nCurLine, nCurCol PRINT  TRANSFORM ( QUANTITY, "999") FONT cFontName SIZE nFontSize RIGHT
   nCurCol = nHMargin + 180
   @ nCurLine, nCurCol PRINT  TRANSFORM ( TOTAL, "999,999.99") FONT cFontName SIZE nFontSize RIGHT

   DBSKIP()
ENDDO

nCurLine += nFontHeight
nCurCol = nHMargin + 10
@ nCurLine, nCurCol PRINT replicate("*",  6) FONT cFontName SIZE nFontSize
nCurCol = nHMargin + 150
nCurCol2 = nCurCol + 30
@ nCurLine+2, nCurCol PRINT LINE TO nCurLine+2, nCurCol2 PENWIDTH .1 

nCurLine += nFontHeight
nCurCol = nHMargin + 10
@ nCurLine, nCurCol PRINT "sum" FONT cFontName SIZE nFontSize
nCurCol = nHMargin + 180
@ nCurLine, nCurCol PRINT  TRANSFORM ( sum_01_05, "999,999.99") FONT cFontName SIZE nFontSize RIGHT

/*
nCurLine += nFontHeight
nCurCol = nHMargin + 150
nCurCol2 = nCurCol + 30
@ nCurLine+2, nCurCol PRINT LINE TO nCurLine+2, nCurCol2 PENWIDTH .5

nCurLine += nFontHeight
nCurCol = nHMargin + 180
@ nCurLine, nCurCol PRINT  TRANSFORM ( sumr_05, "999,999.99") FONT cFontName SIZE nFontSize BOLD RIGHT
*/
   END PRINTPAGE
END PRINTDOC

DBCLOSEALL()

Rep_1.RELEASE

RETURN 0




*----------------------------------------*
FUNCTION hdr_8558

nCurPage++
nCurLine := nVMargin

IF nCurPage > 1
   END PRINTPAGE
ENDIF

START PRINTPAGE

* @ nCurLine, 10 PRINT "Date : " + DTOC(date()) FONT cFontName SIZE nFontSize // BOLD
@ nCurLine, 180 PRINT "Page : " + alltrim(STR(nCurPage))+'/'+alltrim(str(LastPage)) FONT cFontName SIZE nFontSize // BOLD
nCurLine += nFontHeight
@ nCurLine, 100 PRINT "Invoice no " + alltrim(str(inv_no)) FONT cFontName SIZE nFontSize+2 CENTER BOLD
nCurLine += nFontHeight

select cust
seek _customer

nCurLine += nFontHeight
@ nCurLine, 100 PRINT name FONT cFontName SIZE nFontSize BOLD
nCurLine += nFontHeight
@ nCurLine, 100 PRINT address FONT cFontName SIZE nFontSize
nCurLine += nFontHeight
@ nCurLine, 100 PRINT alltrim(zipcode) + ' ' + city FONT cFontName SIZE nFontSize 
nCurLine += nFontHeight
@ nCurLine, 100 PRINT country FONT cFontName SIZE nFontSize
nCurLine += nFontHeight

select invdet

nCurLine += nFontHeight
nCurCol = nHMargin + 10
@ nCurLine, nCurCol PRINT "PRODUCT" FONT cFontName SIZE nFontSize RIGHT BOLD
nCurCol = nHMargin + 15
@ nCurLine, nCurCol PRINT "NAME" FONT cFontName SIZE nFontSize BOLD 
nCurCol = nHMargin + 120
@ nCurLine, nCurCol PRINT "PRICE" FONT cFontName SIZE nFontSize RIGHT BOLD
nCurCol = nHMargin + 150 
@ nCurLine, nCurCol PRINT "QUANTITY" FONT cFontName SIZE nFontSize RIGHT BOLD
nCurCol = nHMargin + 180
@ nCurLine, nCurCol PRINT "TOTAL" FONT cFontName SIZE nFontSize RIGHT BOLD

nCurLine += nFontHeight
nCurCol = nHMargin + 1
nCurCol2 = nCurCol + 180
@ nCurLine+2, nCurCol PRINT LINE TO nCurLine+2, nCurCol2 PENWIDTH .5

prt_01 := .T.

RETURN 0





*----------------------------------------*
FUNCTION hdr_8560

nCurPage++
nCurLine := nVMargin


nCurLine += nFontHeight
nCurLine += nFontHeight

select cust
seek _customer

nCurLine += nFontHeight
nCurLine += nFontHeight
nCurLine += nFontHeight
nCurLine += nFontHeight
nCurLine += nFontHeight

select invdet

nCurLine += nFontHeight
nCurCol = nHMargin + 10
nCurCol = nHMargin + 15
nCurCol = nHMargin + 120
nCurCol = nHMargin + 150 
nCurCol = nHMargin + 180

nCurLine += nFontHeight
nCurCol = nHMargin + 1
nCurCol2 = nCurCol + 180

prt_01 := .T.

RETURN 0
There's nothing you can do that can't be done...
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: report, how compute last page

Post by edk »

Post Reply