[BUG] Complicated bug while updating max adults and children for default period of rooms

Discuss everything related to PHP Hotel Site. All versions. Any questions related to the PHP Hotel Site developing or using should be posted to this forum.

Moderators: ne_moj, zewa, vadimako, ne_moj, zewa, vadimako

PrinceOfAbyss
Junior
Junior
Posts: 17
Joined: Apr 1st, '18, 23:17

[BUG] Complicated bug while updating max adults and children for default period of rooms

Postby PrinceOfAbyss » Apr 11th, '18, 16:53

Steps to replicate this complicated bug:

1. Create a test room, setting Max Adults to 12 and Max Children to 8.
2. The above action automatically creates a new row in <PREFIX>rooms table with the room itself, and a new row in <PREFIX>rooms_prices with the default price for that new room.
3. So, if you confirm the actual tables in phpMyAdmin <PREFIX>rooms and <PREFIX>rooms_prices, values should be max_adults 12 and max_children 8 for table <PREFIX>rooms and adults 12 and children 8 for table <PREFIX>rooms_prices.
4. Now go to Room edit page form and (not the Prices edit page, the Room edit page), and change Max adults to 5 and Max children to 3.
5. Click Update button.
6. Now, if you click the Prices link for that room to view/edit the periods and their prices, you will see that Standard price is supposedly for 5 adults and 3 children.
7. But, if you confirm the tables in phpMyAdmin, you will find out that in table <PREFIX>rooms correctly changed to 5 and 3, BUT in table <PREFIX>rooms_prices they stayed 12 and 8.
8. The above situation leads to the following discrepancy.

In ADMIN side: For the default price, Max adults and children are retrieved from the room's table, but stored wrongly in the room's prices table.
In PUBLIC side: For the default price, Max adults and children are retrieved from the room's prices table where they are stored with their initial (before the edit) values.

PrinceOfAbyss
Junior
Junior
Posts: 17
Joined: Apr 1st, '18, 23:17

Re: [BUG] Complicated bug while updating max adults and children for default period of rooms

Postby PrinceOfAbyss » Apr 16th, '18, 12:55

Any progress with this?

PrinceOfAbyss
Junior
Junior
Posts: 17
Joined: Apr 1st, '18, 23:17

Re: [BUG] Complicated bug while updating max adults and children for default period of rooms

Postby PrinceOfAbyss » Apr 16th, '18, 16:49

Look at what I'm talking about in the following two images... The first is the rooms table, and the seconds is the room_prices.

db_rooms.png
db_rooms.png (27.47 KiB) Viewed 399 times

db_room_prices.png
db_room_prices.png (46.9 KiB) Viewed 399 times

PrinceOfAbyss
Junior
Junior
Posts: 17
Joined: Apr 1st, '18, 23:17

Re: [BUG] Complicated bug while updating max adults and children for default period of rooms

Postby PrinceOfAbyss » Apr 16th, '18, 16:57

Now look at what each view of the following displays in regard to the max adults and max children...

First, in the Admin side, the Edit Room page:
edit_room.png
edit_room.png (13.11 KiB) Viewed 398 times

As you can see, it uses the values from the rooms table.

Second, in the Admin side again, the Edit Prices page:
admin.png
admin.png (43.56 KiB) Viewed 398 times

As you can see, it uses the values from the rooms table for the default period, and the values from the rooms_prices table for the rest of the periods.

Third, in the Public side, the Prices tab in the Room's view page:
public.png
public.png (34.38 KiB) Viewed 398 times

As you can see, it uses the values from the rooms_prices table, for all periods, including the default period, which there is no way to edit...

PrinceOfAbyss
Junior
Junior
Posts: 17
Joined: Apr 1st, '18, 23:17

Re: [BUG] Complicated bug while updating max adults and children for default period of rooms

Postby PrinceOfAbyss » Apr 16th, '18, 19:25

I corrected this myself.

In include/classes/Rooms.class.php:

Line ~1617 [in public function BeforeUpdateRecord()]
after

Code: Select all

      $this->defaultPrice = isset($record_info['default_price']) ? $record_info['default_price'] : '';
      $this->extraBedCharge = isset($record_info['extra_bed_charge']) ? $record_info['extra_bed_charge'] : '';

add

Code: Select all

      $this->maxAdults = isset($record_info['max_adults']) ? $record_info['max_adults'] : '';
      $this->maxChildren = isset($record_info['max_children']) ? $record_info['max_children'] : '';


Then, line ~1624 [in public function AfterUpdateRecord()]
after

Code: Select all

      $default_price = MicroGrid::GetParameter('default_price', false);
        $extra_bed_charge = MicroGrid::GetParameter('extra_bed_charge', false);

add

Code: Select all

      $max_adults = MicroGrid::GetParameter('max_adults', false);
      $max_children = MicroGrid::GetParameter('max_children', false);


Then, line ~1636 [again in public function AfterUpdateRecord()]
before

Code: Select all

      if($default_price != $this->defaultPrice){
         $sql = 'UPDATE '.TABLE_ROOMS_PRICES.' SET mon='.$default_price.', tue='.$default_price.', wed='.$default_price.', thu='.$default_price.', fri='.$default_price.', sat='.$default_price.', sun='.$default_price;
         $sql .= ' WHERE room_id = '.(int)$this->curRecordId.' AND is_default = 1';
         database_void_query($sql);   
      }      

add

Code: Select all

      if($max_adults != $this->maxAdults){
         $sql = 'UPDATE '.TABLE_ROOMS_PRICES.' SET adults='.$max_adults;
         $sql .= ' WHERE room_id = '.(int)$this->curRecordId.' AND is_default = 1';
         database_void_query($sql);
      }

      if($max_children != $this->maxChildren){
         $sql = 'UPDATE '.TABLE_ROOMS_PRICES.' SET children='.$max_children;
         $sql .= ' WHERE room_id = '.(int)$this->curRecordId.' AND is_default = 1';
         database_void_query($sql);
      }

administrator
Site Admin
Site Admin
Posts: 5992
Joined: Jan 7th, '09, 23:18
Contact:

Re: [BUG] Complicated bug while updating max adults and children for default period of rooms

Postby administrator » Apr 18th, '18, 09:01

We'll check this, thank you.

Update:
----------
Your fix was accepted and added to the next version.
Please contact us via PM to get awards bonuses to your account on apphp:
https://www.apphp.com/index.php?page=reward-program


Return to “ApPHP HotelSite / uHotelBooking Talk {developers/users}”