Xbrowser Footer calc

Xbrowser Footer calc

Postby Silvio.Falconi » Tue Mar 24, 2015 9:01 am

Dear Rao,
i modify an old app and I wish add the footer on a xbrowse
but I wish calc the total if the type (first column is "E" or "U" and the calc must be all E - all E
How I must make it?



test.prg
Code: Select all  Expand view
#include"fivewin.ch"

function test()
Local oDlg,oBrw

Local adata:={{"U",15.00,0.00,15.00      },;
                     {"E",148.76,31.24,180.00   },;
                     {"U",16.49,3.46,19.95      }}


DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
DEFINE DIALOG oDlg SIZE 700,300 PIXEL FONT oFont ;
      TITLE 'Footer totals'



    @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      AUTOCOLS ;
      HEADERS 'Type', 'Import', 'Iva', 'Total' ;
      ARRAY aData CELL LINES NOBORDER FASTEDIT FOOTERS

   oBrw:nStretchCol     := 1
   oBrw:MakeTotals()
   oBrw:CreateFromCode()

ACTIVATE DIALOG oDlg CENTERED
Return nil
 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6796
Joined: Thu Oct 18, 2012 7:17 pm

Re: Xbrowser Footer calc

Postby AntoninoP » Tue Mar 24, 2015 10:24 am

Hello,
I think there is a bug in xBrowse.prg line 7148, it is:
Code: Select all  Expand view
           if ValType( :nTotal ) == 'N' .or. ! Empty( :nFooterType )

it should be
Code: Select all  Expand view
           if ValType( :Value ) == 'N' .or. ! Empty( :nFooterType )

To make total only for numeric columns.

To make your example working, without change xbrowse.prg:
Code: Select all  Expand view
#include"fivewin.ch"

function test()
Local oDlg,oBrw, oCol

Local adata:={{"U",15.00,0.00,15.00      },;
                     {"E",148.76,31.24,180.00   },;
                     {"U",16.49,3.46,19.95      }}


DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
DEFINE DIALOG oDlg SIZE 700,300 PIXEL FONT oFont ;
      TITLE 'Footer totals'



    @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      AUTOCOLS ;
      HEADERS 'Type', 'Import', 'Iva', 'Total' ;
      ARRAY aData CELL LINES NOBORDER FASTEDIT FOOTERS

   oBrw:nStretchCol     := 1
   oBrw:CreateFromCode()
   for each oCol in oBrw:aCols
      WITH OBJECT oCol
         if ValType( :Value ) == 'N'
            :nTotal := 0
         endif
      END
   next
   oBrw:MakeTotals()

ACTIVATE DIALOG oDlg CENTERED
Return nil
 


Regards,
Antonino Perricone
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Xbrowser Footer calc

Postby Silvio.Falconi » Tue Mar 24, 2015 10:32 am

I'm using a array here but I have a Dbf with numeric field
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6796
Joined: Thu Oct 18, 2012 7:17 pm

Re: Xbrowser Footer calc

Postby AntoninoP » Tue Mar 24, 2015 10:43 am

In this case does not work?
I tried:
Code: Select all  Expand view
#include"fivewin.ch"

function test()
   Local oDlg,oBrw, oCol
   local aCols := { { "Type",  'C', 10, 0 }, { "Import",  'N', 10, 2 }, { "Iva",  'N',  10, 2 }, { "Total",  'N',  10, 2 } }
   Local adata:={{"U",15.00,0.00,15.00      },;
                     {"E",148.76,31.24,180.00   },;
                     {"U",16.49,3.46,19.95      }}

   DBCREATE( "ftotal", aCols)
   USE ftotal
   FW_ArrayToDBF( aData )
   CLOSE DATA
   
   USE ftotal
   
   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
   DEFINE DIALOG oDlg SIZE 700,300 PIXEL FONT oFont ;
      TITLE 'Footer totals'



    @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      AUTOCOLS ;
      HEADERS 'Type', 'Import', 'Iva', 'Total' ;
      ARRAY "ftotal" CELL LINES NOBORDER FASTEDIT FOOTERS

   oBrw:nStretchCol     := 1
   oBrw:CreateFromCode()
   for each oCol in oBrw:aCols
      WITH OBJECT oCol
         if ValType( :Value ) == 'N'
            :nTotal := 0
         endif
      END
   next
   oBrw:MakeTotals()

ACTIVATE DIALOG oDlg CENTERED
Return nil


and looks fine
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Xbrowser Footer calc

Postby Silvio.Falconi » Tue Mar 24, 2015 11:22 am

yes but the result is bad

I wish calc if the record have the field "E" or "U"
first column must be 116,51
second column 27,78
third column 145,05
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6796
Joined: Thu Oct 18, 2012 7:17 pm

Re: Xbrowser Footer calc

Postby AntoninoP » Tue Mar 24, 2015 4:01 pm

:oops:
In this case we need Rao.
My solution is a little extreme:
Code: Select all  Expand view
#include"fivewin.ch"

function test()
   Local oDlg,oBrw, oCol, oFont
   local aCols := { { "Type",  'C', 10, 0 }, { "Import",  'N', 10, 2 }, { "Iva",  'N',  10, 2 }, { "Total",  'N',  10, 2 } }
   Local adata:={{"U",15.00,0.00,15.00      },;
                     {"E",148.76,31.24,180.00   },;
                     {"U",16.49,3.46,19.95      }}

   DBCREATE( "ftotal", aCols)
   USE ftotal
   FW_ArrayToDBF( aData )
   CLOSE DATA
   
   USE ftotal
   
   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
   DEFINE DIALOG oDlg SIZE 700,300 PIXEL FONT oFont ;
      TITLE 'Footer totals'



    @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      AUTOCOLS ;
      HEADERS 'Type', 'Import', 'Iva', 'Total' ;
      ARRAY "ftotal" CELL LINES NOBORDER FASTEDIT FOOTERS

   oBrw:nStretchCol     := 1
   oBrw:CreateFromCode()
   for each oCol in oBrw:aCols
      WITH OBJECT oCol
         if ValType( :Value ) == 'N'
            :bFooter := {|oCol| CustomSumCol(oCol) }
            :nEditType := EDIT_GET
         endif
      END
   next

ACTIVATE DIALOG oDlg CENTERED
Return nil
 
function CustomSumCol(oCol)
   local oBrw := oCol:oBrw
   local nMult
   local cType
   local uBm      := oBrw:BookMark()
   oCol:cFooter := 0
   
   Eval( oBrw:bGoTop )
   do
      nMult := if(oBrw:aCols[1]:Value = "U", -1, 1)
      oCol:cFooter  += oCol:Value * nMult
   until ( oBrw:Skip( 1 ) < 1 )

   oBrw:BookMark  := uBm
       
   cType    := ValType( oCol:cFooter )
   if cType == oCol:cDataType .and. IfNil( oCol:cFooterPicture, oCol:cEditPicture ) != nil
      oCol:cFooter  := cValToStr( oCol:cFooter, IfNil( oCol:cFooterPicture, oCol:cEditPicture ),, ;
                  IfNil( oCol:lDisplayZeros, oCol:oBrw:lDisplayZeros ) )
   else
      oCol:cFooter := cValToChar( oCol:cFooter )
   endif
   
return oCol:cFooter
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Xbrowser Footer calc

Postby nageswaragunupudi » Tue Mar 24, 2015 5:35 pm

I am planning to make some improvements in xbrowse totalling.
You can start with that improvement now.
First please make this small correction in xbrowse.prg.

Please locate this line in method MakeTotals()
Code: Select all  Expand view
              if Eval( IfNil( :bSumCondition, bCond ), nValue, oCol )
 


Please make a very minor change like this. ( change nValue as @nValue )
Code: Select all  Expand view
              if Eval( IfNil( :bSumCondition, bCond ), @nValue, oCol )
 


This is the only modification you need to do in xbrowse.prg.

Now here is the program code:
Code: Select all  Expand view

#include "fivewin.ch"

function main()

Local oDlg,oBrw, oFont
Local adata:={ {"U",15.00,0.00,15.00      },;
               {"E",148.76,31.24,180.00   },;
               {"U",16.49,3.46,19.95      }}

   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
   DEFINE DIALOG oDlg SIZE 700,300 PIXEL FONT oFont ;
      TITLE 'Footer totals'

    @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      AUTOCOLS ;
      HEADERS 'Type', 'Import', 'Iva', 'Total' ;
      ARRAY aData CELL LINES NOBORDER FASTEDIT FOOTERS

   oBrw:nStretchCol     := 1
   oBrw:nFooterTypes    := AGGR_SUM
   oBrw:bSumConditions  := { |nVal,oCol| If( oBrw:oCol( 1 ):Value == 'U', nVal := -nVal, nil ), .t. }
   WITH OBJECT oBrw:aCols[ 1 ]
      :nFooterType      := nil
      :bSumCondition    := nil
   END
   oBrw:MakeTotals()
   oBrw:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

Return nil
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10254
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Xbrowser Footer calc

Postby Silvio.Falconi » Wed Mar 25, 2015 10:24 am

thanks
I not Known the bsumcondition value!!
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6796
Joined: Thu Oct 18, 2012 7:17 pm

Re: Xbrowser Footer calc

Postby Silvio.Falconi » Wed Mar 25, 2015 8:57 pm

Rao,
it run ok but I need to first column insert a bmp and then the condition not take the right value
only if I add also the bEditValue then run ok
but I see it bad
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6796
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 17 guests