prices breakdown

prices breakdown

Postby Silvio.Falconi » Mon Jun 27, 2022 7: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

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,4 then make error

my test
Code: Select all  Expand view
#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 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: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: prices breakdown

Postby nageswaragunupudi » Mon Jun 27, 2022 2: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
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: prices breakdown

Postby Silvio.Falconi » Mon Jun 27, 2022 2: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 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: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: prices breakdown

Postby nageswaragunupudi » Mon Jun 27, 2022 3: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
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: prices breakdown

Postby nageswaragunupudi » Mon Jun 27, 2022 3: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: Select all  Expand view
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
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: prices breakdown

Postby nageswaragunupudi » Mon Jun 27, 2022 6:55 pm

This logic gives the result as you expect:
Code: Select all  Expand view
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

 


Image
Regards

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

Re: prices breakdown

Postby Silvio.Falconi » Mon Jun 27, 2022 7:07 pm

nageswaragunupudi wrote:This logic gives the result as you expect:
Code: Select all  Expand view
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

 


Image



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)

Image

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


Image


When I have to print the receipt I have another scheme

Image

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

Image




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: Select all  Expand view




 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 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: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: prices breakdown

Postby Silvio.Falconi » Mon Jun 27, 2022 7:27 pm

Now I made a modification

Code: Select all  Expand view
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)

Image


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


Image
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: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: prices breakdown

Postby Silvio.Falconi » Tue Jun 28, 2022 9: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

Image
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: 6772
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 92 guests