#include "FiveWin.Ch"
#include "hbcompat.ch"
#include "ord.ch"
#include "xbrowse.ch"
#include "dtpicker.ch"
//----------------------------------------------------------------------------//
REQUEST DBFCDX
//----------------------------------------------------------------------------//
static aBusy := {}
static aStatus := { "Reserved", "Confirmed", "Occupied", "Canceled", "Empty" }
//----------------------------------------------------------------------------//
function Main()
SET DATE ITALIAN
SET CENTURY ON
SET DELETED ON
SetGetColorFocus()
XBrNumFormat( 'E', .t. )
ReIndexData()
OpenData()
ShowRoomStatus()
return (0)
//----------------------------------------------------------------------------//
static function ShowRoomStatus()
local dStart := STOD( "20130301" )
local dEnd := STOD( "20130304" )
local d1, d2, nFilter := 1
//
local oDlg, oFont, oBrwRooms, oBrwReserva, oCbx
local aGet[2]
//
local nDefinition := 1
aDefinitions :={ "No definition",;
"To Pay Off" ,;
"With Option" ,;
"Check In" ,;
"Check Out" ,;
"Arrive" ,;
"Departure" ,;
"Voucher" }
GetBusyRooms( d1 := dStart, d2 := dEnd, nDefinition )
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 900,500 PIXEL FONT oFont;
TITLE "Check Reserva Situation"
@ 10, 10 SAY "From Night Of" SIZE 80,10 PIXEL OF oDlg
@ 10,100 SAY "Upto Night Of" SIZE 80,20 PIXEL OF oDlg
@ 20, 10 DTPICKER aGet[1] VAR dStart SIZE 80,12 PIXEL OF oDlg UPDATE;
ON CHANGE ( If( d1 != dStart, ;
( GetBusyRooms( d1 := Min( dStart, dEnd ), d2 := Max( dStart, dEnd ),nDefinition ), ;
oBrwRooms:Refresh(), oBrwReserva:Refresh(), oDlg:Update() ), nil ), .t. )
@ 20,100 DTPICKER aGet[2] VAR dEnd SIZE 80,12 PIXEL OF oDlg UPDATE;
ON CHANGE ( If( d2 != dEnd, ;
( GetBusyRooms( d1 := Min( dStart, dEnd ), d2 := Max( dStart, dEnd ), nDefinition ), ;
oBrwRooms:Refresh(), oBrwReserva:Refresh(),oDlg:Update() ), nil ), .t. )
@ 10,230 RADIO oRad VAR nFilter ITEMS "Show All", "Free Only", "Busy Only" ;
SIZE 80,10 PIXEL OF oDlg ;
ON CHANGE ROOMS->( SetRoomsFilter( oBrwRooms, nFilter ), ;
oBrwRooms:Refresh(),oBrwReserva:Refresh(), oBrwRooms:SetFocus() )
@ 10, 330 SAY "Reserva definitions " SIZE 200,10 PIXEL OF oDlg
@ 24,330 COMBOBOX oCbx VAR nDefinition ITEMS aDefinitions ;
SIZE 80,40 PIXEL OF oDlg ;
ON CHANGE( SetOptionFilter( nDefinition,d1,d2,dstart,dEnd,aGet),;
ROOMS->( SetRoomsFilter( oBrwRooms, nDefinition ), ;
oBrwRooms:Refresh() ,;
oBrwReserva:Refresh(),;
oBrwRooms:SetFocus() ) )
@ 35, 10 SAY "Room Status between " + DTOC( Min( dStart, dEnd ) ) + " and " + ;
DTOC( Max( dStart, dEnd ) ) SIZE 200,10 PIXEL OF oDlg UPDATE
@ 50, 10 XBROWSE oBrwRooms SIZE 150,-20 PIXEL OF oDlg DATASOURCE "ROOMS" ;
COLUMNS "ID", "NAME", { || AScan( aBusy, ROOMS->ID ) == 0 } ;
HEADERS "No", "RoomName", "Status" ;
COLSIZES nil, 20, 70 ;
CELL LINES NOBORDER
@ 50,170 XBROWSE oBrwReserva SIZE -10,-20 PIXEL OF oDlg DATASOURCE "RESERVA" ;
COLUMNS "ROOMS_ID", "CHECK_IN", "CHECK_OUT", "STATUS", "GUEST","TOPAYOFF",;
"OPTION", "LARRIVE", "LDEPARTURE", "VOUCHER" ;
HEADERS "ID", "CheckIN", "CheckOUT", "Status", "Guest","ToPayOff" ,;
"Option","Arrive","Departure","Voucher" ;
COLSIZES nil,80,80,40,90,20,70,20,20,50 ;
CELL LINES NOBORDER
WITH OBJECT oBrwRooms
:Status:SetCheck( { 0, 0 }, nil, { "Free", "Busy" } )
:nStretchCol := 2
:bChange := { || oBrwReserva:Refresh() }
:bClrStd := { || If( oBrwRooms:Status:Value, { CLR_BLACK, CLR_WHITE }, { CLR_WHITE, CLR_HRED } ) }
:bClrSel := { || { CLR_BLACK, CLR_HGRAY } }
:SetGroupHeader( "ROOMS" )
//
:CreateFromCode()
END
WITH OBJECT oBrwReserva
:Status:bEditValue := { || aStatus[ Val( RESERVA->STATUS ) ] }
:bClrSel := { || { CLR_BLACK, CLR_HGRAY } }
:bClrStd := { || If( RESERVA->STATUS == '04', { CLR_BLACK, RGB( 160, 210, 255 ) }, ;
If( RESERVA->STATUS == '05', { CLR_BLACK, RGB( 160, 255, 200 ) }, ;
If( RESERVA->CHECK_OUT > d1 .AND. RESERVA->CHECK_IN <= d2, ;
{ CLR_WHITE, CLR_HRED }, { CLR_BLACK, CLR_WHITE } ) ) ) }
:SetGroupHeader( "RESERVATIONS" )
//
:CreateFromCode()
END
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT ( oBrwRooms:SetFocus(), .f. )
return nil
//----------------------------------------------------------------------------//
static function OpenData()
field ID
USE RESERVA NEW SHARED VIA "DBFCDX"
SET ORDER TO TAG ROOM_IN
GO TOP
USE RESERVA NEW SHARED ALIAS "RES" VIA "DBFCDX"
GO TOP
USE ROOMS NEW SHARED VIA "DBFCDX"
SET ORDER TO TAG ROOMS_OD
GO TOP
SET RELATION TO ID INTO RESERVA SCOPED
GO TOP
return .t.
//----------------------------------------------------------------------------//
static function GetBusyRooms( dStart, dEnd , nDefinition)
field ROOMS_ID, CHECK_IN, CHECK_OUT, STATUS, TOPAYOFF, OPTION, LARRIVE, LDEPARTURE, VOUCHER
local cCond, bCond
ASize( aBusy, 0 )
cCond := "CHECK_OUT > STOD('" + DTOS( dStart ) + "' ) .AND. " + ;
"CHECK_IN <= STOD('" + DTOS( dEnd ) + "' )"
cCond += ".AND. STATUS < '04'"
//OTHER DEFINITIONS
DO CASE
case nDefinition = 2
cCond += ".AND. TOPAYOFF = .T."
case nDefinition = 3
cCond += ".AND. ! EMPTY(OPTION)"
case nDefinition = 4
cCond += ".AND. CHECK_IN = STOD('" + DTOS( dStart ) + "' )"
case nDefinition = 5
cCond += ".AND. CHECK_OUT = STOD('" + DTOS( dStart ) + "' )"
case nDefinition = 6
cCond += ".AND. LARRIVE = .T. "
case nDefinition = 7
cCond += ".AND. LDEPARTURE = .T."
case nDefinition = 8
cCond += ".AND. !EMPTY(VOUCHER)"
Endcase
bCond := &( "{ || " + cCond + " }" )
RES->( DBSETFILTER( bCond, cCond ), DBGOTOP() )
RES->( DBEVAL( { || AAdd( aBusy, ROOMS_ID ) } ) )
RES->( DBCLEARFILTER() )
return aBusy
//----------------------------------------------------------------------------//
Static Function SetOptionFilter(nDefinition,d1,d2,dStart,dEnd,aGet)
Do Case
Case nDefinition = 2
Case nDefinition = 3
Case nDefinition = 4
DStart:= Date()
DEnd := Date()
Case nDefinition = 5
DStart:= Date()
DEnd := Date()
Case nDefinition = 6
DStart:= Date()
DEnd := Date()
Case nDefinition = 7
DStart:= Date()
DEnd := Date()
Case nDefinition = 8
EndCase
aGet[1]:refresh()
aGet[2]:refresh()
d1 := dStart
d2 := dEnd
return nil
//----------------------------------------------------------------------------//
static function SetRoomsFilter( oBrw, nFilter )
FIELD ID
static nPrevFilter := 1
if nPrevFilter != nFilter
if nFilter == 2
SET FILTER TO ASCAN( aBusy, ID ) == 0
elseif nFilter == 3
SET FILTER TO ASCAN( aBusy, ID ) > 0
ELSE
SET FILTER TO
ENDIF
GO TOP
nPrevFilter := nFilter
oBrw:Refresh()
endif
return nil
//----------------------------------------------------------------------------//
static function ReIndexData()
field ID,ROOMS_ID,CHECK_IN, CHECK_OUT, STATUS
ferase( "rooms.cdx" )
ferase( "reserva.cdx" )
USE ROOMS NEW EXCLUSIVE VIA "DBFCDX"
INDEX ON ID TAG ROOMS_ID
CLOSE DATA
USE RESERVA NEW EXCLUSIVE VIA "DBFCDX"
INDEX ON ROOMS_ID + DTOS(CHECK_IN) TAG ROOM_IN
INDEX ON STATUS TAG STATUS
INDEX ON CHECK_IN TAG CHECK_IN
INDEX ON CHECK_OUT TAG CHECK_OUT
CLOSE DATA
return nil
//----------------------------------------------------------------------------//