コード例 #1
0
ファイル: car_rentals.php プロジェクト: alikris/OTA
 function update_car_rental_booking($booking_id, $first_name, $last_name, $email, $phone, $address, $town, $zip, $country, $special_requirements, $date_from, $date_to, $car_rental_id, $user_id, $total_price, $drop_off_location_id)
 {
     global $wpdb;
     // We are actually (in terms of db data) looking for date 1 day before the to date.
     // E.g. when you look to book a room from 19.12. to 20.12 you will be staying 1 night, not 2.
     // The same goes for cars.
     $date_to = date('Y-m-d', strtotime($date_to . ' -1 day'));
     // delete previous days from table
     $sql = "DELETE FROM " . BOOKYOURTRAVEL_CAR_RENTAL_BOOKING_DAYS_TABLE . "\r\n\t\t\t\tWHERE car_rental_booking_id = %d ";
     $wpdb->query($wpdb->prepare($sql, $booking_id));
     $sql = "UPDATE " . BOOKYOURTRAVEL_CAR_RENTAL_BOOKINGS_TABLE . "\r\n\t\t\t\tSET first_name = %s,\r\n\t\t\t\tlast_name = %s,\r\n\t\t\t\temail = %s, \r\n\t\t\t\tphone = %s, \r\n\t\t\t\taddress = %s, \r\n\t\t\t\ttown = %s, \r\n\t\t\t\tzip = %s, \r\n\t\t\t\tcountry = %s, \r\n\t\t\t\tspecial_requirements = %s,\r\n\t\t\t\tcar_rental_id = %d, \r\n\t\t\t\tuser_id = %d, \r\n\t\t\t\ttotal_price = %f, \r\n\t\t\t\tdrop_off = %d\r\n\t\t\t\tWHERE Id=%d";
     $wpdb->query($wpdb->prepare($sql, $first_name, $last_name, $email, $phone, $address, $town, $zip, $country, $special_requirements, $car_rental_id, $user_id, $total_price, $drop_off_location_id, $booking_id));
     $dates = BYT_Theme_Utils::get_dates_from_range($date_from, $date_to);
     foreach ($dates as $date) {
         $sql = "INSERT INTO " . BOOKYOURTRAVEL_CAR_RENTAL_BOOKING_DAYS_TABLE . "\r\n\t\t\t\t\t(car_rental_booking_id, booking_date)\r\n\t\t\t\t\tVALUES\r\n\t\t\t\t\t(%d, %s);";
         $wpdb->query($wpdb->prepare($sql, $booking_id, $date));
     }
     return $booking_id;
 }
コード例 #2
0
ファイル: accommodations.php プロジェクト: alikris/OTA
 function calculate_total_price($accommodation_id, $room_type_id, $date_from, $date_to, $room_count, $adults, $children)
 {
     global $wpdb;
     $accommodation_id = BYT_Theme_Utils::get_default_language_post_id($accommodation_id, 'accommodation');
     if ($room_type_id > 0) {
         $room_type_id = BYT_Theme_Utils::get_default_language_post_id($room_type_id, 'room_type');
     }
     $accommodation_is_price_per_person = get_post_meta($accommodation_id, 'accommodation_is_price_per_person', true);
     $accommodation_count_children_stay_free = get_post_meta($accommodation_id, 'accommodation_count_children_stay_free', true);
     $accommodation_count_children_stay_free = isset($accommodation_count_children_stay_free) ? intval($accommodation_count_children_stay_free) : 0;
     $children = $children - $accommodation_count_children_stay_free;
     $children = $children > 0 ? $children : 0;
     // we are actually (in terms of db data) looking for date 1 day before the to date
     // e.g. when you look to book a room from 19.12. to 20.12 you will be staying 1 night, not 2
     $date_to = date('Y-m-d', strtotime($date_to . ' -1 day'));
     $dates = BYT_Theme_Utils::get_dates_from_range($date_from, $date_to);
     $total_price = 0;
     foreach ($dates as $date) {
         $date = date('Y-m-d', strtotime($date));
         $price_per_day = $this->get_accommodation_price($date, $accommodation_id, $room_type_id, false);
         $child_price_per_day = $this->get_accommodation_price($date, $accommodation_id, $room_type_id, true);
         if ($accommodation_is_price_per_person) {
             $total_price += ($adults * $price_per_day + $children * $child_price_per_day) * $room_count;
         } else {
             $total_price += $price_per_day * $room_count;
         }
     }
     $total_price = $total_price * $room_count;
     return $total_price;
 }