Hight, Low and Average dates

Hight, Low and Average dates

Postby Silvio » Mon Mar 30, 2009 11:52 am

How do I calculate the period of Holydays
high, average and low season

I have these parameters

Low from 17/05 to 27/06 and from 30/08 to 20/09
Hight from 26/07 to 29/08
Average from 28/06 to 25/07

and the user insert the init date date_INI and the end date date_END

the function to control the dates must return a value as "hight" or "Low" or "Average"
and must calculate the numbers of days

there is also a problem :

if the user insert a date between a period and the other

sample : from 01/07/09 to 28/08/09

solution : from 01/07/09 to 25/07 are 25 days (average) this have a price

from 26/07 to 28/08 are 32 say (Hight) this have another price

Any Idea How create a function ?
Best Regards, Saludos

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

Re: Hight, Low and Average dates

Postby ukoenig » Mon Mar 30, 2009 6:22 pm

Hello Silvio,

The function and Calculation :
-----------------------------------
Date calculated from : 10.07.2009 - 14.08.2009
Average from 28/06 to 25/07 ( 10.07 - 25.07 = 16 Days )
Hight from 26/07 to 29/08 ( 26.07 - 14.08 = 20 Days )

Image

Code: Select all  Expand view

FUNCTION TEST_DAYS()
LOCAL oDlg, oGet1, oGet2

DEFINE DIALOG oDlg TITLE "Day Tests"

SET DATE GERMAN
SET CENTURY ON  
PRIVATE aDAYS[1][2]
PRIVATE aSEASON[4][2]
cYEAR := LTRIM( STR( YEAR(DATE()) ))

aSEASON[1] := { "17.05." + cYEAR, "27.06." + cYEAR } // LOW
aSEASON[2] := { "28.06." + cYEAR, "25.07." + cYEAR } // AVERAGE
aSEASON[3] := { "26.07." + cYEAR, "29.08." + cYEAR } // HIGHT
aSEASON[4] := { "30.08." + cYEAR, "20.09." + cYEAR } // LOW
dDAY1 := CTOD("18.05." + cYEAR )
dDAY2 := CTOD("16.06." + cYEAR )
nDAYS1 := 0
nDAYS2 := 0
cSEASON := "LOW"

@ 1, 2  GET oGet1 VAR dDAY1 OF oDlg SIZE 40, 15  PICTURE "##.##.####"
@ 1, 8  GET oGet2 VAR dDAY2 OF oDlg SIZE 40, 15  PICTURE "##.##.####"

@ 2, 2 BUTTON "Date-Test" size 50, 25 OF oDlg ;
ACTION ( oGet1:Refresh(), oGet2:Refresh(), ;
                nPRICE := GET_DAYS( dDAY1, dDAY2, aSEASON ), ;
                MsgAlert( STR(nDAYS1) + CRLF + STR(nDAYS2), cSEASON ) )

ACTIVATE DIALOG oDlg CENTERED

RETURN ( NIL )

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

FUNCTION GET_DAYS()

// How do I calculate the period of Holydays
// high, average and low season
// I have these parameters
// Low from 17/05 to 27/06 and from 30/08 to 20/09
// Hight from 26/07 to 29/08
// Average from 28/06 to 25/07
// and the user insert the init date date_INI and the end date date_END
// the function must return a value as "hight" or "Low" or "Average"
// and must calculate the numbers of days
// there is also a problem :
// if the user insert a date between a period and the other
// sample : from 01/07/09 to 28/08/09
// solution : from 01/07/09 to 25/07 are 25 days (average) this have a price
// from 26/07 to 28/08 are 32 say (Hight) this have another price

nDAYS1 := 0 // Basic Days
nDAYS2 := 0 // next Season Days

// LOW
// aSEASON[1] := { "17.05", "27.06" } // LOW
// -------- 20.05 - 24.06 = 36 x LOW -------------------  

IF dDAY1 >= cTOD(aSEASON[1][1] ) .and. dDAY2 <=  cTOD(aSEASON[1][2])
    cSEASON := "LOW"
    nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF


// LOW + AVERAGE
// aSEASON[1] := { "17.05", "27.06" } // LOW
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
// ---------- 26.05 - 12.07 =  33 x LOW +15 x AVERAGE ------------

IF dDAY1 >= cTOD(aSEASON[1][1] ) .and. ;
    ( dDAY2  >= cTOD(aSEASON[2][1]) .and. dDAY2 <= cTOD(aSEASON[2][2]) )
    cSEASON := "LOW+AVERAGE"
    nDAYS1 :=  1 + (cTOD(aSEASON[1][2]) - dDAY1)
    nDAYS2 :=  1 + (dDAY2 - cTOD(aSEASON[2][1]))
ENDIF

// AVERAGE
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
//------------- 29.06 - 22.07 = 25 x AVERAGE --------

IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. dDAY2 <= cTOD(aSEASON[2][2])
    cSEASON := "AVERAGE"
    nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF

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

// AVERAGE + HIGHT
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// --------10.07 - 14.08  = 16 x AVERAGE + 20 x HIGHT -------

IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. ;
    ( dDAY2  >= cTOD(aSEASON[3][1]) .and. dDAY2 <= cTOD(aSEASON[3][2]) )
    cSEASON := "AVERAGE+HEIGHT"
    nDAYS1 :=  1 + (cTOD(aSEASON[2][2]) - dDAY1)
    nDAYS2 :=  1 + (dDAY2 - cTOD(aSEASON[3][1]))
ENDIF

// HIGHT
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// --------18.08 - 14.09  = 28 x HEIGHT -------------

IF cTOD(aSEASON[3][1] ) >= dDAY1 .and. cTOD(aSEASON[3][2]) <= dDAY2
    cSEASON := "HIGH"
    nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF

// HIGHT + LOW
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// aSEASON[4] := { "30.08", "20.09" } // LOW
// --------- 14.08 - 16.09 = 16 x HIGHT + 17 x LOW ------

IF dDAY1 >= cTOD(aSEASON[3][1] ) .and. ;
    ( dDAY2  >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2]) )
    cSEASON := "HIGH+LOW"
    nDAYS1 :=  1 + (cTOD(aSEASON[3][2]) - dDAY1)
    nDAYS2 :=  1 + (dDAY2 - cTOD(aSEASON[4][1]))
ENDIF

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

// LOW
// aSEASON[4] := { "30.08", "20.09" } // LOW
// ---------------- 30.08 - 15.09 = 16 x LOW ----------------

IF dDAY1 >= cTOD(aSEASON[4][1] ) .and. dDAY2 <= cTOD(aSEASON[4][2])
    cSEASON := "LOW"
    nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF

RETURN( nDAYS1, nDAYS2, cSEASON )
 


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: Hight, Low and Average dates

Postby Silvio » Mon Mar 30, 2009 10:30 pm

thanks
but I saw the source
I found cSEASON := "HIGH+LOW" or cSEASON := "AVERAGE+HEIGHT"

I must have

the total of days of Hight sample 20
the total of days of Average sample 12
the total of days of Low sample 00
but for each total I need Know the season : "hight" or "Low" or "Average"

I cannot have cSEASON := "HIGH+LOW" or cSEASON := "AVERAGE+HEIGHT"

because the I seek on dbf the prices for total days + season

sample
20 days Hight -> € 7.00
12 days average -> € 5.00

How I can seek on dbf cSEASON := "HIGH+LOW" or cSEASON := "AVERAGE+HEIGHT"

I have only "hight" or "Low" or "Average"



do U understand me ?
Best Regards, Saludos

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

Re: Hight, Low and Average dates

Postby ukoenig » Mon Mar 30, 2009 10:43 pm

Hello Silvio,

Your Question :
there is also a problem :
if the user insert a date between a period and the other
sample : from 01/07/09 to 28/08/09
solution : from 01/07/09 to 25/07 are 25 days (average) this have a price
from 26/07 to 28/08 are 32 say (Hight) this have another price

Average = value 1
Hight = value 2
Image
the header of the message shows only, that there is maybe a combination.
When there is no combination, the second value = 0 and the Header shows only one season.
When there is a combination like LOW and AVERAGE, the messagebox
shows LOW+AVERAGE ( both values > 0 ) like You can see in the screenshot.
LOW and AVERAGE is not added. There are allways 2 Values You get.
The price-calculation would be : price := ( value1 * price1 ) + ( value2 * price2 )

You dont need to take care of the combination because if value2 = 0, * price2 is also 0.
Code: Select all  Expand view

IF cSeason = "HIGHT" // LOW is the next possible season after HIGHT
      price := ( days1 * HIGHT-price ) + ( days2 * LOWprice )
ENDIF
 

If You work only with information : Low, Average and Hight, You can change LOW+HIGHT to LOW.
The problem is, that You have 2 LOW-seasons, You have to handle ( end of season )
LOW from 17/05 to 27/06 and from 30/08 to 20/09
I think, when there is a index on LOW, AVERAGE and HIGHT, You can handle LOW only in combination
with 17/5 and 30/8, to make it different.

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: Hight, Low and Average dates

Postby Silvio » Tue Mar 31, 2009 9:10 am

I write on your private email .pls
Best Regards, Saludos

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

Re: Hight, Low and Average dates

Postby ukoenig » Tue Mar 31, 2009 10:47 am

I'm busy, to add a price-calculation to the function.
As well, it will be possible with a value ( price = .T. ), to define a longer period than the next season
That is used for the Price-calculation.

A customer rents a umbrella from 18.05 - 15.09 ( all seasons ), from LOW = 7.00 Euro to LOW = 7.00 Euro
Image

A extrem-test with values inside => AVERAGE = 28.06. - 25.07., HEIGHT = 26.07. - 29.08.
Image

The season-array gets a extension for the price.
The End-result of the price can be stored to a database-field, as well all values in between, if needed.

aSEASON[1] := { "17.05." + cYEAR, "27.06." + cYEAR, 7.00 } // LOW
aSEASON[2] := { "28.06." + cYEAR, "25.07." + cYEAR, 9.00 } // AVERAGE
aSEASON[3] := { "26.07." + cYEAR, "29.08." + cYEAR, 11.00 } // HIGHT
aSEASON[4] := { "30.08." + cYEAR, "20.09." + cYEAR, 7.00 } // LOW

It's a crazy calculation, but I got it working. Still some finetuning and tests must be done.
I will update the function when the tests are finished.
Code: Select all  Expand view

FUNCTION TEST_PRICE()
LOCAL o Get1, oGet2, oGet3

DEFINE DIALOG oDlg SIZE 300, 220 TITLE "Price Test"

SET DATE GERMAN
SET CENTURY ON  
SET DECIMALS TO 2
PRIVATE aDAYS[1][2]
PRIVATE aSEASON[4][3]
cYEAR := LTRIM( STR( YEAR(DATE()) ))

aSEASON[1] := { "17.05." + cYEAR, "27.06." + cYEAR, 7.00 } // LOW
aSEASON[2] := { "28.06." + cYEAR, "25.07." + cYEAR, 9.00 } // AVERAGE
aSEASON[3] := { "26.07." + cYEAR, "29.08." + cYEAR, 11.00 } // HIGHT
aSEASON[4] := { "30.08." + cYEAR, "20.09." + cYEAR, 7.00 } // LOW
dDAY1 := CTOD("18.05." + cYEAR )
dDAY2 := CTOD("15.09." + cYEAR )
nDAYS1 := 0
nDAYS2 := 0
lPRICE := .F.
cSEASON := "LOW"
nPRICE := 0
nCOUNT1 := 0 // LOW
nCOUNT2 := 0 // AVERAGE
nCOUNT3 := 0 // HIGHT
nCOUNT4 := 0 // LOW
nPRICE1 := 0 // LOW
nPRICE2 := 0 // AVERAGE
nPRICE3 := 0 // HIGHT
nPRICE4 := 0 // LOW

@ 0.5, 3 SAY oSay PROMPT "Price = .T. only used for Price-calculation"

@ 2, 5 SAY oSay PROMPT "Start"
@ 2, 13 SAY oSay PROMPT "End"
@ 2, 19 SAY oSay PROMPT "Price ?"

@ 3.2, 2  GET oGet1 VAR dDAY1 OF oDlg SIZE 40, 15  PICTURE "##.##.####"
@ 3.2, 8  GET oGet2 VAR dDAY2 OF oDlg SIZE 40, 15  PICTURE "##.##.####"
@ 3.2, 16  CHECKBOX oGet3 VAR lPRICE PROMPT "&Price" SIZE 100, 20 OF oDlg

@ 4, 2 BUTTON oBtn PROMPT "Date-Test" size 50, 25 OF oDlg ;
ACTION ( oGet1:Refresh(), oGet2:Refresh(), oGet3:Refresh(), ;
IIF( lPRICE = .F., ( nPRICE := GET_DATE( dDAY1, dDAY2, aSEASON ), ;
MsgAlert( STR(nDAYS1) + CRLF + STR(nDAYS2), cSEASON ) ), ;
( nPRICE := GET_PRICE( dDAY1, dDAY2, aSEASON ), ;
MsgAlert( "LOW : " + STR(nCOUNT1) + " * " + LTRIM(STR(aSEASON[1][3])) + " = " + LTRIM(STR(nPRICE1)) + CRLF + ;
"AVERAGE : " + STR(nCOUNT2) + " * " + LTRIM(STR(aSEASON[2][3]))+ " = " + LTRIM(STR(nPRICE2)) + CRLF + ;      
"HIGHT : " + STR(nCOUNT3) + " * " + LTRIM(STR(aSEASON[3][3]))+ " = " + LTRIM(STR(nPRICE3)) + CRLF + ;
"LOW : " + STR(nCOUNT4) + " * " + LTRIM(STR(aSEASON[4][3]))+ " = " + LTRIM(STR(nPRICE4)) + CRLF + CRLF + ;                     
"Days complete : " + LTRIM( STR ( 1 + (dDAY2 - dDAY1) ) ) + CRLF + CRLF + ;
"Price : " + STR( nPRICE ) + " Euro" , cSEASON ) ) ) )

ACTIVATE DIALOG oDlg CENTERED

RETURN ( NIL )

// ---------- PRICE - CALCULATION ----------------------------

FUNCTION GET_PRICE( dDAY1, dDAY2, aSEASON )

nDAYS1 := 0 // Basic Days
nDAYS2 := 0 // next Season Days

nCOUNT1 := 0 // LOW
nCOUNT2 := 0 // AVERAGE
nCOUNT3 := 0 // HIGHT
nCOUNT4 := 0 // LOW
nPRICE1 := 0 // LOW
nPRICE2 := 0 // AVERAGE
nPRICE3 := 0 // HIGHT
nPRICE4 := 0 // LOW
nPRICE := 0

// aSEASON[1] := { "17.05", "27.06" } // LOW
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// aSEASON[4] := { "30.08", "20.09" } // LOW

// -------------- LOW ---------------------------------------

// aSEASON[1] := { "17.05", "27.06" }
// -------- Test 18.05-15.09 -------------

// If   DAY1 >= SEASON_1.1   and    DAY2 <= SEASON_1.2
// ----------------------------------------------------------------------------
IF dDAY1 >= cTOD(aSEASON[1][1] ) .and. dDAY2 <=  cTOD(aSEASON[1][2])
   nCOUNT1 := 1 + ( dDAY2 - dDAY1 )
// msgalert( "LOW 1.1" )
ENDIF

// If   DAY1 <= SEASON_1.2   and    DAY2 > SEASON_1.2
// -------------------------------------------------------------------------
IF dDAY1 <= cTOD(aSEASON[1][2] ) .and. dDAY2 > cTOD(aSEASON[1][2])
   nCOUNT1 :=  1 + ( cTOD(aSEASON[1][2]) - dDAY1 )
// msgalert( "LOW 1.2" )
ENDIF

// -------------- AVERAGE ---------------------------------

// aSEASON[2] := { "28.06", "25.07" }
// ---------- Test 18.05-15.09  -----------

// If   DAY1 >= SEASON_2.1   and    DAY2 <= SEASON_2.2
// ---------------------------------------------------------------------------
IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. dDAY2 <= cTOD(aSEASON[2][2])
   nCOUNT2 := 1 + (dDAY2 - dDAY1)
// msgalert( "HEIGHT 2.1" )
ENDIF

// If   DAY1 < SEASON_2.1   and    DAY2 > SEASON_2.2
// ------------------------------------------------------------------------
IF dDAY1 < cTOD(aSEASON[2][1] ) .and. dDAY2 > cTOD(aSEASON[2][2])
   nCOUNT2 :=  1 + ( cTOD(aSEASON[2][2]) - cTOD(aSEASON[2][1]) )
// msgalert( "HEIGHT 2.2" )
ENDIF

// If   DAY1 < SEASON_2.1   and    DAY2 <= SEASON_2.2
// -------------------------------------------------------------------------
IF dDAY1 < cTOD(aSEASON[2][1] ) .and. dDAY2 >= cTOD(aSEASON[2][2])
   nCOUNT3 :=  1 + ( dDAY2 - cTOD(aSEASON[2][1]) )
// msgalert( "HEIGHT 2.3" )
ENDIF

// If   DAY1 >= SEASON_2.1   and    DAY2 > SEASON_2.2
// -------------------------------------------------------------------------
IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. dDAY2 > cTOD(aSEASON[2][2])
   nCOUNT2 :=  1 + ( cTOD(aSEASON[2][2]) - dDAY1 )
// msgalert( "HEIGHT 2.4" )
ENDIF

//------------- HIGHT ---------------------------------------

// aSEASON[3] := { "26.07", "29.08" }
// -------- Test 18.05-15.09 -------------

// If   DAY1 >= SEASON_3.1   and    DAY2 <= SEASON_3.2
// ---------------------------------------------------------------------------
IF dDAY1 >= cTOD(aSEASON[3][1] ) .and. dDAY2 <= cTOD(aSEASON[3][2])
   nCOUNT3 := 1 + (dDAY2 - dDAY1)
// msgalert( "HEIGHT 3.1" )
ENDIF

// If   DAY1 < SEASON_3.1   and    DAY2 > SEASON_3.2
// -----------------------------------------------------------------------
IF dDAY1 < cTOD(aSEASON[3][1] ) .and. dDAY2 > cTOD(aSEASON[3][2])
   nCOUNT3 :=  1 + ( cTOD(aSEASON[3][2]) - cTOD(aSEASON[3][1]) )
// msgalert( "HEIGHT 3.2" )
ENDIF

// If   DAY1 < SEASON_3.1   and    DAY2 <= SEASON_3.2
// -------------------------------------------------------------------------
IF dDAY1 < cTOD(aSEASON[3][1] ) .and. dDAY2 <= cTOD(aSEASON[3][2])
   nCOUNT3 :=  1 + ( dDAY2 - cTOD(aSEASON[3][1]) )
// msgalert( "HEIGHT 3.3" )
ENDIF

// If   DAY1 >= SEASON_3.1   and    DAY2 > SEASON_3.2
// --------------------------------------------------------------------------
IF dDAY1 >= cTOD(aSEASON[3][1] ) .and. dDAY2 > cTOD(aSEASON[3][2])
   nCOUNT3 :=  1 + ( cTOD(aSEASON[3][2]) - dDAY1 )
// msgalert( "HEIGHT 3.4" )
ENDIF

// ------------ LOW ---------------------------------------

// aSEASON[4] := { "30.08", "20.09" }
// --------- Test 18.05-15.09 ------------

// If   DAY1 >= SEASON_4.1   and    DAY2 <= SEASON_2.2
// ----------------------------------------------------------------------------
IF dDAY1 >= cTOD(aSEASON[4][1] ) .and. dDAY2 <= cTOD(aSEASON[4][2])
   nCOUNT4 := 1 + (dDAY2 - dDAY1)
// msgalert( "LOW 4.1" )
ENDIF

// If   DAY1 < SEASON_4.1   and    DAY2 > SEASON_4.1
// -----------------------------------------------------------------------
IF dDAY1 < cTOD(aSEASON[4][1] ) .and. dDAY2 > cTOD(aSEASON[4][1])
   nCOUNT4 :=  1 + ( dDAY2 - cTOD(aSEASON[4][1]) )
// msgalert( "LOW 4.2" )
ENDIF

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

cSTART := ""
cEND := ""
IF dDAY1 >= cTOD(aSEASON[1][1]) .and. dDAY1 <= cTOD(aSEASON[1][2])
   cSTART := "LOW"
ENDIF
IF dDAY1 >= cTOD(aSEASON[2][1]) .and. dDAY1 <= cTOD(aSEASON[2][2])
   cSTART := "AVERAGE"
ENDIF
IF dDAY1 >= cTOD(aSEASON[3][1]) .and. dDAY1 <= cTOD(aSEASON[3][2])
   cSTART := "HIGH"
ENDIF
IF dDAY1 >= cTOD(aSEASON[4][1]) .and. dDAY1 <= cTOD(aSEASON[4][2])
   cSTART := "LOW"
ENDIF

IF dDAY2 >= cTOD(aSEASON[1][1]) .and. dDAY2 <= cTOD(aSEASON[1][2])
   cEND := "LOW"
ENDIF
IF dDAY2 >= cTOD(aSEASON[2][1]) .and. dDAY2 <= cTOD(aSEASON[2][2])
   cEND := "AVERAGE"
ENDIF
IF dDAY2 >= cTOD(aSEASON[3][1]) .and. dDAY2 <= cTOD(aSEASON[3][2])
   cEND := "HIGH"
ENDIF
IF dDAY2 >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2])
   cEND := "LOW"
ENDIF

cSEASON := cSTART + " - " + cEND

nPRICE1 := nCOUNT1 * aSEASON[1][3]
nPRICE2 := nCOUNT2 * aSEASON[2][3]
nPRICE3 := nCOUNT3 * aSEASON[3][3]
nPRICE4 := nCOUNT4 * aSEASON[4][3]

nPRICE :=  nPRICE1 + nPRICE2 + nPRICE3 + nPRICE4

RETURN( nPRICE )

RETURN( nPrice )

// --------- DAY - CALCULATION -----------------------------

FUNCTION GET_DATE(dDAY1, dDAY2, aSEASON)

nDAYS1 := 0 // Basic Days
nDAYS2 := 0 // next Season Days

// LOW
// aSEASON[1] := { "17.05", "27.06" } // LOW
// -------- 20.05 - 24.06 = 36 x LOW -------------------  

IF dDAY1 >= cTOD(aSEASON[1][1] ) .and. dDAY2 <=  cTOD(aSEASON[1][2])
   cSEASON := "LOW"
   nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF


// LOW + AVERAGE
// aSEASON[1] := { "17.05", "27.06" } // LOW
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
// ---------- 26.05 - 12.07 =  33 x LOW +15 x AVERAGE ------------

IF dDAY1 >= cTOD(aSEASON[1][1] ) .and. ;
   ( dDAY2  >= cTOD(aSEASON[2][1]) .and. dDAY2 <= cTOD(aSEASON[2][2]) )
   cSEASON := "LOW+AVERAGE"
   nDAYS1 :=  1 + (cTOD(aSEASON[1][2]) - dDAY1)
   nDAYS2 :=  1 + (dDAY2 - cTOD(aSEASON[2][1]))
ENDIF

// AVERAGE
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
//------------- 29.06 - 22.07 = 25 x AVERAGE --------

IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. dDAY2 <= cTOD(aSEASON[2][2])
   cSEASON := "AVERAGE"
   nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF

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

// AVERAGE + HIGHT
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// --------10.07 - 14.08  = 16 x AVERAGE + 20 x HIGHT -------

IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. ;
   ( dDAY2  >= cTOD(aSEASON[3][1]) .and. dDAY2 <= cTOD(aSEASON[3][2]) )
   cSEASON := "AVERAGE+HEIGHT"
   nDAYS1 :=  1 + (cTOD(aSEASON[2][2]) - dDAY1)
   nDAYS2 :=  1 + (dDAY2 - cTOD(aSEASON[3][1]))
ENDIF

// HIGHT
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// --------18.08 - 14.09  = 28 x HEIGHT -------------

IF cTOD(aSEASON[3][1] ) >= dDAY1 .and. cTOD(aSEASON[3][2]) <= dDAY2
   cSEASON := "HIGH"
   nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF

// HIGHT + LOW
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// aSEASON[4] := { "30.08", "20.09" } // LOW
// --------- 14.08 - 16.09 = 16 x HIGHT + 17 x LOW ------

IF dDAY1 >= cTOD(aSEASON[3][1] ) .and. ;
  ( dDAY2  >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2]) )
   cSEASON := "HIGH+LOW"
   nDAYS1 :=  1 + (cTOD(aSEASON[3][2]) - dDAY1)
   nDAYS2 :=  1 + (dDAY2 - cTOD(aSEASON[4][1]))
ENDIF

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

// LOW
// aSEASON[4] := { "30.08", "20.09" } // LOW
// ---------------- 30.08 - 15.09 = 16 x LOW ----------------

IF dDAY1 >= cTOD(aSEASON[4][1] ) .and. dDAY2 <= cTOD(aSEASON[4][2])
   cSEASON := "LOW"
   nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF

RETURN( nDAYS1, nDAYS2, cSEASON )
 


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: Hight, Low and Average dates

Postby Silvio » Wed Apr 01, 2009 9:06 am

there is a error
the customer cannot pay - 68,00 € !!!!

Image
Best Regards, Saludos

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

Re: Hight, Low and Average dates

Postby ukoenig » Wed Apr 01, 2009 9:19 am

Silvio,

I have to cover / test all possible solutions. That makes it difficult.
The logic works and You can save all values to a database-field.
As well I added the season price in the message of the group-display.
If I do changes in the source, I will show a Update-Message with date.
on top of the source.

Image

The result-table to test all combinations :
Image

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: Hight, Low and Average dates

Postby ukoenig » Wed Apr 01, 2009 7:32 pm

Hello Silvio,

the calculation works fine now. With all tests, I got correct results.
The predefined tests from the menue are showing the results from the table.
It is a complete little application now.

Image

Code: Select all  Expand view

#include "FiveWin.ch"

STATIC nDAYS := 0, nPRICE := 0

FUNCTION MAIN()
local oWnd

SetBalloon( .T. ) // Balloon shape required for tooltips

SET DATE GERMAN
SET CENTURY ON  
SET DECIMALS TO 2
PRIVATE aDAYS[1][2]
PRIVATE aSEASON[4][3]
cYEAR := LTRIM( STR( YEAR(DATE()) ))

aSEASON[1] := { "17.05." + cYEAR, "27.06." + cYEAR, 7.00 } // LOW
aSEASON[2] := { "28.06." + cYEAR, "25.07." + cYEAR, 9.00 } // AVERAGE
aSEASON[3] := { "26.07." + cYEAR, "29.08." + cYEAR, 11.00 } // HIGHT
aSEASON[4] := { "30.08." + cYEAR, "20.09." + cYEAR, 7.00 } // LOW
dDAY1 := CTOD("18.05." + cYEAR )
dDAY2 := CTOD("15.09." + cYEAR )
lPRICE := .F.
cSEASON := "LOW"
nCOUNT1 := 0 // LOW
nCOUNT2 := 0 // AVERAGE
nCOUNT3 := 0 // HIGHT
nCOUNT4 := 0 // LOW
nPRICE1 := 0 // LOW
nPRICE2 := 0 // AVERAGE
nPRICE3 := 0 // HIGHT
nPRICE4 := 0 // LOW

DEFINE WINDOW oWnd TITLE "Price-Test"  MDI ;
MENU BuildMenu(oWnd)  //   TMenu():New()  

SET MESSAGE OF oWnd TO "Price-Test" ;
CENTERED CLOCK KEYBOARD 2007

ACTIVATE WINDOW oWnd MAXIMIZED ;
ON INIT PRICE_TEST(oWnd) ;
ON PAINT gradpaint0( hDC, oWnd )

RETURN NIL

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

static func gradpaint0( hDC, oWnd )

local aGrad := { { 0.50, 16054371, 11892819 } }

GradientFill( hDC,  0, 0, oWnd:nHeight, oWnd:nWidth, aGrad, .F. )

RETURN NIL

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

FUNCTION BuildMenu(oWnd)
local oMenu, oSub1, oSub2, oSub3, oSub4, oSub5, oSub7, oSub8, oSub9, oSub10, oSub11

MENU oMenu
    MENUITEM "&Season-Price-Tests"
    MENU
        MENUITEM oSub1 PROMPT "17.05. - 27.06.   => Only LOW"  ;
        ACTION ( nPRICE := GET_PRICE( cTOD("17.05.2009"), cTOD("27.06.2009"), aSEASON ))

        MENUITEM oSub2 PROMPT "28.06. - 25.07.   => Only AVERAGE"  ;
        ACTION ( nPRICE := GET_PRICE( cTOD("28.06.2009"), cTOD("25.07.2009"), aSEASON ))

        MENUITEM oSub3 PROMPT "26.07. - 29.08.   => Only HIGHT"  ;
        ACTION ( nPRICE := GET_PRICE( cTOD("26.07.2009"), cTOD("29.08.2009"), aSEASON ))

        MENUITEM oSub4 PROMPT "30.08. - 20.09.   => Only LOW"  ;
        ACTION ( nPRICE := GET_PRICE( cTOD("30.08.2009"), cTOD("20.09.2009"), aSEASON ))

        SEPARATOR

        MENUITEM oSub5 PROMPT "17.05. - 20.09.   => ALL"  ;
        ACTION ( nPRICE := GET_PRICE( cTOD("17.05.2009"), cTOD("20.09.2009"), aSEASON ))

        SEPARATOR

       
        MENUITEM oSub6 PROMPT "18.05. - 23.07.   => Combi LOW + AVARAGE"  ;
        ACTION ( nPRICE := GET_PRICE( cTOD("18.05.2009"), cTOD("23.07.2009"), aSEASON ))

        MENUITEM oSub7 PROMPT "22.07. - 26.08.   => Combi AVARAGE + HIGHT"  ;
        ACTION ( nPRICE := GET_PRICE( cTOD("22.07.2009"), cTOD("26.08.2009"), aSEASON ))

        MENUITEM oSub8 PROMPT "28.07. - 18.09.   => Combi HIGH + LOW"  ;
        ACTION ( nPRICE := GET_PRICE( cTOD("28.07.2009"), cTOD("18.09.2009"), aSEASON ))

        SEPARATOR

        MENUITEM oSub9 PROMPT "18.05. - 26.08.   => Combi LOW + AVARAGE + HIGH"  ;
        ACTION ( nPRICE := GET_PRICE( cTOD("18.05.2009"), cTOD("26.08.2009"), aSEASON ))

        MENUITEM oSub10 PROMPT "23.07. - 14.09.   => Combi AVARAGE + HIGH + LOW"  ;
        ACTION ( nPRICE := GET_PRICE( cTOD("23.07.2009"), cTOD("14.09.2009"), aSEASON ))

        SEPARATOR

        MENUITEM oSub11 PROMPT "START DIALOG"  ;
        ACTION ( PRICE_TEST(oWnd) )

      ENDMENU

ENDMENU

RETURN oMenu

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

FUNCTION PRICE_TEST(oWnd)
LOCAL oDlg, oBtn1, oBtn2, oSay, oGET1, oGET2, oGET3

DEFINE DIALOG oDlg SIZE 300, 220 TITLE "Price Test"

@ 0.5, 3 SAY oSay PROMPT "Price = .T. only used for Price-calculation"

@ 2, 5 SAY oSay PROMPT "Start"
@ 2, 13 SAY oSay PROMPT "End"
@ 2, 19 SAY oSay PROMPT "Price ?"

@ 3.2, 2  GET oGet1 VAR dDAY1 OF oDlg SIZE 40, 15  PICTURE "##.##.####"
@ 3.2, 8  GET oGet2 VAR dDAY2 OF oDlg SIZE 40, 15  PICTURE "##.##.####"
@ 3.2, 16  CHECKBOX oGet3 VAR lPRICE PROMPT "&Price" SIZE 100, 20 OF oDlg


@ 4, 2 BUTTON oBtn1 PROMPT "Date-Test" size 50, 25 OF oDlg ;
ACTION ( oGet1:Refresh(), oGet2:Refresh(), oGet3:Refresh(), ;
IIF( lPRICE = .F., (    nPRICE := GET_DATE( dDAY1, dDAY2, aSEASON ), ;
                MsgAlert( STR(nDAYS1) + CRLF + STR(nDAYS2), cSEASON ) ), ;
                 ( nPRICE := GET_PRICE( dDAY1, dDAY2, aSEASON ) ) ) )


@ 4, 15 BUTTON oBtn2 PROMPT "Close" size 50, 25 OF oDlg ;
ACTION ( oDlg:End() )

ACTIVATE DIALOG oDlg CENTERED

RETURN ( NIL )

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

FUNCTION GET_PRICE( dDAY1, dDAY2, aSEASON )

nDAYS1 := 0 // Basic Days
nDAYS2 := 0 // next Season Days

nCOUNT1 := 0 // LOW
nCOUNT2 := 0 // AVERAGE
nCOUNT3 := 0 // HIGHT
nCOUNT4 := 0 // LOW
nPRICE1 := 0 // LOW
nPRICE2 := 0 // AVERAGE
nPRICE3 := 0 // HIGHT
nPRICE4 := 0 // LOW

nDAYS := 0
nPRICE := 0

// aSEASON[1] := { "17.05", "27.06" } // LOW
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// aSEASON[4] := { "30.08", "20.09" } // LOW

// -------- Days Start and End inside Season-Group -------------

IF dDAY1 >= cTOD(aSEASON[1][1] )  .and.    dDAY2 <= cTOD(aSEASON[1][2] ) .or. ;
    dDAY1 >= cTOD(aSEASON[2][1] )  .and.    dDAY2 <= cTOD(aSEASON[2][2] ) .or. ;
    dDAY1 >= cTOD(aSEASON[3][1] )  .and.    dDAY2 <= cTOD(aSEASON[3][2] ) .or. ;
    dDAY1 >= cTOD(aSEASON[4][1] )  .and.    dDAY2 <= cTOD(aSEASON[4][2] )

    IF dDAY1 >= cTOD(aSEASON[1][1] ) .and. dDAY2 <=  cTOD(aSEASON[1][2])
        nCOUNT1 := 1 + ( dDAY2 - dDAY1 )
    ENDIF
    // ---------------------------------------------------------------------------
    IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. dDAY2 <= cTOD(aSEASON[2][2])
        nCOUNT2 := 1 + (dDAY2 - dDAY1)
    ENDIF
    // ---------------------------------------------------------------------------
    IF dDAY1 >= cTOD(aSEASON[3][1] ) .and. dDAY2 <= cTOD(aSEASON[3][2])
        nCOUNT3 := 1 + (dDAY2 - dDAY1)
    ENDIF
    // ----------------------------------------------------------------------------
    IF dDAY1 >= cTOD(aSEASON[4][1] ) .and. dDAY2 <= cTOD(aSEASON[4][2])
        nCOUNT4 := 1 + (dDAY2 - dDAY1)
    ENDIF
ENDIF

// -------- Days Start in 1. Season and End in 4. Season -------------

IF dDAY1 >= cTOD(aSEASON[1][1])  .and. dDAY1 <= cTOD(aSEASON[1][2]) .and. ;
    dDAY2 >= cTOD(aSEASON[4][1])  .and. dDAY2 <= cTOD(aSEASON[4][2])
    nCOUNT1 := 1 + ( cTOD(aSEASON[1][2]) - dDAY1 )
    nCOUNT2 := 1 + ( cTOD(aSEASON[2][2]) - cTOD(aSEASON[2][1]) )
    nCOUNT3 := 1 + ( cTOD(aSEASON[3][2]) - cTOD(aSEASON[3][1]) )
    nCOUNT4 := 1 + ( dDAY2 - cTOD(aSEASON[4][1]) )
ENDIF

// -------- Days Start in LOW Season and End in AVERAGE Season -------------

IF dDAY1 >= cTOD(aSEASON[1][1])  .and. dDAY1 <= cTOD(aSEASON[1][2]) .and. ;
    dDAY2 >= cTOD(aSEASON[2][1])  .and. dDAY2 <= cTOD(aSEASON[2][2])
    nCOUNT1 := 1 + ( cTOD(aSEASON[1][2]) - dDAY1 )
    nCOUNT2 := 1 + dDAY2 - ( cTOD(aSEASON[2][1]) )
ENDIF

// -------- Days Start in AVERAGE Season and End in HIGHT Season -------------

IF dDAY1 >= cTOD(aSEASON[2][1])  .and. dDAY1 <= cTOD(aSEASON[2][2]) .and. ;
    dDAY2 >= cTOD(aSEASON[3][1])  .and. dDAY2 <= cTOD(aSEASON[3][2])
    nCOUNT2 := 1 + ( cTOD(aSEASON[2][2]) - dDAY1 )
    nCOUNT3 := 1 + dDAY2 - ( cTOD(aSEASON[3][1]) )
ENDIF

// -------- Days Start in HIGHT Season and End in LOW Season -------------

IF dDAY1 >= cTOD(aSEASON[3][1])  .and. dDAY1 <= cTOD(aSEASON[3][2]) .and. ;
    dDAY2 >= cTOD(aSEASON[4][1])  .and. dDAY2 <= cTOD(aSEASON[4][2])
    nCOUNT3 := 1 + ( cTOD(aSEASON[3][2]) - dDAY1 )
    nCOUNT4 := 1 + dDAY2 - ( cTOD(aSEASON[4][1]) )
ENDIF

// -------- Days Start in LOW Season and End in HIGHT Season -------------

IF dDAY1 >= cTOD(aSEASON[1][1])  .and. dDAY1 <= cTOD(aSEASON[1][2]) .and. ;
    dDAY2 >= cTOD(aSEASON[3][1])  .and. dDAY2 <= cTOD(aSEASON[3][2])
    nCOUNT1 := 1 + ( cTOD(aSEASON[1][2]) - dDAY1 )
    nCOUNT2 := 1 + ( cTOD(aSEASON[2][2]) - cTOD(aSEASON[2][1]) )
    nCOUNT3 := 1 + dDAY2 - ( cTOD(aSEASON[3][1]) )
ENDIF

// -------- Days Start in AVERAGE Season and End in LOW Season -------------

IF dDAY1 >= cTOD(aSEASON[2][1])  .and. dDAY1 <= cTOD(aSEASON[2][2]) .and. ;
    dDAY2 >= cTOD(aSEASON[4][1])  .and. dDAY2 <= cTOD(aSEASON[4][2])
    nCOUNT2 := 1 + ( cTOD(aSEASON[2][2]) - dDAY1 )
    nCOUNT3 := 1 + ( cTOD(aSEASON[3][2]) - cTOD(aSEASON[3][1]) )
    nCOUNT4 := 1 + dDAY2 - ( cTOD(aSEASON[4][1]) )
ENDIF


cSTART := ""
cEND := ""
IF dDAY1 >= cTOD(aSEASON[1][1]) .and. dDAY1 <= cTOD(aSEASON[1][2])
    cSTART := "LOW"
ENDIF
IF dDAY1 >= cTOD(aSEASON[2][1]) .and. dDAY1 <= cTOD(aSEASON[2][2])
    cSTART := "AVERAGE"
ENDIF
IF dDAY1 >= cTOD(aSEASON[3][1]) .and. dDAY1 <= cTOD(aSEASON[3][2])
    cSTART := "HIGH"
ENDIF
IF dDAY1 >= cTOD(aSEASON[4][1]) .and. dDAY1 <= cTOD(aSEASON[4][2])
    cSTART := "LOW"
ENDIF

IF dDAY2 >= cTOD(aSEASON[1][1]) .and. dDAY2 <= cTOD(aSEASON[1][2])
    cEND := "LOW"
ENDIF
IF dDAY2 >= cTOD(aSEASON[2][1]) .and. dDAY2 <= cTOD(aSEASON[2][2])
    cEND := "AVERAGE"
ENDIF
IF dDAY2 >= cTOD(aSEASON[3][1]) .and. dDAY2 <= cTOD(aSEASON[3][2])
    cEND := "HIGH"
ENDIF
IF dDAY2 >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2])
    cEND := "LOW"
ENDIF

cSEASON := cSTART + " - " + cEND

nPRICE1 := nCOUNT1 * aSEASON[1][3]
nPRICE2 := nCOUNT2 * aSEASON[2][3]
nPRICE3 := nCOUNT3 * aSEASON[3][3]
nPRICE4 := nCOUNT4 * aSEASON[4][3]

nDAYS := nCOUNT1 + nCOUNT2 + nCOUNT3 + nCOUNT4
nPRICE :=  nPRICE1 + nPRICE2 + nPRICE3 + nPRICE4

MsgAlert( "LOW : " + STR(nCOUNT1) + " * " + LTRIM(STR(aSEASON[1][3])) + ;
          " = " + LTRIM(STR(nPRICE1)) + CRLF + ;
        "AVERAGE : " + STR(nCOUNT2) + " * " + LTRIM(STR(aSEASON[2][3])) + ;
          " = " + LTRIM(STR(nPRICE2)) + CRLF + ;                   
        "HIGHT : " + STR(nCOUNT3) + " * " + LTRIM(STR(aSEASON[3][3])) + ;
    " = " + LTRIM(STR(nPRICE3)) + CRLF + ;
        "LOW : " + STR(nCOUNT4) + " * " + LTRIM(STR(aSEASON[4][3])) + ;
    " = " + LTRIM(STR(nPRICE4)) + CRLF + CRLF + ;                      
        "Days complete : " + LTRIM( STR ( 1 + (dDAY2 - dDAY1) ) ) + CRLF + CRLF + ;
        "Price : " + STR( nPRICE ) + " Euro" , cSEASON )

RETURN( nDAYS, nPRICE )

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

FUNCTION GET_DATE(dDAY1, dDAY2, aSEASON)

nDAYS1 := 0 // Basic Days
nDAYS2 := 0 // next Season Days

// LOW
// aSEASON[1] := { "17.05", "27.06" } // LOW
// -------- 20.05 - 24.06 = 36 x LOW -------------------  

IF dDAY1 >= cTOD(aSEASON[1][1] ) .and. dDAY2 <=  cTOD(aSEASON[1][2])
    cSEASON := "LOW"
    nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF


// LOW + AVERAGE
// aSEASON[1] := { "17.05", "27.06" } // LOW
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
// ---------- 26.05 - 12.07 =  33 x LOW +15 x AVERAGE ------------

IF dDAY1 >= cTOD(aSEASON[1][1] ) .and. ;
    ( dDAY2  >= cTOD(aSEASON[2][1]) .and. dDAY2 <= cTOD(aSEASON[2][2]) )
    cSEASON := "LOW+AVERAGE"
    nDAYS1 :=  1 + (cTOD(aSEASON[1][2]) - dDAY1)
    nDAYS2 :=  1 + (dDAY2 - cTOD(aSEASON[2][1]))
ENDIF

// AVERAGE
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
//------------- 29.06 - 22.07 = 25 x AVERAGE --------

IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. dDAY2 <= cTOD(aSEASON[2][2])
    cSEASON := "AVERAGE"
    nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF

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

// AVERAGE + HIGHT
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// --------10.07 - 14.08  = 16 x AVERAGE + 20 x HIGHT -------

IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. ;
    ( dDAY2  >= cTOD(aSEASON[3][1]) .and. dDAY2 <= cTOD(aSEASON[3][2]) )
    cSEASON := "AVERAGE+HEIGHT"
    nDAYS1 :=  1 + (cTOD(aSEASON[2][2]) - dDAY1)
    nDAYS2 :=  1 + (dDAY2 - cTOD(aSEASON[3][1]))
ENDIF

// HIGHT
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// --------18.08 - 14.09  = 28 x HEIGHT -------------

IF cTOD(aSEASON[3][1] ) >= dDAY1 .and. cTOD(aSEASON[3][2]) <= dDAY2
    cSEASON := "HIGH"
    nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF

// HIGHT + LOW
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// aSEASON[4] := { "30.08", "20.09" } // LOW
// --------- 14.08 - 16.09 = 16 x HIGHT + 17 x LOW ------

IF dDAY1 >= cTOD(aSEASON[3][1] ) .and. ;
    ( dDAY2  >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2]) )
    cSEASON := "HIGH+LOW"
    nDAYS1 :=  1 + (cTOD(aSEASON[3][2]) - dDAY1)
    nDAYS2 :=  1 + (dDAY2 - cTOD(aSEASON[4][1]))
ENDIF

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

// LOW
// aSEASON[4] := { "30.08", "20.09" } // LOW
// ---------------- 30.08 - 15.09 = 16 x LOW ----------------

IF dDAY1 >= cTOD(aSEASON[4][1] ) .and. dDAY2 <= cTOD(aSEASON[4][2])
    cSEASON := "LOW"
    nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF

RETURN( nDAYS1, nDAYS2, cSEASON )
 


Regards
Uwe :lol:
Last edited by ukoenig on Thu Apr 02, 2009 8:16 am, edited 1 time 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: Hight, Low and Average dates

Postby Silvio » Thu Apr 02, 2009 8:13 am

thanks Uwe,

How I can modify your functions ?
Now I need a function return bach only tre variables : number daysLow, number dayshight, number daysAverage if I give it only two date ( date_init and date_end)
Best Regards, Saludos

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

Re: Hight, Low and Average dates

Postby ukoenig » Thu Apr 02, 2009 9:37 am

Hello Silvio,

inside the calculation, no change is needed, because it is only the Day-calculation.
I did some small changes.
Now with the switch Price Y / N, You can change the MsgAlert between Price and Days.
The predefined Menue-calculations are also working for both solutions.
The vars You asked for are :
LOW = nDAYS1, AVERAGE = nDAYS2, HIGHT = nDAYS3, LOW = nDAYS4 and COMPLETE = nDAYS.
The Button Day-Test displays different Alerts with setting Price Y or N
Image
Code: Select all  Expand view

#include "FiveWin.ch"

STATIC nDAYS := 0, nPRICE := 0, lPRICE := .F., LDAYS := .F.
STATIC nDAYS1 := 0, nDAYS2 := 0, nDAYS3 := 0, nDAYS4 := 0

FUNCTION MAIN()
local oWnd

SetBalloon( .T. ) // Balloon shape required for tooltips

SET DATE GERMAN
SET CENTURY ON  
SET DECIMALS TO 2
PRIVATE aDAYS[1][2]
PRIVATE aSEASON[4][3]

// Optional DAY-Array
// ----------------------
PRIVATE aDAYS[3][1]
aDAYS[1][1] := 0
aDAYS[2][1] := 0
aDAYS[3][1] := 0
lDAYS := .F.

cYEAR := LTRIM( STR( YEAR(DATE()) ))

aSEASON[1] := { "17.05." + cYEAR, "27.06." + cYEAR, 7.00 } // LOW
aSEASON[2] := { "28.06." + cYEAR, "25.07." + cYEAR, 9.00 } // AVERAGE
aSEASON[3] := { "26.07." + cYEAR, "29.08." + cYEAR, 11.00 } // HIGHT
aSEASON[4] := { "30.08." + cYEAR, "20.09." + cYEAR, 7.00 } // LOW
dDAY1 := CTOD("18.05." + cYEAR )
dDAY2 := CTOD("15.09." + cYEAR )

lPRICE := .F.
cSEASON := "LOW"

nDAYS1 := 0 // LOW
nDAYS2 := 0 // AVERAGE
nDAYS3 := 0 // HIGHT
nDAYS4 := 0 // LOW

nPRICE1 := 0 // LOW
nPRICE2 := 0 // AVERAGE
nPRICE3 := 0 // HIGHT
nPRICE4 := 0 // LOW

DEFINE WINDOW oWnd TITLE "Price-Test"  MDI ;
MENU BuildMenu(oWnd)  //   TMenu():New()  

SET MESSAGE OF oWnd TO "Price-Test" ;
CENTERED CLOCK KEYBOARD 2007

ACTIVATE WINDOW oWnd MAXIMIZED ;
ON INIT PRICE_DAYS(oWnd) ;
ON PAINT gradpaint0( hDC, oWnd )

RETURN NIL

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

static func gradpaint0( hDC, oWnd )
local oBmp1
local aGrad := { { 0.50, 16054371, 11892819 } }

GradientFill( hDC,  0, 0, oWnd:nHeight, oWnd:nWidth, aGrad, .F. )
DEFINE BITMAP oBmp1 FILENAME "User.bmp"
ABPaint( hDC, 40, 45, oBmp1:hBitmap, 220 )

RETURN NIL

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

FUNCTION BuildMenu(oWnd)
local oMenu

MENU oMenu
    MENUITEM "&Season-Price- and Day-Tests"
    MENU
        MENUITEM oFirst PROMPT "17.05. - 27.06.   => Only LOW"  ;
        ACTION ( nPRICE := GET_DAYS( cTOD("17.05.2009"), cTOD("27.06.2009"), aSEASON ))

        MENUITEM oFirst PROMPT "28.06. - 25.07.   => Only AVERAGE"  ;
        ACTION ( nPRICE := GET_DAYS( cTOD("28.06.2009"), cTOD("25.07.2009"), aSEASON ))

        MENUITEM oFirst PROMPT "26.07. - 29.08.   => Only HIGHT"  ;
        ACTION ( nPRICE := GET_DAYS( cTOD("26.07.2009"), cTOD("29.08.2009"), aSEASON ))

        MENUITEM oFirst PROMPT "30.08. - 20.09.   => Only LOW"  ;
        ACTION ( nPRICE := GET_DAYS( cTOD("30.08.2009"), cTOD("20.09.2009"), aSEASON ))

        SEPARATOR

        MENUITEM oFirst PROMPT "17.05. - 20.09.   => ALL"  ;
        ACTION ( nPRICE := GET_DAYS( cTOD("17.05.2009"), cTOD("20.09.2009"), aSEASON ))

        SEPARATOR
       
        MENUITEM oFirst PROMPT "18.05. - 23.07.   => Combi LOW + AVARAGE"  ;
        ACTION ( nPRICE := GET_DAYS( cTOD("18.05.2009"), cTOD("23.07.2009"), aSEASON ))

        MENUITEM oFirst PROMPT "22.07. - 26.08.   => Combi AVARAGE + HIGHT"  ;
        ACTION ( nPRICE := GET_DAYS( cTOD("22.07.2009"), cTOD("26.08.2009"), aSEASON ))

        MENUITEM oFirst PROMPT "28.07. - 18.09.   => Combi HIGH + LOW"  ;
        ACTION ( nPRICE := GET_DAYS( cTOD("28.07.2009"), cTOD("18.09.2009"), aSEASON ))

        SEPARATOR

        MENUITEM oFirst PROMPT "18.05. - 26.08.   => Combi LOW + AVARAGE + HIGH"  ;
        ACTION ( nPRICE := GET_DAYS( cTOD("18.05.2009"), cTOD("26.08.2009"), aSEASON ))

        MENUITEM oFirst PROMPT "23.07. - 14.09.   => Combi AVARAGE + HIGH + LOW"  ;
        ACTION ( nPRICE := GET_DAYS( cTOD("23.07.2009"), cTOD("14.09.2009"), aSEASON ))

        SEPARATOR

        MENUITEM oFirst PROMPT "START Price-DIALOG"  ;
        ACTION ( PRICE_DAYS(oWnd) )

    ENDMENU

ENDMENU

RETURN oMenu

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

FUNCTION PRICE_DAYS(oWnd)
LOCAL oBtn1, oBtn2, oGET, oGET1, oGET2, oGET3, oGET4, oGroup, oBmp1

DEFINE DIALOG oDlg SIZE 400, 290 TITLE "Price Test" TRANSPARENT

@ 0.6, 1.5 GROUP oGroup TO  7.5, 27 PROMPT "Calculation" OF oDlg  COLOR CLR_YELLOW, CLR_BLUE
oGroup:ltransparent:=.T.

@ 3.2, 3 SAY oSay PROMPT "Price = .T. only used for Price-calculation ( Days-Array = .F. )"
@ 3.8, 3 SAY oSay PROMPT "Price = .F. and Days-Array = .T. Displays Days as Array"

@ 4.8, 5 SAY oSay PROMPT "Start"
@ 4.8, 13 SAY oSay PROMPT "End"
@ 4.8, 20 SAY oSay PROMPT "Price or Days-Array ?"

@ 6.5, 2  GET oGet1 VAR dDAY1 OF oDlg SIZE 40, 15  PICTURE "##.##.####" UPDATE
@ 6.5, 8  GET oGet2 VAR dDAY2 OF oDlg SIZE 40, 15  PICTURE "##.##.####" UPDATE
@ 6.5, 17  CHECKBOX oGet3 VAR lPRICE PROMPT "&Price" SIZE 50, 20 OF oDlg UPDATE
@ 6.5, 21  CHECKBOX oGet4 VAR lDAYS PROMPT "&Day-Array" SIZE 80, 20 OF oDlg UPDATE

@ 6.2, 1.9 BUTTON oBtn1 PROMPT "Date-Test" size 50, 25 OF oDlg ;
ACTION ( oDlg:Update(), ;
   IIF( lDAYS = .F., GET_DAYS( dDAY1, dDAY2, aSEASON ), ;
      ( GET_DAYS( dDAY1, dDAY2, aSEASON ), ;
       MsgAlert( "LOW : " + STR(aDAYS[1][1]) + " Days" + CRLF + ;
       "AVERAGE : " + STR(aDAYS[2][1]) + " Days" + CRLF + ;
       "HEIGHT : " + STR(aDAYS[3][1]) + " Days", "Day-Array" ) ) ) )

@ 6.2, 23 BUTTON oBtn2 PROMPT "Close" size 50, 25 OF oDlg ;
ACTION ( oDlg:End() )

ACTIVATE DIALOG oDlg CENTERED ;
ON PAINT gradpaint1( hDC, oDlg )  

RETURN( NIL )

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

FUNCTION GET_DAYS( dDAY1, dDAY2, aSEASON )

nDAYS1 := 0 // LOW
nDAYS2 := 0 // AVERAGE
nDAYS3 := 0 // HIGHT
nDAYS4 := 0 // LOW

nPRICE1 := 0 // LOW
nPRICE2 := 0 // AVERAGE
nPRICE3 := 0 // HIGHT
nPRICE4 := 0 // LOW

nDAYS := 0
nPRICE := 0

// aSEASON[1] := { "17.05", "27.06" } // LOW
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// aSEASON[4] := { "30.08", "20.09" } // LOW

// -------- Days Start and End inside Season-Group -------------

IF dDAY1 >= cTOD(aSEASON[1][1] )  .and.    dDAY2 <= cTOD(aSEASON[1][2] ) .or. ;
    dDAY1 >= cTOD(aSEASON[2][1] )  .and.    dDAY2 <= cTOD(aSEASON[2][2] ) .or. ;
    dDAY1 >= cTOD(aSEASON[3][1] )  .and.    dDAY2 <= cTOD(aSEASON[3][2] ) .or. ;
    dDAY1 >= cTOD(aSEASON[4][1] )  .and.    dDAY2 <= cTOD(aSEASON[4][2] )

    IF dDAY1 >= cTOD(aSEASON[1][1] ) .and. dDAY2 <=  cTOD(aSEASON[1][2])
        nDAYS1 := 1 + ( dDAY2 - dDAY1 )
    ENDIF
    // ---------------------------------------------------------------------------
    IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. dDAY2 <= cTOD(aSEASON[2][2])
        nDAYS2 := 1 + (dDAY2 - dDAY1)
    ENDIF
    // ---------------------------------------------------------------------------
    IF dDAY1 >= cTOD(aSEASON[3][1] ) .and. dDAY2 <= cTOD(aSEASON[3][2])
        nDAYS3 := 1 + (dDAY2 - dDAY1)
    ENDIF
    // ----------------------------------------------------------------------------
    IF dDAY1 >= cTOD(aSEASON[4][1] ) .and. dDAY2 <= cTOD(aSEASON[4][2])
        nDAYS4 := 1 + (dDAY2 - dDAY1)
    ENDIF
ENDIF

// -------- Days Start in 1. Season and End in 4. Season -------------

IF dDAY1 >= cTOD(aSEASON[1][1])  .and. dDAY1 <= cTOD(aSEASON[1][2]) .and. ;
    dDAY2 >= cTOD(aSEASON[4][1])  .and. dDAY2 <= cTOD(aSEASON[4][2])
    nDAYS1 := 1 + ( cTOD(aSEASON[1][2]) - dDAY1 )
    nDAYS2 := 1 + ( cTOD(aSEASON[2][2]) - cTOD(aSEASON[2][1]) )
    nDAYS3 := 1 + ( cTOD(aSEASON[3][2]) - cTOD(aSEASON[3][1]) )
    nDAYS4 := 1 + ( dDAY2 - cTOD(aSEASON[4][1]) )
ENDIF

// -------- Days Start in LOW Season and End in AVERAGE Season -------------

IF dDAY1 >= cTOD(aSEASON[1][1])  .and. dDAY1 <= cTOD(aSEASON[1][2]) .and. ;
    dDAY2 >= cTOD(aSEASON[2][1])  .and. dDAY2 <= cTOD(aSEASON[2][2])
    nDAYS1 := 1 + ( cTOD(aSEASON[1][2]) - dDAY1 )
    nDAYS2 := 1 + dDAY2 - ( cTOD(aSEASON[2][1]) )
ENDIF

// -------- Days Start in AVERAGE Season and End in HIGHT Season -------------

IF dDAY1 >= cTOD(aSEASON[2][1])  .and. dDAY1 <= cTOD(aSEASON[2][2]) .and. ;
    dDAY2 >= cTOD(aSEASON[3][1])  .and. dDAY2 <= cTOD(aSEASON[3][2])
    nDAYS2 := 1 + ( cTOD(aSEASON[2][2]) - dDAY1 )
    nDAYS3 := 1 + dDAY2 - ( cTOD(aSEASON[3][1]) )
ENDIF

// -------- Days Start in HIGHT Season and End in LOW Season -------------

IF dDAY1 >= cTOD(aSEASON[3][1])  .and. dDAY1 <= cTOD(aSEASON[3][2]) .and. ;
    dDAY2 >= cTOD(aSEASON[4][1])  .and. dDAY2 <= cTOD(aSEASON[4][2])
    nDAYS3 := 1 + ( cTOD(aSEASON[3][2]) - dDAY1 )
    nDAYS4 := 1 + dDAY2 - ( cTOD(aSEASON[4][1]) )
ENDIF

// -------- Days Start in LOW Season and End in HIGHT Season -------------

IF dDAY1 >= cTOD(aSEASON[1][1])  .and. dDAY1 <= cTOD(aSEASON[1][2]) .and. ;
    dDAY2 >= cTOD(aSEASON[3][1])  .and. dDAY2 <= cTOD(aSEASON[3][2])
    nDAYS1 := 1 + ( cTOD(aSEASON[1][2]) - dDAY1 )
    nDAYS2 := 1 + ( cTOD(aSEASON[2][2]) - cTOD(aSEASON[2][1]) )
    nDAYS3 := 1 + dDAY2 - ( cTOD(aSEASON[3][1]) )
ENDIF

// -------- Days Start in AVERAGE Season and End in LOW Season -------------

IF dDAY1 >= cTOD(aSEASON[2][1])  .and. dDAY1 <= cTOD(aSEASON[2][2]) .and. ;
    dDAY2 >= cTOD(aSEASON[4][1])  .and. dDAY2 <= cTOD(aSEASON[4][2])
    nDAYS2 := 1 + ( cTOD(aSEASON[2][2]) - dDAY1 )
    nDAYS3 := 1 + ( cTOD(aSEASON[3][2]) - cTOD(aSEASON[3][1]) )
    nDAYS4 := 1 + dDAY2 - ( cTOD(aSEASON[4][1]) )
ENDIF

cSTART := ""
cEND := ""
IF dDAY1 >= cTOD(aSEASON[1][1]) .and. dDAY1 <= cTOD(aSEASON[1][2])
    cSTART := "LOW"
ENDIF
IF dDAY1 >= cTOD(aSEASON[2][1]) .and. dDAY1 <= cTOD(aSEASON[2][2])
    cSTART := "AVERAGE"
ENDIF
IF dDAY1 >= cTOD(aSEASON[3][1]) .and. dDAY1 <= cTOD(aSEASON[3][2])
    cSTART := "HIGH"
ENDIF
IF dDAY1 >= cTOD(aSEASON[4][1]) .and. dDAY1 <= cTOD(aSEASON[4][2])
    cSTART := "LOW"
ENDIF

IF dDAY2 >= cTOD(aSEASON[1][1]) .and. dDAY2 <= cTOD(aSEASON[1][2])
    cEND := "LOW"
ENDIF
IF dDAY2 >= cTOD(aSEASON[2][1]) .and. dDAY2 <= cTOD(aSEASON[2][2])
    cEND := "AVERAGE"
ENDIF
IF dDAY2 >= cTOD(aSEASON[3][1]) .and. dDAY2 <= cTOD(aSEASON[3][2])
    cEND := "HIGH"
ENDIF
IF dDAY2 >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2])
    cEND := "LOW"
ENDIF

cSEASON := cSTART + " - " + cEND
nDAYS := nDAYS1 + nDAYS2 + nDAYS3 + nDAYS4

IF lPRICE = .T. .and. lDAYS = .F.
    nPRICE1 := nDAYS1 * aSEASON[1][3]
    nPRICE2 := nDAYS2 * aSEASON[2][3]
    nPRICE3 := nDAYS3 * aSEASON[3][3]
    nPRICE4 := nDAYS4 * aSEASON[4][3]
    nPRICE :=  nPRICE1 + nPRICE2 + nPRICE3 + nPRICE4

    MsgAlert( "LOW :  " + STR(nDAYS1) + " * " + LTRIM(STR(aSEASON[1][3])) + ;
              " = " + LTRIM(STR(nPRICE1)) + " Euro" + CRLF + ;
            "AVERAGE :  " + STR(nDAYS2) + " * " + LTRIM(STR(aSEASON[2][3])) + ;
              " = " + LTRIM(STR(nPRICE2)) + " Euro" + CRLF + ;                 
            "HIGHT :  " + STR(nDAYS3) + " * " + LTRIM(STR(aSEASON[3][3])) + ;
        " = " + LTRIM(STR(nPRICE3)) + " Euro" + CRLF + ;
           "LOW :  " + STR(nDAYS4) + " * " + LTRIM(STR(aSEASON[4][3])) + ;
        " = " + LTRIM(STR(nPRICE4)) + " Euro" + CRLF + CRLF + ;                    
            "Days complete :  " + LTRIM( STR ( 1 + (dDAY2 - dDAY1) ) ) + " Days" + CRLF + CRLF + ;
            "Price :  " + STR( nPRICE ) + " Euro" , cSEASON )
ENDIF
IF lPRICE = .F. .and. lDAYS = .F.
    MsgAlert( "LOW :  " + STR(nDAYS1) + " Days" + CRLF + ;       
            "AVERAGE :  " + STR(nDAYS2) + " Days" + CRLF + ; 
            "HIGHT :  " + STR(nDAYS3) + " Days" + CRLF + ;
            "LOW :  " + STR(nDAYS4) + " Days"  + CRLF + CRLF + ;                     
            "Days complete :  " + LTRIM( STR ( 1 + (dDAY2 - dDAY1) ) ) + " Days", cSEASON )
ENDIF
IF lPRICE = .F. .and. lDAYS = .T.
    aDAYS[1][1] := nDAYS1 + nDAYS4
    aDAYS[2][1] := nDAYS2
    aDAYS[3][1] := nDAYS3
ENDIF

RETURN( nDAYS, nPRICE, aDAYS )
 


Regards
Uwe :lol:
Last edited by ukoenig on Fri Apr 03, 2009 1:17 pm, edited 1 time 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: Hight, Low and Average dates

Postby ukoenig » Fri Apr 03, 2009 1:05 pm

Hello Silvio,

Optional, You can save the Days to a Array,
LOW1 and LOW2 are added. You get a Array with 3 Values : LOW, AVERAGE and HIGH.
The changes are included in the code above.

Image

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: karinha and 29 guests