Page 1 of 1

Xbrowser Footer calc

PostPosted: Tue Mar 24, 2015 9:01 am
by Silvio.Falconi
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
 

Re: Xbrowser Footer calc

PostPosted: Tue Mar 24, 2015 10:24 am
by AntoninoP
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

Re: Xbrowser Footer calc

PostPosted: Tue Mar 24, 2015 10:32 am
by Silvio.Falconi
I'm using a array here but I have a Dbf with numeric field

Re: Xbrowser Footer calc

PostPosted: Tue Mar 24, 2015 10:43 am
by AntoninoP
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

Re: Xbrowser Footer calc

PostPosted: Tue Mar 24, 2015 11:22 am
by Silvio.Falconi
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

Re: Xbrowser Footer calc

PostPosted: Tue Mar 24, 2015 4:01 pm
by AntoninoP
: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

Re: Xbrowser Footer calc

PostPosted: Tue Mar 24, 2015 5:35 pm
by nageswaragunupudi
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

Re: Xbrowser Footer calc

PostPosted: Wed Mar 25, 2015 10:24 am
by Silvio.Falconi
thanks
I not Known the bsumcondition value!!

Re: Xbrowser Footer calc

PostPosted: Wed Mar 25, 2015 8:57 pm
by Silvio.Falconi
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