A suggestion :help

A suggestion :help

Postby Silvio » Fri Mar 27, 2009 12:12 am

I must create prices for umbrellas rent
it can be calcolate counting the days of rent
sample :

one day 9.00 euro
seven days 50,00 euro
15 days 100,00 euro
30 days 205,00 euro

but I have a problem

How I can make if I must to pay only for 14 or 18 days or 20 or 25 days ?
do U have an Idea ?
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: A suggestion :help

Postby Armando Picon » Fri Mar 27, 2009 1:31 am

Sivio... use the Fibonacci serie
FWH + BCC582 + WorkShop 4.5 + Resource Hacker + Mingw
Mis nuevas herramientas
Comunicacion via WhatsApp (+51) 957549 665
Comunicación via Correo: apic1002002 at yahoo dot es; apic1002002@gmail.com
User avatar
Armando Picon
 
Posts: 446
Joined: Mon Dec 26, 2005 9:11 pm
Location: Lima, Peru

Re: A suggestion :help

Postby Armando » Fri Mar 27, 2009 2:23 am

Silvio:

Just an idea

You must to know the price for each day as follow

9 euros / 1 days = 9 euros each day
50 euros / 7 days = 7.15 euros each day
100 euros / 15 days = 6.67 euros each day and
205 euros / 30 days = 6.84 euros each day

With these prices you make a table

FROM TO Price for each day
1 to 6 9 euros
7 to 14 7.15 euros each day
15 to 29 6.67 euros each day and
30 to 999 6.84 euros each day

Then, an example:

If your customer rent an umbrella for 10 days the price for each day must be 7.15 euros
because 10 is betwen 7 to 14

10 * 7.15 = 71.50 Euros

What do you think ?

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3211
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: A suggestion :help

Postby Silvio » Fri Mar 27, 2009 8:44 am

it is a good idea

BUT


if I have 14 days to pay

14*7.15 = 100,1euros

but if I have 15 gg pay 100 euros

if I have 14 or 15 pay the same ??
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: A suggestion :help

Postby Armando » Fri Mar 27, 2009 1:24 pm

Silvio:

Then, don't use the rounded prices for each day

9 euros / 1 days = 9 euros each day
50 euros / 7 days = 7.14 euros each day
100 euros / 15 days = 6.66 euros each day and
205 euros / 30 days = 6.83 euros each day

Regards

14 * 7.14 = 99.96 Euros
15 * 6.66 = 99.90 Euros

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3211
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: A suggestion :help

Postby ukoenig » Fri Mar 27, 2009 7:50 pm

Hello Silvio,

I created a function for this ( Tested and Updated 28.03.2009 ).
With that it is possible to calculate the price, even with using days are not Linear.
In my application, I used it for the calculation of fluctuate prices of articles.

Another exsample how to keep the price between two given points ,
You can find in my answer to Amando at the bottom. It is very easy and uses the same logic.

Just put some values and tell me Your results.
There are some control-Alerts You can use.

Silvio, maybe You can change the title of the topic in : How to calculate fluctuate prices ?
If somebody needs this calulation, it is better to find.

Image

Test-calculation ( interpolating ) between two given values :
7 Days = 50 Euro and 14 Days = 100 Euro
-----------------------------------------------
7 Days = 50,00 Euro
8 Days = 57,14 Euro
9 Days = 64,29 Euro
10 Days = 71,42 Euro
11 Days = 78,57 Euro
12 Days = 85,71 Euro
13 Days = 92,86 Euro
14 Days = 100,00 Euro
Code: Select all  Expand view


FUNCTION PRICE_TEST(oWnd)
LOCAL oDlg, oGET

// A array DAYS and PRICE
// ----------------------------
PRIVATE aPRICE[6][2]
aPRICE[1] := { 1, 10 }
aPRICE[2] := { 7, 50 }   // 12 Days = 50 + ( ( ( 100 - 50 ) / 7 ) * 5 ) = 85.71
aPRICE[3] := { 14, 100 }
aPRICE[4] := { 21, 130 }  // 25 Days = 130 + ( ( ( 200 - 130 ) / 7 ) * 4 ) = 170
aPRICE[5] := { 28, 200 }  
aPRICE[6] := { 35, 200 }  // 30 Days = 200 + ( ( 200 / ( 35 - 28 ) * 2 ) = 257,14  => End

// calculate the price
// ----------------------
nDAYS := 12

DEFINE DIALOG oDlg TITLE "Price Test"

@ 1, 2  GET oGet VAR nDAYS OF oDlg SIZE 30, 15  PICTURE "99"
@ 2, 2 BUTTON "Price-Test" size 50, 25 OF oDlg ;
ACTION ( oGet:Refresh(), ;
      nPRICE := GETPRICE1( nDAYS, aPRICE ), ;
      MsgAlert( nPrice ) )

ACTIVATE DIALOG oDlg CENTERED

RETURN ( NIL )

// ------------------------------------------

FUNCTION GETPRICE1( nDAYS, aPRICE )
nPRICE := 0

// Testing days of last Array-Element for valid input
// ------------------------------------------------------------
IF nDAYS = 0
    MsgAlert( "No Days-value defined !","Error" )
    RETURN( NIL )
ENDIF
IF nDAYS > aPRICE[LEN(aPRICE)][1]
    MsgAlert( "To many Days !","Error" )
    RETURN( NIL )
ENDIF

I := 1
FOR I := 1 to LEN( aPRICE )  // 6
   IF I + 1 < LEN( aPRICE )   // < 6

      // Price is defined for nDAYS ( no calculation )
      // ---------------------------------------------------
      IF nDAYS = aPRICE[I][1]

         nPRICE :=  aPRICE[I][2]

         EXIT

      ENDIF

      //   1      7     14     21    28    35
      //   6     13      20      27      34
      //   1-6, 7-13, 14-20, 21-27, 28-34, 35

      IF nDAYS >= aPRICE[I][1] .and. nDAYS <= aPRICE[I+1][1]-1  

         // nPARTPRICE := ( 100 - 50 )  /  ( 14 - 7 )  = 7,14
         // aPRICE[3] := { 14, 100 }
         // ----
         // nPARTPRICE := ( 200 - 130 )  /  ( 28 - 21 ) = 10
         // aPRICE[5] := { 28, 200 }
         // ---------------------------------------------------------
         nPARTPRICE := ( aPRICE[I+1][2]- aPRICE[I][2] )/( aPRICE[I+1][1]- aPRICE[I][1] )
           
         // nPRICE :=  50 + ( 7,14 * ( 12 - 7 ) ) = 85,71
         // aPRICE[2] := { 7, 50 }  
         // 12 Days =   50 + ( ( ( 100 - 50 ) / 7 ) * 5 )   = 85.71
         // ------
         // nPRICE :=  130 + ( 10 * ( 25 - 21 ) ) = 170
         // aPRICE[4] := { 21, 130 }
         // 25 Days =   130 + ( ( ( 200 - 130 ) / 7 ) * 4 )   = 170
         // -------------------------------------------------------------
         nPRICE :=  aPRICE[I][2] + ( nPARTPRICE * ( nDAYS - aPRICE[I][1] ) )

         // msgalert( aPRICE[I][2], "1")    
         // msgalert( nPARTPRICE, "2")    
         // msgalert( aPRICE[I-1][1], "3")  

         EXIT

     ENDIF

  ENDIF

  // Special calculation needed for last Array-Element
  // Last Array-Element only for End of days ( no extra price )
  // -------------------------------------------------------------------
  IF I = LEN( aPRICE )  // 6

      IF nDAYS >= aPRICE[I-1][1] // Array-Element 5

         // aPRICE[5] := { 28, 200 }
         // aPRICE[6] := { 35, 200 } // End
         // nPARTPRICE := 200 /  ( 35 - 28 )  = 28,57

         // ----------------------------------------------------------
         nPARTPRICE := aPRICE[I][2] / ( aPRICE[I][1] - aPRICE[I-1][1] )  
           
         // 30 Days =  200 + ( ( 200 / ( 35 - 28 ) * 2 )   = 257,14
         // -------------------------------------------------------------------
         nPRICE :=  aPRICE[I][2] + ( nPARTPRICE * ( nDAYS - aPRICE[I-1][1] ) )

         // msgalert( aPRICE[I][2], "1")  //   200
         // msgalert( nPARTPRICE, "2")  //   28,57
         // msgalert( aPRICE[I-1][1], "3")  //    28
         // msgalert( aPRICE[I][1], "4")     //    35

         EXIT

      ENDIF

   ENDIF

NEXT

RETURN ( nPRICE )
 


Regards
Uwe :lol:
Last edited by ukoenig on Sat Mar 28, 2009 6:53 pm, edited 7 times in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: A suggestion :help

Postby ukoenig » Sat Mar 28, 2009 2:29 pm

The Function is Updated ( 28.03.2009 )

Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: A suggestion :help

Postby Armando » Sat Mar 28, 2009 5:16 pm

Ukoenig:

Taking your example I get these individual prices

7 50.00 7.1429
8 57.14 7.1400
9 64.29 7.1500
10 71.42 7.1300
11 78.57 7.1500
12 85.71 7.1400
13 92.86 7.1500
14 100.00 7.1400

As we can see the price of 9 days is more expensive than the price of 8 days
and the price of 11 days is more expensive than the price of 10 days also.
and so on.

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3211
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: A suggestion :help

Postby ukoenig » Sat Mar 28, 2009 6:24 pm

Hello Armando

The prices are calculated ( interpolated ) between two given prices in my function above.
It is a solution for a part of a merchandise planning and control system.
If You want to keep the price the same between two given points, it is very easy to do this.
There is nothing to calculate and the function returns the exact price inside a price-group.
It is the same function-logic like solution 1. Now You have two options, how to get a price.
For me, this logic doesn't make sense, because if somebody rents 14 Days ( start of Group ), it would be
the same like for 20 Days ( end of Group).
Normaly for that, You have to use the special price from this group from 14 to 21 Days and use the
Price for the calculation. Let' say, somebody stays 18 Days, the price for each Day from group 14 to 21 is used.
But it's up to You.

The picture shows the difference between the two solutions :
Image

Returns the same price between two given points

Overview :
Image


Code: Select all  Expand view

FUNCTION PRICE_TEST(oWnd)
LOCAL oDlg, oGET

// A array DAYS and PRICE
// ----------------------------
PRIVATE aPRICE[6][2]
aPRICE[1] := { 1, 10 }
aPRICE[2] := { 7, 50 }  
aPRICE[3] := { 14, 100 }
aPRICE[4] := { 21, 130 }  
aPRICE[5] := { 28, 200 }  
aPRICE[6] := { 35, 260 }  

// find the Price of a given Day ( Group )
// ---------------------------------------------
nDAYS := 12

DEFINE DIALOG oDlg TITLE "Price Test"

@ 1, 2  GET oGet VAR nDAYS OF oDlg SIZE 30, 15  PICTURE "99"
@ 2, 2 BUTTON "Price-Test" size 50, 25 OF oDlg ;
ACTION ( oGet:Refresh(), ;
      nPRICE := GETPRICE2( nDAYS, aPRICE ), ;
      MsgAlert( nPrice ) )

ACTIVATE DIALOG oDlg CENTERED

RETURN ( NIL )

// ------------------------------------------

FUNCTION GETPRICE2( nDAYS, aPRICE )
nPRICE := 0

// Testing days of last Array-Element for valid input
// ------------------------------------------------------------
IF nDAYS = 0
    MsgAlert( "No Days-value defined !","Error" )
    RETURN( NIL )
ENDIF
IF nDAYS > aPRICE[LEN(aPRICE)][1]
    MsgAlert( "To many Days !","Error" )
    RETURN( NIL )
ENDIF

I := 1
FOR I := 1 to LEN( aPRICE )  // 6

IF I < LEN( aPRICE )
   IF nDAYS >= aPRICE[I][1]  .and. nDAYS < aPRICE[I+1][1]
      nPRICE :=  aPRICE[I][2]
      EXIT
   ENDIF
ELSE // For the last Array-Element
   IF nDAYS = aPRICE[I][1]
      nPRICE :=  aPRICE[I][2]
      EXIT
   ENDIF
ENDIF

NEXT

RETURN ( nPRICE )

 


Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: A suggestion :help

Postby Silvio » Sun Mar 29, 2009 1:19 am

Sorry but I have this prices
Image

I must create a dbf from it

If I have to pay an umbrellas ( look on jpg first line : ombrellone 1° Fila blue box ) for 14 days How many euros I must ask ?

If you calculare the price of each day for 14 days = 7 x 14 = 98 euro

but you can see on the blu box you can pay for 15 day only 63 euro

then I must pay many euro for 14 day than for 15 days ?


Do U understand my problem ?
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: A suggestion :help

Postby ukoenig » Sun Mar 29, 2009 1:44 am

Hello Silvio,

I had a look at the table and understand it like this :
There is a special offering >= 15 Days = 63 Euro and a price for one Day = 7 Euro.
If You rent < 15 Days, the price of 7 Euro each day is used.
If You calculate until 9 Days with 7 Euro a Day, You reach the price of the special offering.
That means :
If somebody stays > 9 Days and < 15 Days, the price will be higher > 63 Euro.
The Day-price after using the special offering 63 Euro = 63 / 15 would be 4,20 Euro up to 30 Days.
To stay 18 Days = 63 + ( 3 * 4,20 ) = 75,60 Euro => Fix-price 15 Days + 3 * Day-price ( 4,20 Euro ).
It is possible, to include this logic in my function.

The calculation :
< 15 Days = 7 Euro * Days
18 Days = 63 Euro + ( 3 * 4,20 Euro ) = 75,60 Euro.
Maybe You can speek to Your customer, if my understanding is correct, using 4,20 Euro a day after 14 days ( 15 ) ?

Days.....Price
--------------
1--------7
..
9--------63
14-------98
-----------------------
15-------63
..
30------126

Code: Select all  Expand view

FUNCTION PRICE_TEST(oWnd)
LOCAL oDlg, oGET

PRIVATE aPRICE[3][3]
aPRICE[1] := { 1, 0, 7 }   // 1 day
aPRICE[2] := { 1, 15, 63 }  // min 15 Days
aPRICE[3] := { 16, 30, 126 } // min >= 16 Days
nDAYS := 1

DEFINE DIALOG oDlg TITLE "Price Test"

@ 1, 2  GET oGet VAR nDAYS OF oDlg SIZE 30, 15  PICTURE "99"
@ 2, 2 BUTTON "Price-Test" size 50, 25 OF oDlg ;
ACTION ( oGet:Refresh(), ;
                nPRICE := GETPRICE3( nDAYS, aPRICE ), ;
                MsgAlert( nPrice ) )

ACTIVATE DIALOG oDlg CENTERED

RETURN ( NIL )

// -----------------------

FUNCTION GETPRICE3( nDAYS, aPRICE )
nPRICE := 0

IF nDAYS = 0
    MsgAlert( "Day-value missing !","Error" )
    RETURN( NIL )
ENDIF

I := 1
FOR I := 1 to nDAYS

   // Days < 15 ( max 14 * 7 = 98 Euro )
   // ---------------------------------------
   IF nDAYS < aPRICE[2][2]
      nPRICE := aPRICE[1][3] * nDAYS
   ENDIF    

   // longer >= 15 Days
   // --------------------
   IF nDAYS >= aPRICE[2][2] .and. nDAYS <= aPRICE[3][2]
      // 63 Euro / 15 = 4,20 Euro
      // --------------------------------
      nPRICE := ( aPRICE[2][3] / aPRICE[2][2] ) * nDAYS  
   ENDIF       

   // longer > 30 Days same calculation of 4,20 Euro each day
   // ------------------------------------------------------------------
   IF nDAYS > aPRICE[3][2]
      // 63 Euro / 15 Days = 4,20 Euro
      // -----------------------------------
      nPRICE := ( aPRICE[2][3] / aPRICE[2][2] ) * nDAYS  
   ENDIF      

NEXT

RETURN ( nPRICE )
 


Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 86 guests