Example #1
0
															<?php 
                    }
                    ?>
														</select>
													<?php 
                }
                ?>
													<br/>
													<?php 
                if ($item->is_per_day == 1 || $item->is_per_day == 2) {
                    ?>
														<?php 
                    echo $item->is_per_day == 1 ? JText::_('LNG_NUMBER_OF_DAYS', true) : JText::_('LNG_NUMBER_OF_NIGHTS', true);
                    ?>
														<?php 
                    $nrDays = JHotelUtil::getNumberOfDays($this->item->reservationData->userData->start_date, $this->item->reservationData->userData->end_date);
                    ?>
														<select id="days-<?php 
                    echo $item->id;
                    ?>
" name="extra-option-days-<?php 
                    echo $item->id;
                    ?>
"  <?php 
                    echo $item->map_per_length_of_stay == 1 ? 'onfocus="this.oldvalue=this.value;this.blur();" onchange="this.value=this.oldvalue;"' : '';
                    ?>
 >
															<?php 
                    for ($i = 1; $i < 21; $i++) {
                        ?>
																<option value="<?php 
    public function getReservationDetailsExcursions($resevation, $excursions, $currency)
    {
        $result = array();
        $nr_days_except_offers = 0;
        $index = 0;
        foreach ($excursions as $excursion) {
            $index++;
            $showExcursionDescription = true;
            $excursionInfo = new stdClass();
            $totalExcursionPrice = 0;
            $dayCounter = 0;
            $showPricePerDay = true;
            if (isset($excursion->price_type_day) && $excursion->price_type_day == 1) {
                $showPricePerDay = false;
            }
            ob_start();
            foreach ($excursion->daily as $day) {
                $price_day = $day['price_final'];
                if (isset($excursion->customPrices) && isset($excursion->customPrices[$day["date"]])) {
                    $price_day = $excursion->customPrices[$day["date"]];
                }
                $price_day *= $excursion->nrItemsBooked;
                $info_discount = '';
                $dayCounter++;
                foreach ($day['discounts'] as $d) {
                    if (strlen($info_discount) > 0) {
                        $info_discount .= '<BR>';
                    }
                    $info_discount .= $d->discount_name . ' ' . JHotelUtil::fmt(-1 * $d->discount_value) . '' . ($d->percent == 1 ? "%" : " " . $currency->symbol);
                }
                if (strlen($info_discount) > 0) {
                    $info_discount = "<div class='discount_info'>" . $info_discount . '</div>';
                }
                ?>
					
					<tr class='rsv_dtls_excursion_info'>
						<?php 
                if ($showExcursionDescription) {
                    ?>
							<td colspan=5 align="left" valign="top" style="border-top:solid 1px grey;padding: 3px 9px;"	rowspan='<?php 
                    echo !$showPricePerDay ? 1 : count($excursion->daily);
                    ?>
'>
								
								<?php 
                    if (count($excursions) > 1) {
                        ?>
									<strong>#<?php 
                        echo $index;
                        ?>
</strong>
								<?php 
                    }
                    ?>
								<?php 
                    echo '<strong>' . $excursion->excursion_name . '</strong>' . ' (' . JText::_('LNG_FOR', true) . ' ' . $excursion->nrItemsBooked . ')';
                    ?>
							</td>
							<?php 
                    $showExcursionDescription = false;
                }
                ?>
						
					<?php 
                $totalExcursionPrice += $price_day;
                ?>
					
					<td align="left" valign="top" style="border-top:solid  1px grey;padding: 3px 9px;" nowrap="nowrap">
							
							<?php 
                if (isset($excursion->price_type_day) && $excursion->price_type_day == 1) {
                    $nrDays = JHotelUtil::getNumberOfDays($resevation->start_date, $resevation->end_date);
                    //TODO - get nr Days
                    echo $nrDays . " " . strtolower(JText::_("LNG_NIGHTS"));
                } else {
                    echo JHotelUtil::getDateGeneralFormat($day['date']);
                }
                echo $info_discount;
                ?>
						</td>
						<td align="right" valign="top" style="border-top:solid  1px grey;padding: 3px 9px;">
							&nbsp;
							<?php 
                echo JHotelUtil::fmt($showPricePerDay ? $price_day : $totalExcursionPrice, 2);
                ?>
						</td>
						
						
					</tr>
					
					<?php 
                if (isset($excursion->price_type_day) && $excursion->price_type_day == 1) {
                    break;
                }
            }
            ?>
				
					<?php 
            $excursionInfo->name = $excursion->excursion_name;
            $excursionInfo->excursionDescription = ob_get_contents();
            ob_end_clean();
            $excursionInfo->excursionPrice = $totalExcursionPrice;
            $result[] = $excursionInfo;
        }
        return $result;
    }
 public static function getHotelOffers($hotelId, $startDate, $endDate, $offersIds = array(), $adults = 2, $children = 0, $discountCode = null, $checkAvailability = true, $confirmationId = null)
 {
     $adults = $adults == 0 ? 2 : $adults;
     $db = JFactory::getDBO();
     $offerFilter = "";
     if (count($offersIds) > 0) {
         $offerFilter = " and ";
         foreach ($offersIds as $id) {
             $values = explode("|", $id);
             $offerFilter .= "(hor.offer_id =" . $values[0] . ' and ';
             $offerFilter .= "hor.room_id =" . $values[1] . ' )';
         }
     }
     //dmp($offerFilter);
     $isHotelAvailable = true;
     if (!self::isHotelAvailable($hotelId, $startDate, $endDate) && $checkAvailability) {
         $isHotelAvailable = false;
     }
     //dmp($startDate);
     //dmp($endDate);
     //dmp($isHotelAvailable);
     $availabilityFilter = "and\to.is_available = 1 and r.is_available = 1 ";
     if (!$checkAvailability) {
         $availabilityFilter = "";
     }
     $languageTag = JRequest::getVar('_lang');
     //get hotel rooms
     $query = "select r.*,o.*,hlct.content as offer_content,hlit.content as offer_other_info,hlt.content as offer_description,hlost.content as offer_short_description,ot.*, ot.id as rate_id, rr.availability as availability, rr.id as room_rate_id,GROUP_CONCAT(hov.voucher) as vouchers\r\n\t\t\t\tfrom #__hotelreservation_rooms r\r\n\t\t\t\tinner join #__hotelreservation_rooms_rates rr \t\t\ton r.room_id = rr.room_id\r\n\t\t\t\tinner join #__hotelreservation_offers_rooms \t\t\thor \tON hor.room_id\t \t= r.room_id\r\n\t\t\t\tinner join #__hotelreservation_offers\t\t \t\t\to \t\tON hor.offer_id \t= o.offer_id\r\n\t\t\t\tinner join #__hotelreservation_offers_rates \t\t\tot \t\tON ot.offer_id\t= hor.offer_id and ot.room_id = hor.room_id\r\n\t\t\t\tleft join #__hotelreservation_offers_vouchers hov on hov.offerId = o.offer_id\r\n\t\t\t\tleft join\r\n\t\t\t\t\t(select * from \r\n\t\t\t\t\t #__hotelreservation_language_translations \r\n\t\t\t\t\t where type = " . OFFER_TRANSLATION . "\r\n\t\t\t\t\t and language_tag = '{$languageTag}'\r\n\t\t\t\t\t) as hlt on hlt.object_id = o.offer_id\r\n\t\t\t\tleft join\r\n\t\t\t\t\t(select * from \r\n\t\t\t\t\t #__hotelreservation_language_translations \r\n\t\t\t\t\t where type = " . OFFER_SHORT_TRANSLATION . "\r\n\t\t\t\t\t and language_tag = '{$languageTag}'\r\n\t\t\t\t\t) as hlost on hlost.object_id = o.offer_id\r\n\t\t\t\tleft join\r\n\t\t\t\t\t(select * from \r\n\t\t\t\t\t #__hotelreservation_language_translations \r\n\t\t\t\t\t where type = " . OFFER_CONTENT_TRANSLATION . "\r\n\t\t\t\t\t and language_tag = '{$languageTag}'\r\n\t\t\t\t\t) as hlct on hlct.object_id = o.offer_id\r\n\t\t\t\tleft join\r\n\t\t\t\t\t(select * from \r\n\t\t\t\t\t #__hotelreservation_language_translations \r\n\t\t\t\t\t where type = " . OFFER_INFO_TRANSLATION . "\r\n\t\t\t\t\t and language_tag = '{$languageTag}'\r\n\t\t\t\t\t) as hlit on hlit.object_id = o.offer_id\r\n\t\t\t\t\t\r\n\t\t\t\t\t\r\n\t\t\t\twhere o.hotel_id= {$hotelId} {$offerFilter}\r\n\t\t\t\t{$availabilityFilter}\r\n\t\t\t\tand\tIF(\r\n\t\t\t\to.offer_datasf <> '0000-00-00'\r\n\t\t\t\tAND\r\n\t\t\t\to.offer_dataef <> '0000-00-00',\r\n\t\t\t\tDATE(now()) BETWEEN o.offer_datasf  AND o.offer_dataef,\r\n\t\t\t\tIF(\r\n\t\t\t\to.offer_datasf <> '0000-00-00',\r\n\t\t\t\tDATE(now()) >= o.offer_datasf,\r\n\t\t\t\tDATE(now()) <=o.offer_dataef\r\n\t\t\t\t)\r\n\t\t\t\t)\r\n\t\t\t\tgroup by hor.offer_room_id";
     //echo($query);
     $db->setQuery($query);
     $offers = $db->loadObjectList();
     $number_days = (strtotime($endDate) - strtotime($startDate)) / (60 * 60 * 24);
     //dmp($offers);
     //get hotel rates
     if (count($offers)) {
         foreach ($offers as $offer) {
             //get offer custom rate settings
             $query = "select * from #__hotelreservation_offers_rate_prices r\r\n\t\t\t\t\twhere rate_id={$offer->rate_id} and '{$startDate}'<= date and date<='{$endDate}'";
             $db->setQuery($query);
             $offerRateDetails = $db->loadObjectList();
             $offer->offerRateDetails = $offerRateDetails;
             //dmp($offerRateDetails);
             //get room custom rate settings
             $query = "select * from #__hotelreservation_rooms_rate_prices r\r\n\t\t\t\t\twhere rate_id={$offer->room_rate_id} and '{$startDate}'<= date and date<='{$endDate}'";
             //dmp($query);
             $db->setQuery($query);
             $roomRateDetails = $db->loadObjectList();
             $offer->roomRateDetails = $roomRateDetails;
             //dmp($offer->roomRateDetails);
             //calculate available number of room
             $offer->nrRoomsAvailable = $offer->availability;
             $offer->is_disabled = false;
             $offer->lock_for_departure = false;
             //dmp($offer->vouchers);
             //set voucher as array
             if (isset($offer->vouchers)) {
                 $offer->vouchers = explode(',', $offer->vouchers);
             }
             //dmp($offer->vouchers);
             //check if offer can start on arrival date
             $d = strtotime($startDate);
             $nr_d = 'offer_day_' . date("N", $d);
             if ($offer->{$nr_d} == 0) {
                 $offer->is_disabled = true;
                 //dmp("disable");
             }
             $daily = array();
             $totalPrice = 0;
             $offer_max_nights = $offer->offer_max_nights;
             if (!$isHotelAvailable) {
                 $offer->is_disabled = true;
                 //dmp("disable");
             }
             //check if arrival date is disabled on arrival date
             if (count($roomRateDetails)) {
                 foreach ($roomRateDetails as $roomRateDetail) {
                     if ($roomRateDetail->date == $startDate && $roomRateDetail->lock_arrival == 1) {
                         $offer->is_disabled = true;
                         //dmp("disable");
                     }
                     if ($roomRateDetail->date == $endDate) {
                         if ($roomRateDetail->lock_departure == 1) {
                             // 								dmp("disable");
                             $offer->is_disabled = true;
                             $offer->lock_for_departure = true;
                         }
                     }
                 }
             }
             $dayCounter = 0;
             for ($d = strtotime($startDate); $d < strtotime($endDate);) {
                 $dayString = date('Y-m-d', $d);
                 $dayCounter++;
                 //dmp($dayString);
                 //set default price from rate
                 $weekDay = date("N", $d);
                 $string_price = "price_" . $weekDay;
                 $dayPrice = $offer->{$string_price};
                 $childPrice = $offer->child_price;
                 $extraPersonPrice = $offer->extra_pers_price;
                 //dmp($extraPersonPrice);
                 //check if there is a custom price set
                 if (count($offerRateDetails)) {
                     foreach ($offerRateDetails as $offerRateDetail) {
                         if ($offerRateDetail->date == $dayString) {
                             $dayPrice = $offerRateDetail->price;
                             $extraPersonPrice = $offerRateDetail->extra_pers_price;
                             $childPrice = $offerRateDetail->child_price;
                             //	dmp($dayString . ": ". $dayPrice);
                         }
                     }
                 }
                 //dmp($extraPersonPrice);
                 //dmp($dayPrice);
                 //check if we have an extra night
                 $isExtraNight = false;
                 if ($offer_max_nights <= 0) {
                     $dayPrice = $offer->extra_night_price;
                     $isExtraNight = true;
                     //dmp("extra price: ".$offer->extra_night_price);
                 }
                 if ($offer->price_type == 1) {
                     $totalAdults = $adults <= $offer->base_adults ? $adults : $offer->base_adults;
                     $dayPrice = $dayPrice * $totalAdults + $childPrice * $children;
                 }
                 //add extra person cost - if it is the case
                 if ($adults > $offer->base_adults) {
                     $dayPrice += ($adults - $offer->base_adults) * $extraPersonPrice;
                 }
                 $nrDays = JHotelUtil::getNumberOfDays($startDate, $endDate);
                 //dmp($nrDays);
                 if ($offer->offer_min_nights > $nrDays) {
                     $offer->is_disabled = true;
                 }
                 //for single use
                 //if the price is per person apply single supplement , if is for room apply discount
                 if ($adults == 1 && $children == 0) {
                     if (!$isExtraNight) {
                         if ($offer->price_type == 1) {
                             $dayPrice = $dayPrice + $offer->single_balancing;
                             //dmp("add balancing: ".$offer->single_balancing." -> ".$dayPrice);
                         } else {
                             $dayPrice = $dayPrice - $offer->single_balancing;
                         }
                     } else {
                         if ($offer->price_type_day == 1) {
                             if ($offer->price_type == 1) {
                                 $dayPrice = $dayPrice + $offer->single_balancing / $offer->offer_min_nights;
                             } else {
                                 $dayPrice = $dayPrice - $offer->single_balancing / $offer->offer_min_nights;
                             }
                         } else {
                             if ($offer->price_type_day == 0) {
                                 if ($offer->price_type == 1) {
                                     $dayPrice = $dayPrice + $offer->single_balancing;
                                 } else {
                                     $dayPrice = $dayPrice - $offer->single_balancing;
                                 }
                             }
                         }
                     }
                 }
                 //check if offer is available on stay period
                 if (!(strtotime($offer->offer_datas) <= $d && $d <= strtotime($offer->offer_datae))) {
                     $offer->is_disabled = true;
                 }
                 //get the minimum availability in the selected period
                 if (count($roomRateDetails)) {
                     foreach ($roomRateDetails as $roomRateDetail) {
                         //get room availability - if rate details are set default settings are ignored
                         if ($roomRateDetail->date == $dayString) {
                             $offer->nrRoomsAvailable = $roomRateDetail->availability;
                         }
                     }
                 }
                 if ($offer_max_nights > 0) {
                     if (count($offerRateDetails)) {
                         foreach ($offerRateDetails as $offerRateDetail) {
                             //set single use price
                             if ($offerRateDetail->date == $dayString && $offer->price_type == 1 && $adults == 1 && $children == 0) {
                                 $dayPrice = $offerRateDetail->single_use_price;
                             }
                         }
                     }
                 }
                 //apply current discounts
                 $query = "  SELECT\r\n\t\t\t\t\t\t\t\tdiscount_id,\r\n\t\t\t\t\t\t\t\tdiscount_name,\r\n\t\t\t\t\t\t\t\tdiscount_datas,\r\n\t\t\t\t\t\t\t\tdiscount_datae,\r\n\t\t\t\t\t\t\t\tif(price_type = 1 , discount_value * {$adults}, discount_value) as discount_value,\r\n\t\t\t\t\t\t\t\tpercent,\r\n\t\t\t\t\t\t\t\tminimum_number_days,\r\n\t\t\t\t\t\t\t\tminimum_number_persons,\r\n\t\t\t\t\t\t\t\tmaximum_number_days,\r\n\t\t\t\t\t\t\t\tcheck_full_code,\r\n\t\t\t\t\t\t\t\tprice_type,\r\n\t\t\t\t\t\t\t\tcode\r\n\t\t\t\t\t\t\t\tFROM #__hotelreservation_discounts\r\n\t\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\tis_available = 1\r\n\t\t\t\t\t\t\t\tAND\r\n\t\t\t\t\t\t\t\tFIND_IN_SET( " . $offer->room_id . ", discount_room_ids  )\r\n\t\t\t\t\t\t\t\tAND\r\n\t\t\t\t\t\t\t\tFIND_IN_SET( " . $offer->offer_id . ", offer_ids  )\r\n\t\t\t\t\t\t\t\tAND\r\n\t\t\t\t\t\t\t\t'" . date('Y-m-d', $d) . "' BETWEEN discount_datas AND discount_datae\r\n\t\t\t\t\t\t\t\tAND\r\n\t\t\t\t\t\t\t\tIF( minimum_number_days > 0, minimum_number_days <= {$number_days}, 1 )\r\n\t\t\t\t\t\t\t\tAND\r\n\t\t\t\t\t\t\t\tIF( minimum_number_persons > 0, minimum_number_persons <= {$adults}, 1 )\r\n\t\t\t\t\t\t\t\tORDER BY discount_datas\r\n\t\t\t\t\t\t\t\t";
                 //dmp($query);
                 $db->setQuery($query);
                 $discounts = $db->loadObjectList();
                 $offer->hasDiscounts = count($discounts) > 0;
                 //dmp($discounts);
                 $selectedDiscounts = array();
                 $discountValue = 0;
                 $discountPercent = 0;
                 if (count($discounts) > 0) {
                     foreach ($discounts as $discount) {
                         if ($dayCounter <= $discount->maximum_number_days) {
                             $match = false;
                             if (isset($discount->code) && isset($discountCode)) {
                                 if ($discount->check_full_code == 1) {
                                     $match = strcasecmp($discountCode, $discount->code) == 0;
                                 } else {
                                     $match = stripos($discountCode, $discount->code) === 0;
                                 }
                             }
                             if ($match || !isset($discount->code) || strlen($discount->code) == 0) {
                                 $selectedDiscounts[] = $discount;
                                 if ($discount->percent) {
                                     $discountPercent += $discount->discount_value;
                                 } else {
                                     $discountValue += $discount->discount_value;
                                 }
                             }
                         }
                     }
                 }
                 if ($offer->nrRoomsAvailable == 0) {
                     $offer->is_disabled = true;
                 }
                 //apply percent
                 $dayPrice = round($dayPrice - $dayPrice * ($discountPercent / 100), 2);
                 //apply value
                 $dayPrice = $dayPrice - $discountValue;
                 $day = array('date' => $dayString, 'price' => $dayPrice, 'price_final' => $dayPrice, 'display_price_final' => $dayPrice, 'discounts' => $selectedDiscounts, 'nrRoomsAvailable' => $offer->nrRoomsAvailable, 'isExtraNight' => $isExtraNight);
                 $daily[$dayString] = $day;
                 $totalPrice += $dayPrice;
                 $offer_max_nights--;
                 $d = strtotime(date('Y-m-d', $d) . ' + 1 day ');
             }
             //dmp($offer->offer_name);
             //dmp($offer->nrRoomsAvailable);
             //$this->itemRoomsCapacity[$offer->room_id ] = array($offer->nrRoomsAvailable, 1);
             $number_days = (strtotime($endDate) - strtotime($startDate)) / (60 * 60 * 24);
             $offer->daily = $daily;
             //average price per offer
             $offer->offer_average_price = JHotelUtil::fmt($totalPrice / $number_days, 2);
             $offer->pers_total_price = JHotelUtil::fmt($totalPrice / ($adults + $children), 2);
             if ($offer->price_type_day == 1) {
                 $offer->offer_average_price = $daily[$startDate]["price"];
                 $offer->pers_total_price = $daily[$startDate]["price"] / ($adults + $children);
                 foreach ($daily as $day) {
                     if ($day["isExtraNight"]) {
                         $offer->pers_total_price += $day["price"] / ($adults + $children);
                         $offer->offer_average_price += $day["price"];
                     }
                 }
             }
             //load offers pictures
             $query = "  SELECT *\r\n\t\t\t\t\t\t\tFROM #__hotelreservation_offers_pictures\r\n\t\t\t\t\t\t\tWHERE offer_id = " . $offer->offer_id . " AND offer_picture_enable = 1\r\n\t\t\t\t\t\t\tORDER BY offer_picture_id";
             $db->setQuery($query);
             $offer->pictures = $db->loadObjectList();
             $offer->adults = $adults;
             $offer->children = $children;
         }
     }
     self::setOfferDisplayPrice($offers);
     self::checkRoomAvailability($offers, array(), $hotelId, $startDate, $endDate, $confirmationId);
     return $offers;
 }
Example #4
0
 function displayTableRow($room, $row)
 {
     //dmp("R: ". $row);
     $startDate = $this->state->get('filter.start_date');
     $endDate = $this->state->get('filter.end_date');
     echo "<td class='td_color_fundal_1'></td>";
     for ($d = strtotime($startDate); $d <= strtotime($endDate);) {
         $dayString = date('d-m-Y', $d);
         $class = "";
         if ($d == strtotime(date('d-m-Y') . ' -1 day')) {
             $class = 'td_color_fundal_crt_day_1';
         } else {
             $class = 'td_color_fundal_1';
         }
         $class2 = "";
         if ($d == strtotime(date('d-m-Y'))) {
             $class2 = 'td_color_fundal_crt_day_2';
         } else {
             $class2 = 'td_color_fundal_2';
         }
         $showBooking = false;
         if (isset($this->availabilityReport[$room->room_id])) {
             foreach ($this->availabilityReport[$room->room_id][$row] as $booking) {
                 if (strtotime($booking->start_date) < strtotime($startDate)) {
                     $booking->start_date = $startDate;
                 }
                 if (strtotime($booking->start_date) == $d) {
                     $stayPeriod = JHotelUtil::getNumberOfDays($booking->start_date, $booking->end_date);
                     $colSpan = $stayPeriod * 2;
                     echo "<td class='td_color_fundal_1' colspan='{$colSpan}'>";
                     echo "\t<div class='reseravation_box reserved_details_" . strtolower(str_replace(' ', '_', $booking->status_reservation_name)) . "'>" . "<a class='client' href='#dialog_" . $booking->confirmation_id . "' name='modal'>" . $booking->last_name . ' ' . $booking->first_name . "</a>" . "</div>" . "<div id='dialog_" . $booking->confirmation_id . "' class='window'>" . "<div class='info'>" . "<SPAN class='title_ID'>" . JText::_('LNG_RESERVATION', true) . ' : ' . JHotelUtil::getStringIDConfirmation($booking->confirmation_id) . "</SPAN>" . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' value='Close it' class='close'/>" . $booking->confirmation_details . "</div>" . "</div>";
                     echo "</td>";
                     $showBooking = true;
                     $d = strtotime(date('d-m-Y', $d) . ' + ' . $stayPeriod . ' day ');
                     break;
                 }
             }
             //echo "<td  class='td_color_fundal_1'></td>";
         }
         if (!$showBooking) {
             echo "<td  class='{$class2}'></td>";
             if ($d != strtotime($endDate)) {
                 echo "<td class='{$class}'></td>";
             }
         } else {
             continue;
         }
         $d = strtotime(date('d-m-Y', $d) . ' + 1 day ');
     }
 }