• Welcome to SQLitening Support Forum.
 

News:

Welcome to the SQLitening support forums!

Main Menu

Is Auto Checkout Guests Candidate For Trigger?

Started by Fredrick Ughimi, September 05, 2019, 03:57:53 PM

Previous topic - Next topic

cj

What values? 
Please supply something with a database and tables.

Fredrick Ughimi

#16
>>Please supply something with a database and tables.

sRoomNo and sRecordNo

>>Please supply something with a database and tables.

#COMPILE EXE
#DIM ALL
#INCLUDE "SQLitening.inc"

FUNCTION PBMAIN () AS LONG

   slOpen ("GuestsProDB.db3","C")

    'Registration
  slExe BUILD$("Create Table If Not Exists tblRegistration(Surname TEXT COLLATE NOCASE, Othernames TEXT COLLATE NOCASE, Address TEXT,", _
  "MobileNo TEXT, CompanyName TEXT, Position TEXT, Nationality TEXT, ArrivalDate TEXT, ArrivalTime TEXT, NoOfNights TEXT, DepartureDate TEXT, DepartureTime TEXT,", _
  "StateArrivingFrom TEXT, StateGoingTo TEXT, Identification TEXT, IDNo TEXT, Sponsor TEXT, PurposeOfVisit TEXT, NoOfGuests TEXT, RoomNo TEXT, RoomRate TEXT,", _
  "RoomType TEXT, BillNo TEXT, StayOver)")

   slExe "Create Index If Not Exists Registrationndx1 ON tblRegistration(BillNo)"

   slExe "Create Index If Not Exists Registrationndx2 ON tblRegistration(Surname)"

   slExe "Create Index If Not Exists Registrationndx3 ON tblRegistration(Othernames)"

   'RegistrationHistory
  slExe BUILD$("Create Table If Not Exists tblRegistrationHistory(Surname TEXT COLLATE NOCASE, Othernames TEXT COLLATE NOCASE, Address TEXT,", _
  "MobileNo TEXT, CompanyName TEXT, Position TEXT, Nationality TEXT, ArrivalDate TEXT, ArrivalTime TEXT, NoOfNights TEXT, DepartureDate TEXT, DepartureTime TEXT,", _
  "StateArrivingFrom TEXT, StateGoingTo TEXT, Identification TEXT, IDNo TEXT, Sponsor TEXT, PurposeOfVisit TEXT, NoOfGuests TEXT, RoomNo TEXT, RoomRate TEXT,", _
  "RoomType TEXT, BillNo TEXT, StayOver)")

   slExe "Create Index If Not Exists RegistrationHistoryndx2 ON tblRegistrationHistory(BillNo)"

   slExe "Create Index If Not Exists RegistrationHistoryndx3 ON tblRegistrationHistory(Surname)"

   slExe "Create Index If Not Exists RegistrationHistoryndx4 ON tblRegistrationHistory(Othernames)"

  'RoomRates
   slExe "Create Table If Not Exists tblRoomRates (RoomNo TEXT, RoomType, CashRate, CashDeposit, CreditRate, CreditDeposit, Status)"

   slExe "Create UNIQUE Index If Not Exists RoomRatesndx1 ON tblRoomRates(RoomNo)"

   'Call AutoCheckOut
   AutoCheckOutGuests

END FUNCTION


FUNCTION AutoCheckOutGuests() AS LONG

    LOCAL Errorcode&
    LOCAL CheckoutAns&
    LOCAL sRoomNo AS STRING
    LOCAL sRecordNo, sStatus AS STRING
    LOCAL x AS LONG
    LOCAL s$
    sStatus = "Available"

     FOR x = -10 TO 100:NEXT
     s$ = "SELECT RowID as RecordNo,RoomNo as rRoomNo, DepartureDate,DepartureTime,"
     s$+= " case"
     s$+= "   when DepartureDate <= date('now') THEN 'greater'"
     s$+= "   when DepartureDate = date('now') THEN 'less'"
     s$+= "   WHEN DepartureTime > time('12') THEN 'Greater Than'"
     's$+= "  else             'equal'"
     s$+= " end as NewColName"
     s$+= " from tblRegistration"

     slExe slBuildInsertOrUpdate("tblRoomRates", sRoomNo & $Nul & "Available", "RoomNo, Status", "RoomNo=" & sRoomNo)
     Errorcode& = slExe("Insert into tblRegistrationHistory Select * From tblRegistration Where RowID = '" + sRecordNo + "'","E")
     IF Errorcode& = 19 THEN
         MSGBOX "Bill No Already Sent And Is Still Existing In The Registeration History", %MB_TASKMODAL OR %MB_ICONINFORMATION, EXE.NAME$
         EXIT FUNCTION
     END IF

     slEXE "Delete From tblRegistration WHERE DepartureDate <= date('now') AND DepartureTime >= time('12')"

     IF slGetChangeCount = 0 THEN

         ? "No Guests is due to leave", %MB_TASKMODAL OR %MB_ICONINFORMATION, EXE.NAME$
         EXIT FUNCTION

     ELSE
         ? "GuestS moved to the History table and deleted from the current guests table", %MB_TASKMODAL OR %MB_ICONINFORMATION, EXE.NAME$
     END IF

END FUNCTION

Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

I think the unique billno should be used instead of recordno.
Everything should be in a transaction.
I would think knowing the roomno or billno would have to be passed to the function.
I don't see any need for the CASE statement.

Fredrick Ughimi

>>I think the unique billno should be used instead of recordno.

Yeah the BillNo is more reliable

>>Everything should be in a transaction.

Yes

>>I would think knowing the roomno or billno would have to be passed to the function.

Like this? Function AutoCheckOutGuests(ByVal roomno As Long, ByVal billno As Long) As Long

>>I don't see any need for the CASE statement.

Serves a good purpose here. Responsible for triggering the statements.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

Yes
Function AutoCheckOutGuests(ByVal roomno As Long, ByVal billno As Long) As Long

BYVAL not required unless the value might be changed and caller needs original number.
If you use all strings then passing strings is fine.

Fredrick Ughimi

>>If you use all strings then passing strings is fine.

The were all defined as string

Function AutoCheckOutGuests(sRoomNo As String, sBillNo As String) As String ?
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

#21
If you have the room number you probably can get the bill number.
If you have the bill number you might not need the room number.

I
LOCAL sRoomNo AS STRING
LOCAL sBillNo AS STRING
LOCAL ecode   AS LONG
ecode = AutoCheckOutGuests(sRoomNo, sBillNo)

Fredrick Ughimi

Getting the sBillNo or sRoomNo is the issue now.

If I was executing the code under MLG Notification or Timer I can get both the sBillNo and sRoomNo values

I need to look at using it under MLG or Listview.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

What is auto checkout?
Doesn't someone have to pay the bill and hand in a room key?

Fredrick Ughimi

>>What is auto checkout?

Good question. A client requested for it.

>>Doesn't someone have to pay the bill and hand in a room key?

>>I have tried talking the client out of it, but he wouldn't bulge. He says making the room automatically available after date and time has expired would make the workers at the front office forcefully make the room available physical. His reason doesn't really sit well with me.

Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

#25
Sounds like they owe another day or need to be evicted.
I think they would automatically be charged another day.
or
I suppose they could have left without checking out.
But if they come back would be a real problem if they still have a key.

Fredrick Ughimi

Hello Cj,

The management of the hotel don't allow guests to owe the hotel except guests that are registered debtors. They have a mechanism is place to get their money from the debtors.

They are trying to prevent guests that are in the habit of delaying their exit when their stay has expired. The feature still doesn't make sense to me.

In the meantime I decided to only display guests that their DepartureDate < Date$, without deleting any records.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Bern Ertl

Quote from: Fredrick Ughimi on September 05, 2019, 03:57:53 PMHello,

I am stump trying to figure out how to automatically 'trigger' this sequence of SQL startements. I wonder if Trigger is the best condidate.
...
But triggers are only triggered when an INSERT, DELETE or UPDATE occurs. I want the statements triggered when this conditions are met:

If (sDepartureDate < Date$) Or (sDepartureDate = Date$ And Time$ > "12") Then
....
End If

Any help would be appreciated.

TRIGGERs are great.  You will likely need 3 triggers to cover all possible data changes that might impact the condition you want monitored:  INSERT and DELETE on tblRegistration and UPDATE on tblRegistration.DepartureDate