function gdlrs_get_booking_total_price($data, $coupon = '')
 {
     global $hostel_option;
     $total_price = 0;
     // group the customer by room
     $customer_rooms = array();
     for ($i = 0; $i < intval($data['gdlr-room-number']); $i++) {
         $customer_rooms[$data['gdlr-room-id'][$i]] = empty($customer_rooms[$data['gdlr-room-id'][$i]]) ? 1 : $customer_rooms[$data['gdlr-room-id'][$i]] + 1;
     }
     foreach ($customer_rooms as $room_id => $guest_num) {
         $post_option = json_decode(gdlr_decode_preventslashes(get_post_meta($room_id, 'post-option', true)), true);
         $post_option['data'] = array('check-in' => $data['gdlr-check-in'], 'check-out' => $data['gdlr-check-out']);
         $price = gdlrs_get_booking_price($post_option);
         if (empty($post_option['room-type']) || $post_option['room-type'] == 'dorm') {
             $price['total'] = $price['total'] * $guest_num;
         }
         $total_price += $price['total'];
     }
     // service
     if (!empty($data['service'])) {
         $services_price = gdlrs_calculate_service_price($data);
         $total_price += $services_price['total'];
     }
     // coupon discount
     $discount_price = gdlr_get_coupon_discount($data, $coupon);
     $total_price -= $discount_price;
     if (!empty($hostel_option['booking-vat-amount'])) {
         $vat_amount = $total_price * floatval($hostel_option['booking-vat-amount']) / 100;
         $total_price += $vat_amount;
     }
     $pay_amount = $total_price;
     if (!empty($hostel_option['booking-deposit-amount']) && $data['pay_deposit'] == 'true') {
         $pay_amount = $total_price * floatval($hostel_option['booking-deposit-amount']) / 100;
     }
     return array('total_price' => $total_price, 'pay_amount' => $pay_amount);
 }
Ejemplo n.º 2
0
 function gdlrs_get_summary_form($data, $with_form = true, $coupon = '')
 {
     global $hostel_option;
     $total_price = 0;
     $ret = '<div class="gdlr-price-summary-wrapper" >';
     // display branches if exists
     if (!empty($data['gdlr-hotel-branches'])) {
         $term = get_term_by('id', $data['gdlr-hotel-branches'], 'hostel_room_category');
         $ret .= '<div class="gdlr-price-summary-hotel-branches gdlr-title-font">';
         $ret .= $term->name;
         $ret .= '</div>';
     } else {
         $ret .= '<div class="gdlr-price-summary-head">' . __('Price Breakdown', 'gdlr-hotel') . '</div>';
     }
     // group the customer by room
     $customer_rooms = array();
     for ($i = 0; $i < intval($data['gdlr-room-number']); $i++) {
         $customer_rooms[$data['gdlr-room-id'][$i]] = empty($customer_rooms[$data['gdlr-room-id'][$i]]) ? 1 : $customer_rooms[$data['gdlr-room-id'][$i]] + 1;
     }
     foreach ($customer_rooms as $room_id => $guest_num) {
         $post_option = json_decode(gdlr_decode_preventslashes(get_post_meta($room_id, 'post-option', true)), true);
         $post_option['data'] = array('check-in' => $data['gdlr-check-in'], 'check-out' => $data['gdlr-check-out']);
         $price = gdlrs_get_booking_price($post_option);
         if (empty($post_option['room-type']) || $post_option['room-type'] == 'dorm') {
             $price['total'] = $price['total'] * $guest_num;
         }
         $ret .= '<div class="gdlr-price-room-summary">';
         $ret .= '<div class="gdlr-price-room-summary-title">';
         $ret .= __('Room', 'gdlr-hotel') . ' : ' . get_the_title($room_id);
         $ret .= '<span class="gdlr-price-room-summary-price" href="#" >' . gdlr_hostel_money_format($price['total']) . '</span>';
         $ret .= '</div>';
         $ret .= '<div class="gdlr-price-room-summary-info gdlr-title-font" >';
         $ret .= '<span>' . __('Guest', 'gdlr-hotel') . ' : ' . $guest_num . '</span>';
         $ret .= '</div>';
         $ret .= '</div>';
         $total_price += $price['total'];
     }
     // service
     if (!empty($data['service'])) {
         $services_price = gdlrs_calculate_service_price($data);
         $ret .= '<div class="gdlr-service-price-summary">';
         $ret .= '<div class="gdlr-service-price-summary-head" >' . __('Additional Services', 'gdlr-hotel') . '</div>';
         foreach ($services_price as $key => $service_price) {
             if ($key == 'total') {
                 continue;
             }
             $ret .= '<div class="gdlr-service-price-summary-item">';
             $ret .= '<span class="gdlr-head">' . $service_price['title'] . '</span>';
             $ret .= '<span class="gdlr-tail">' . gdlr_hostel_money_format($service_price['price']) . '</span>';
             $ret .= '<div class="clear"></div>';
             $ret .= '</div>';
         }
         $ret .= '</div>';
         $total_price += $services_price['total'];
     }
     // vat
     if (!empty($hostel_option['booking-vat-amount'])) {
         $ret .= '<div class="gdlr-price-summary-vat" >';
         $ret .= '<div class="gdlr-price-summary-vat-total" >';
         $ret .= '<span class="gdlr-head">' . __('Total', 'gdlr-hotel') . '</span>';
         $ret .= '<span class="gdlr-tail">' . gdlr_hostel_money_format($total_price) . '</span>';
         $ret .= '<div class="clear"></div>';
         $ret .= '</div>';
         // vat-total
         if (!empty($coupon)) {
             $discount = gdlr_get_coupon_discount($data, $coupon);
             $total_price -= $discount;
             $ret .= '<div class="gdlr-price-summary-vat-discount" >';
             $ret .= '<span class="gdlr-head">' . __('Coupon Discount', 'gdlr-hotel') . '</span>';
             $ret .= '<span class="gdlr-tail">' . gdlr_hostel_money_format($discount) . '</span>';
             $ret .= '<div class="clear"></div>';
             $ret .= '</div>';
         }
         $vat_amount = $total_price * floatval($hostel_option['booking-vat-amount']) / 100;
         $total_price += $vat_amount;
         $ret .= '<div class="gdlr-price-summary-vat-amount" >';
         $ret .= '<span class="gdlr-head">' . __('Vat', 'gdlr-hotel') . ' ' . $hostel_option['booking-vat-amount'] . '%</span>';
         $ret .= '<span class="gdlr-tail">' . gdlr_hostel_money_format($vat_amount) . '</span>';
         $ret .= '<div class="clear"></div>';
         $ret .= '</div>';
         // vat-amount
         $ret .= '</div>';
     }
     // deposit
     if ($with_form && !empty($hostel_option['booking-deposit-amount'])) {
         // grand total
         $ret .= '<div class="gdlr-price-summary-grand-total gdlr-active" >';
         $ret .= '<span class="gdlr-head">' . __('Grand Total', 'gdlr-hotel') . '</span>';
         $ret .= '<span class="gdlr-tail">' . gdlr_hostel_money_format($total_price) . '</span>';
         $ret .= '</div>';
         $deposit_text = $hostel_option['booking-deposit-amount'] . '% ' . __('Deposit', 'gdlr-hotel');
         $deposit_amount = $total_price * floatval($hostel_option['booking-deposit-amount']) / 100;
         $ret .= '<div class="gdlr-price-deposit-wrapper">';
         $ret .= '<div class="gdlr-price-deposit-input" >';
         $ret .= '<span class="gdlr-active" ><label class="gdlr-radio-input"><input type="radio" name="pay_deposit" value="false" checked ></label>' . __('Pay Full Amount', 'gdlr-hotel') . '</span>';
         $ret .= '<span><label class="gdlr-radio-input"><input type="radio" name="pay_deposit" value="true" ></label>' . __('Pay', 'gdlr-hotel') . ' ' . $deposit_text . '</span>';
         $ret .= '</div>';
         $ret .= '<div class="gdlr-price-deposit-inner-wrapper">';
         $ret .= '<div class="gdlr-price-deposit-title">' . $deposit_text . '</div>';
         $ret .= '<div class="gdlr-price-deposit-caption">' . __('*Pay the rest on arrival', 'gdlr-hotel') . '</div>';
         $ret .= '<div class="gdlr-price-deposit-amount">' . gdlr_hostel_money_format($deposit_amount) . '</div>';
         $ret .= '</div>';
         $ret .= '</div>';
         $ret .= '<a id="gdlr-edit-booking-button" class="gdlr-edit-booking-button gdlr-button with-border" href="#">' . __('Edit Booking', 'gdlr-hotel') . '</a>';
     } else {
         $ret .= '<div class="gdlr-price-summary-grand-total-wrapper-2" >';
         $ret .= '<div class="gdlr-price-summary-grand-total ';
         $ret .= empty($data['pay_deposit']) || $data['pay_deposit'] == 'false' ? 'gdlr-active' : '';
         $ret .= '" >';
         $ret .= '<span class="gdlr-head">' . __('Grand Total', 'gdlr-hotel') . '</span>';
         $ret .= '<span class="gdlr-tail">' . gdlr_hostel_money_format($total_price) . '</span>';
         $ret .= '</div>';
         if (!empty($data['pay_deposit']) && $data['pay_deposit'] == 'true') {
             $deposit_text = $hostel_option['booking-deposit-amount'] . '% ' . __('Deposit', 'gdlr-hotel');
             $deposit_amount = $total_price * floatval($hostel_option['booking-deposit-amount']) / 100;
             $ret .= '<div class="gdlr-price-deposit-wrapper">';
             $ret .= '<div class="gdlr-price-deposit-inner-wrapper">';
             $ret .= '<div class="gdlr-price-deposit-title">' . $deposit_text . '</div>';
             $ret .= '<div class="gdlr-price-deposit-caption">' . __('*Pay the rest on arrival', 'gdlr-hotel') . '</div>';
             $ret .= '<div class="gdlr-price-deposit-amount">' . gdlr_hostel_money_format($deposit_amount) . '</div>';
             $ret .= '</div>';
             $ret .= '</div>';
             $ret .= '<div class="gdlr-pay-on-arrival" >';
             $ret .= '<span class="gdlr-head">' . __('Pay on arrival', 'gdlr-hotel') . '</span>';
             $ret .= '<span class="gdlr-tail">' . gdlr_hostel_money_format($total_price - $deposit_amount) . '</span>';
             $ret .= '</div>';
         }
         $ret .= '</div>';
     }
     $ret .= '</div>';
     // gdlr-price-summary-wrapper
     return $ret;
 }
 function gdlr_get_booking_total_price($data, $coupon = '')
 {
     global $hotel_option;
     $total_price = 0;
     for ($i = 0; $i < intval($data['gdlr-room-number']); $i++) {
         $post_option = json_decode(gdlr_decode_preventslashes(get_post_meta($data['gdlr-room-id'][$i], 'post-option', true)), true);
         $post_option['data'] = array('check-in' => $data['gdlr-check-in'], 'check-out' => $data['gdlr-check-out'], 'adult' => $data['gdlr-adult-number'][$i], 'children' => $data['gdlr-children-number'][$i]);
         $price = gdlr_get_booking_price($post_option);
         $total_price += $price['total'];
     }
     // service
     if (!empty($data['service'])) {
         $services_price = gdlr_calculate_service_price($data);
         $total_price += $services_price['total'];
     }
     // coupon discount
     $discount_price = gdlr_get_coupon_discount($data, $coupon);
     $total_price -= $discount_price;
     if (!empty($hotel_option['booking-vat-amount'])) {
         $vat_amount = $total_price * floatval($hotel_option['booking-vat-amount']) / 100;
         $total_price += $vat_amount;
     }
     $pay_amount = $total_price;
     if (!empty($hotel_option['booking-deposit-amount']) && $data['pay_deposit'] == 'true') {
         $pay_amount = $total_price * floatval($hotel_option['booking-deposit-amount']) / 100;
     }
     return array('total_price' => $total_price, 'pay_amount' => $pay_amount);
 }