hotel season problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
z_cool
Forum Newbie
Posts: 6
Joined: Wed May 24, 2006 12:56 am

hotel season problem

Post by z_cool »

I am trying to do a php script for a hotel.
The hotels have different prices for different seasons. The seasons vary from low season to high season.
The dates for the low season are as follows: 01 May 2006 to 14 Oct 2006.
for the high season are as follows: 15 Oct 2006 to 15 Apr 2007
In the form there will be the following fields:

Date of Arrival
Date of Departure
The accomodation type(e.g studio or apartment)
for both studio and apartment, there are 2 prices,i.e, one for low season and one for high season.

An example is if a client arrives in a low season period and departs in a high season period, the total of his stay will be as follows:

((Number of days he stayed in low season*price of accomodation)+(number of days he stayed in high season*price of accomodation))

If the clients comes in the same season and leaves in the same season, his total of stay will be calculated as below:
(Number of days stayed*price of accomodation)

It is to be noted that the accomodations and the seasons dates will be retrieved from the database.
The problem is that i can't find a solution to the problem of calculating the total price for the stay of the client wheh he arrives in a season and leaves in another season.
mcccy005
Forum Contributor
Posts: 123
Joined: Sun May 28, 2006 7:08 pm

Post by mcccy005 »

Not going to write the code for you (got my own to write); but if you do know a bit of php you should be able to follow this dodgy psudocode...

DO something along the lines of this psudocode:
if date_of_arrival is NOT in the same season as date of departure (eg. date_of_arrival is less than or prior to end of current season AND date_of_departure is AFTER season of date_of_arrival)
THEN
num_days of season1=last date of season1-date_of_arrival (ie. calculate the difference between the two dates) and do your little formula (ie. num_days*price of season1)
then do date of departure minus beginning date of season2 and do the number of days*price of season2.


obviously you will have to check that the difference is from one season to the next as opposed to starting in one season; staying through the next; and then departing in the 3rd season.
Post Reply