bad calculation prices for days

bad calculation prices for days

Postby Silvio.Falconi » Sat Jul 04, 2020 10:41 am

this is the price listino of the beach chalet ( June,May and september)

Image


to create the price list I stored the cost in 4 fields: day, week, 15days, month and then the cost for the seasonal stay.

my problem is that the calc is never precise:

If a customer has stayed 3 days,

the function fetches the price for a week divides it by 7 to get the cost per day and then multiplies it for the number of days

example

Week 40 € / 7 = 5.71 €

5.71 * 3 = 17.14 €

and the calculation is wrong because it should be 18

in the function I enter the prices in an array and initially divide each price by the days

day 6 euro
week 40 euros
15 days 120 euros
month 180 euros

so I do

prz [1]:= day / 1
prz [2]:= week / 7
prz [3]:= 15days / 15
prz [4]:= month / 30

and then I multiply by the days

do case
case days <2
nPrice: = ngg * prz [1]
case days <7
nPrice: = ngg * prz [2]
case days <15
nPrice: = ngg * prz [3]
houses days <30
nPrice: = ngg * prz [4]
endcase

where is the error?
Last edited by Silvio.Falconi on Mon Jul 06, 2020 4:31 pm, edited 1 time in total.
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: 7090
Joined: Thu Oct 18, 2012 7:17 pm

Re: bad calculation prices for days

Postby remtec » Sat Jul 04, 2020 5:39 pm

Hola Silvio

Tengo una duda segun lo que entiendo.
Tu defines la siguiente condición:

day 6 euro
week 40 euros
15 days 120 euros
month 180 euros

Si no estoy equivocado, no se debiera tener la siguiente relación, considerando que tu dia base tiene un valor definido?:

day 6 euro
week 42 euros
15 days 90 euros
month 180 euros.

Pienso que segun tu tabla indicada, no podrias aplicar tu formula que para sacar el valor correspondiente a 3 dias.

Pienso que para que te de lo 18 que necesitas, solo debistes aplicar (Valor dia 6 * Cant. Das 3) = 18 Euros.

Creo que debieras revisar la relacion precio en tu tabla.

Saludos
Antonio
FWH 22.10 - HARBOUR - PELLES C
remtec
 
Posts: 719
Joined: Fri May 12, 2017 2:50 pm

Re: bad calculation prices for days

Postby Bayron » Sun Jul 05, 2020 12:09 am

Hi Silvio,
There are several problems with your question
1 the relation between prices don't match as pointed by Antonio

2 It makes absolutely no sense to have an array of prices, if every single component of the array is the same, just multiplied by the price of a single day.

3 For what i see, from the relation between 1 day and 1 week, It looks like the intention was to provide a discount when the costumer occupies the beach chalet for a specific amount of time. If that is the situation, the 2 easier ways to approach it are:

3.1 Create the array, that it should be created from a table configurable by user, not hard coded... (You may have to use this one, since there is no relationship on prices, from the picture you posted)
Code: Select all  Expand view  RUN
prz [1]:= 6   //1 day
prz [2]:= 40           //1 week
prz [3]:= 65          // 2 weeks
prz [4]:= 100        // 4 weeks
 


Then obtain the number of days more than for example 1 week, multiply by single day charge, then add both ammounts....

Code: Select all  Expand view  RUN
days = 9
extra_days = days - 7
nPrice := prz[2] + (extra_days * prz[1])
 


3.2 Create the array, that it should be created from a table configurable by user, not hard coded with porcentages according to ammount of time (Recommended)
Code: Select all  Expand view  RUN
prz [1]:= 6  //1 day Euros
prz [2]:= 0.5           //1 week %
prz [3]:= 0.10         // 2 weeks %
prz [4]:= 0.20       // 4 weeks %
 


Then modify your logic to something like:

Code: Select all  Expand view  RUN
do case
case days >0 and days <2
nPrice: = ngg * prz [1]

case days >1 and days <10  //from more than 1 day, and a little over a week, but less less than 50% of the following  week,
nPrice: = (ngg * prz[1]) * (100 - prz [2])

case days >10 and days <21
nPrice: = (ngg * prz[1]) * (100 - prz [3])

case days >21
nPrice: = (ngg * prz[1]) * (100 - prz [4])
endcase
=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: bad calculation prices for days

Postby Silvio.Falconi » Mon Jul 06, 2020 9:15 am

I not understood , Bayron I sent my test
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: 7090
Joined: Thu Oct 18, 2012 7:17 pm

Re: bad calculation prices for days

Postby FranciscoA » Mon Jul 06, 2020 4:11 pm

Silvio.

I suppose that the variations in prices, according to the days, are due to a marketing policy.

What I do not understand is the inconsistency, since I think that the greater the number of days, the price should be less, up to a certain limit.
For example, if the price for a week is 40 (5.71 per day), for 15 days it should be less (per day), and so on.

However, it is my particular concept, since everything depends on the marketing policy, as I said previously.

You can try the following example code, adapting it to your needs.
The code shows the results you want to obtain for the 3 days you mentioned.
Maybe it will guide you.

Code: Select all  Expand view  RUN
//----------------------------------------
#include "fivewin.ch"

Function Main()
local nDays := 0
If MisGets("Precio segun dias","","Digite cant dias",@nDays,"lupa")
   if nDays > 0
      PriceDay(nDays)
   else
      MsgStop("No digitó los dias")
   endif
Endif
Return nil
//----------------------------------------
Function PriceDay(nDays)
local nPriceDay := 0
local n1Day := 6, n7Days := 40, n15Days := 83, n30Days := 150

Do Case
   Case nDays >= 1 .and. nDays <= 6
        nPriceDay := n1Day           //6.00
   Case nDays >= 7 .and. nDays <= 14
        nPriceDay := n7Days / 7      //5.7142
   Case nDays >= 15 .and. nDays <= 29  
        nPriceDay := n15Days / 15    //5.5333
   Case nDays >= 30
        nPriceDay := n30Days / 30    //5.00
EndCase

MsgInfo( "Days     : " +Str(nDays,10) +CRLF+;
         "PriceDay : " +Str(nPriceDay,10,4) +CRLF+;
         "PriceTot : " +Str(nPriceDay * nDays,10,4) )

Return nPriceDay
 
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2159
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: bad calculation prices for days

Postby Silvio.Falconi » Mon Jul 06, 2020 4:30 pm

FranciscoA wrote:Silvio.

I suppose that the variations in prices, according to the days, are due to a marketing policy.

What I do not understand is the inconsistency, since I think that the greater the number of days, the price should be less, up to a certain limit.
For example, if the price for a week is 40 (5.71 per day), for 15 days it should be less (per day), and so on.

However, it is my particular concept, since everything depends on the marketing policy, as I said previously.

You can try the following example code, adapting it to your needs.
The code shows the results you want to obtain for the 3 days you mentioned.
Maybe it will guide you.



thanks francisco but not good
sample first row ( see the picture)
local n1Day := 6, n7Days := 40, n15Days := 65, n30Days := 100
If I have 14 days ( on June)
your calc is 80,00
the owner of the chalet calc is 60,666666

cannot be 80 because for 15 day the price is 65

then I published a price list of June,May and september for the privacy

if you give me the mail I can send all the list price and a test to try
Last edited by Silvio.Falconi on Mon Jul 06, 2020 5:14 pm, edited 1 time in total.
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: 7090
Joined: Thu Oct 18, 2012 7:17 pm

Re: bad calculation prices for days

Postby Silvio.Falconi » Mon Jul 06, 2020 5:08 pm

this is the consequence of a discussion long ago with James B.

who told me that making an archive with as many records as the days of the summer season for all the services was a huge mistake:

10 elements X 10 services X 10 packages X 10 sections X 93 days = 930,000 price records

he advised me to create a small archive with the prices per day / week / 15days / month as described in the price list that the owner of the chalet gave me.

The problem is that when you have days that are not the standard ones, you have problems because the calculation is wrong

at least in the archive I wanted to do, the user could have customized all the prices by hand and the search in the archive could have been easier - Desc, n days for the price list num X

Now I can't go back and I have to use the archive created from the price list given to me by the owner of the chalet

but I have obvious difficulties because the calculation continues to be incorrect
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: 7090
Joined: Thu Oct 18, 2012 7:17 pm

Re: bad calculation prices for days

Postby Silvio.Falconi » Mon Jul 06, 2020 5:20 pm

FranciscoA wrote:Silvio.

I suppose that the variations in prices, according to the days, are due to a marketing policy.

What I do not understand is the inconsistency, since I think that the greater the number of days, the price should be less, up to a certain limit.
For example, if the price for a week is 40 (5.71 per day), for 15 days it should be less (per day), and so on.

However, it is my particular concept, since everything depends on the marketing policy, as I said previously.

You can try the following example code, adapting it to your needs.
The code shows the results you want to obtain for the 3 days you mentioned.
Maybe it will guide you.


the complete archive Price List

Image





Another sample
reservation from 1/July to 29 July

I set the price local n1Day := 9, n7Days := 60, n15Days := 120, n30Days := 180 ( see third row - the last columns on the right of the picture )

your calc made 232

cannot be good because the user pay for 30 days 180€ , he cannot pay for 29 days 232€

the owner of chalet calc is 170€
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: 7090
Joined: Thu Oct 18, 2012 7:17 pm

Re: bad calculation prices for days

Postby FranciscoA » Mon Jul 06, 2020 5:47 pm

Silvio.Falconi wrote:if you give me the mail I can send all the list price and a test to try


falegria230349@yahoo.es
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2159
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: bad calculation prices for days

Postby FranciscoA » Tue Jul 07, 2020 1:22 am

Silvio.Falconi wrote:
Another sample
reservation from 1/July to 29 July

I set the price local n1Day := 9, n7Days := 60, n15Days := 120, n30Days := 180 ( see third row - the last columns on the right of the picture )

your calc made 232

cannot be good because the user pay for 30 days 180€ , he cannot pay for 29 days 232€

the owner of chalet calc is 170€



Can you try this way?
This code shows the result of 174 for 29 days, while the result of the owner of chalet is 170, according to what you say.
What formule the owner used to obtain 170?
Can you post here the results from 16 days to 30 days, which the owner of chalet considers corrects?


Code: Select all  Expand view  RUN
//----------------------------------------
Function PriceDay(nDays)
local nPriceDay := 0
local n1Day := 9, n7Days := 60, n15Days := 120, n30Days := 180

Do Case
   Case nDays ==  1                    ;  nPriceDay := n1Day
   Case nDays >=  2 .and. nDays <=  7  ;  nPriceDay := n7Days / 7
   Case nDays >=  8 .and. nDays <= 15  ;  nPriceDay := n15Days / 15
   Case nDays >= 16 .and. nDays <= 30  ;  nPriceDay := n30Days / 30
   Case nDays > 30                     ;  nPriceDay := n30Days / 30
EndCase

MsgInfo( "Days     : " +Str(nDays,10) +CRLF+;
         "PriceDay : " +Str(nPriceDay,10,4) +CRLF+;
         "PriceTot : " +Str(nPriceDay * nDays,10,4) )

Return nPriceDay
 
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2159
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: bad calculation prices for days

Postby Silvio.Falconi » Tue Jul 07, 2020 4:50 am

174 can be right for me ,
then the owner made a descount I not understood also from 174 to 171, because it doesn't always behave this way
probably because it takes the cost of the month 180€ and takes it off one day 9€ -> 180 - 9 = 171 (1 of round)

do you saw my List price ?
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: 7090
Joined: Thu Oct 18, 2012 7:17 pm

Re: bad calculation prices for days

Postby gdeteran » Tue Jul 07, 2020 9:23 pm

Solo para optimizar:
If nDays > 21
---
elseif nDays > 10
----
elseif nDays > 1
-----
else
-----
Saludos,
Gonzalo
Puerto Montt - CHILE
FWH 22.12 - Harbour 3.2.0dev (r2008190002) - Borland/Embarcadero C++ 7.0(32-bit)
User avatar
gdeteran
 
Posts: 115
Joined: Fri Oct 14, 2005 7:10 pm
Location: Puerto Montt - CHILE

Re: bad calculation prices for days

Postby Silvio.Falconi » Wed Jul 08, 2020 4:59 am

I am convinced that I would need an archive where the end user must enter a price for each item from day 1 to day 30/31. and this for each element that there are 4, for each sector (from A to N) for each service and for each package (element + service). I have not found solutions. for me only in this way the user could customize each price because doing as I was advised some time ago by the experts you risk not calculating the right rate well
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: 7090
Joined: Thu Oct 18, 2012 7:17 pm

Re: bad calculation prices for days

Postby Silvio.Falconi » Mon Jul 20, 2020 9:58 am

just an idea,

to insert in a ascii (txt) file a personalized mathematical formula but then I didn't understand how to load it in the program (fwh) and calculate the right price

sample :

local n1Day := 9, n7Days := 60, n15Days := 120, n30Days := 180

n7Days / 7
n15Days /15
n30Days /30

price * days * percentual + Recharge
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: 7090
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 74 guests