FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour prices breakdown
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
prices breakdown
Posted: Mon Jun 27, 2022 07:41 AM
I have to convert a total price into columns and positions relative to this system, i.e. the total price must be broken down into parts according to the scheme

aImports:={200,100,50,20,10,5,3,2,1,0.50,0.20,0.10,0.05}

for a sample :

total price 1.20 it return me

col - Row
9 --------1
11 -------1


the total max is 391.85 is the sum of all columns

I made a test but there is an error because then the 4 position it jump to 9 and I not understood why



the second column of xbrowse it the row of scheme and the first are the columns
as you can see it cal 1,2,3,4 then make error

my test
Code (fw): Select all Collapse
 #include "Fivewin.ch"

function test()

 local  abolletta := {391.85,0,0,0,0,0}
 local aImports := Restore_Prices(abolletta)

XBROWSER aImports


return nil 
//---------------------------------------------------------------------//
 Function Restore_Prices(aTotali)
   local   nRiga
   local  nColonna,nNumero
   local nI
   local nTotale
   local aData:= {}
   local aDataX:= {}

   For ncolonna= 1 to 6
             nTotale:= aTotali[ncolonna]
             aData:= {}

             //righe
             aData:= BinCalc(nTotale)

                 For k= 1 to Len(adata)
                   nriga:=adata[k]
                   AaDd(aDataX,{nriga,nColonna} )
                  Next
     Next
return aDataX

Function BinCalc(nValue)
LOCAL aImports:={200,100,50,20,10,5,3,2,1,0.50,0.20,0.10,0.05}
LOCAL nPosition := 0
LOCAL nRest := nValue
LOCAL aRet   := {}

   DO WHILE .T.
     nPosition := ASCAN(aImports,{|e| e <= nRest})
      IF nPosition > 0
         AADD(aRet,nPosition)
         nRest -= aImports[nPosition]
      ELSE
         EXIT
      ENDIF
   ENDDO
RETURN aRet
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: prices breakdown
Posted: Mon Jun 27, 2022 02:31 PM
for a sample :

total price 1.20 it return me

col - Row
9 --------1
11 -------1


If the total price is 40, what is the correct result you expect?
Regards



G. N. Rao.

Hyderabad, India
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: prices breakdown
Posted: Mon Jun 27, 2022 02:40 PM

40.00 euro or 0.40 euro?
aImports:={200,100,50,20,10,5,3,2,1,0.50,0.20,0.10,0.05

If Is 0.40 it's no possibile
If Is 40.00
col 4 (20)
col 5 (10)
col 6(5)
Col7 (3)
col8(2)

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: prices breakdown
Posted: Mon Jun 27, 2022 03:29 PM
If Is 0.40 it's no possibile

Any value with decimal part .40 is not possibe, eg. 100.40, 90.40. etc.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: prices breakdown
Posted: Mon Jun 27, 2022 03:54 PM

the total max is 391.85 is the sum of all columns

I made a test but there is an error because then the 4 position it jump to 9 and I not understood why

Image

the second column of xbrowse it the row of scheme and the first are the columns
as you can see it cal 1,2,3,


This is correct
Code (fw): Select all Collapse
200 + 100 + 50 + 20 + 20 + 1 + 0.50 + 0.20 + 0.10 + 0.5 = 391.85

Because you used <= same value ( 20 ) is used twice.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: prices breakdown
Posted: Mon Jun 27, 2022 06:55 PM
This logic gives the result as you expect:
Code (fw): Select all Collapse
function ValSplit( nValue )

   local nRest, aRet := {}

   DEFAULT nValue := 391.65
   nRest := nValue

   AEval( {200,100,50,20,10,5,3,2,1,0.50,0.20,0.10,0.05}, ;
      { |n,i| If( n <= nRest, ( AAdd( aRet, { i, n } ), ;
              nRest := ROUND( nRest - n, 2 ) ), nil ) } )

   if nRest != 0.00
      ? "not possible. nRest =", nRest
   else
      XBROWSER aRet SETUP ( oBrw:cHeaders := { "COL", "EUROS" }, ;
         oBrw:lFooter := .t., oBrw:aCols[ 2 ]:cEditPicture := "999.99", ;
         oBrw:aCols[ 2 ]:nFooterType := AGGR_SUM, oBrw:MakeTotals() )
   endif

return aRet


Regards



G. N. Rao.

Hyderabad, India
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: prices breakdown
Posted: Mon Jun 27, 2022 07:07 PM
nageswaragunupudi wrote:This logic gives the result as you expect:
Code (fw): Select all Collapse
function ValSplit( nValue )

   local nRest, aRet := {}

   DEFAULT nValue := 391.65
   nRest := nValue

   AEval( {200,100,50,20,10,5,3,2,1,0.50,0.20,0.10,0.05}, ;
      { |n,i| If( n <= nRest, ( AAdd( aRet, { i, n } ), ;
              nRest := ROUND( nRest - n, 2 ) ), nil ) } )

   if nRest != 0.00
      ? "not possible. nRest =", nRest
   else
      XBROWSER aRet SETUP ( oBrw:cHeaders := { "COL", "EUROS" }, ;
         oBrw:lFooter := .t., oBrw:aCols[ 2 ]:cEditPicture := "999.99", ;
         oBrw:aCols[ 2 ]:nFooterType := AGGR_SUM, oBrw:MakeTotals() )
   endif

return aRet





it's correct
I explain to you
In the procedure of the amounts the end user goes to select the amount of the bet (Lottery)



But when I close this dialog I'm going to save only the totals for each column


and I'm going to enter the totals in the first dialog





When I have to print the receipt I have another scheme



then I decompose the totals so you can know the columns and rows

that is, while in the insertion see figure 1 I have the prices vertically, in the printout of the receipt I have them horizontally

therefore, by breaking down the total prices for each group, I can print the pixel in the relative space


here I wanted to explain what I've been trying to do for days


If I try with

abolletta := {391.85,0,0,0,0,0,0,0,0,0,0,0,0}
aImports := Restore_Prices( abolletta)

Function Restore_Prices(aTotali)
local nRiga
local nColonna,nNumero
local nI
local nTotale
local aData:= {}
local aDataX:= {}

For ncolonna= 1 to 13
nTotale:= aTotali[ncolonna]
aData:= {}


aData:= ValSplit( nTotale )

For k= 1 to Len(adata)
nriga:=adata[k]
AaDd(aDataX,{nriga,nColonna} )
Next
Next
return aDataX


Now I have this






when I go to print i have error

// Imports
#define _MARGIN_TOP_IMPORTS 10.83
#define _MARGIN_LEFT_IMPORTS 2.25
#define _SQUARE_RAD_IMPORTS 0.9
#define _SQUARE_LEFT_IMPORTS 10.2
#define _SQUARE_SIZE_IMPORTS 0.44
#define _SQUARE_DIST_IMPORTS 0.13
#define _XSPACE_IMPORTS 0.57
#define _YSPACE_IMPORTS 0.7

Code (fw): Select all Collapse
 DEFINE BRUSH oBrush COLOR CLR_BLACK


   PRINT oPrn NAME OemToAnsi( "Silvio Print" ) PREVIEW
             DEFINE PEN  oPen WIDTH  1  OF oPrn
 PAGE     // printing the circles form

 Print_Imports( oPrn, oPen, aImports, oBrush )

             ENDPAGE
          ENDPRINT


Function Print_Imports( oPrn, oPen, aImports, oBrush )
    LOCAL n, o
    LOCAL nI
    LOCAL nTop, nLeft, nBottom, nRight, aRect
    LOCAL nVar := 1
    LOCAL nRow, nCol
    LOCAL nRadH := _SQUARE_RAD_IMPORTS * ( 10 * oPrn:nHorzRes() / oPRn:nHorzSize() ) / 10 // radius for round boxes in printer resolution horizontal
    LOCAL nRadV := _SQUARE_RAD_IMPORTS * ( 10 * oPrn:nVertRes()  / oPrn:nVertSize() )  / 10 // radius for round boxes in printer resolution vertical
    local ncolonna, nRiga


  for nI := 1 to len( aImports )
             nColonna     :=   aImports[ nI ][1]
             nRiga        :=   aImports[ nI ][2]

             nRow := int( nRiga / 6 )
             nCol := ( nColonna % 13 )
             if nCol == 0
                nCol := 13
             else
                ++nRow
             endif

             nTop    := _MARGIN_TOP_IMPORTS  + .1 + ( --nRow  * _YSPACE_IMPORTS )
             nLeft   := _MARGIN_LEFT_IMPORTS + .1 + ( --nCol  * _XSPACE_IMPORTS )
             nBottom := nTop    - .1 + _SQUARE_SIZE_IMPORTS
             nRight  := nLeft   - .1 + _SQUARE_SIZE_IMPORTS

             oPrn:Cmtr2Pix( @nTop,    @nLeft  )
             oPrn:Cmtr2Pix( @nBottom, @nRight )

             aRect := { nTop,  nLeft , nBottom , nRight }
             oPrn:FillRect( aRect, oBrush )
          next


     return nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: prices breakdown
Posted: Mon Jun 27, 2022 07:27 PM
Now I made a modification

Code (fw): Select all Collapse
 Function Restore_Prices(aTotali)
     local   nRiga
     local  nColonna,nNumero
     local nI
     local nTotale
     local aData:= {}
     local aDataX:= {}

     For ncolonna= 1 to 13
               nTotale:= aTotali[ncolonna]
               aData:= {}

               //righe

                   aData:= ValSplit( nTotale )
                   For k= 1 to Len(adata)
                     nriga:=adata[k][1]
                     AaDd(aDataX,{nriga,nColonna} )
                    Next
       Next
  return aDataX



If I use

abolletta := {1.50,1.20,1.20,0,0,0,0,0,0,0,0,0,0}
aImports := Restore_Prices( abolletta)




have to print 3 rows but then on Print I have this


Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: prices breakdown
Posted: Tue Jun 28, 2022 09:54 AM
I corrected the function Now run ok

sample :
local abolletta := {1.50,1.20,1.20,0,0,1.50,1.20} //demo
aImports := Restore_Prices( abolletta)

result

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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

Continue the discussion