Ejemplo n.º 1
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_coupon_discount($data, $coupon = '')
 {
     if (empty($coupon)) {
         return 0;
     }
     $posts = get_posts(array('post_type' => 'coupon', 'posts_per_page' => 1, 'meta_key' => 'gdlr-coupon-code', 'meta_value' => $coupon));
     $post_option = json_decode(gdlr_decode_preventslashes(get_post_meta($posts[0]->ID, 'post-option', true)), true);
     // expire date
     if (!empty($post_option['coupon-expiry']) && strtotime(date("Y-m-d")) > strtotime($post_option['coupon-expiry'])) {
         return 0;
     }
     // available num
     $coupon_num = get_post_meta($posts[0]->ID, 'gdlr-coupon-num', true);
     $coupon_num = empty($coupon_num) ? 0 : intval($coupon_num);
     if ($post_option['coupon-amount'] != -1 && $coupon_num >= $post_option['coupon-amount']) {
         return 0;
     }
     update_post_meta($posts[0]->ID, 'gdlr-coupon-num', $coupon_num + 1);
     // specify room
     if (!empty($post_option['specify-room'])) {
         $room_specify = explode(',', $post_option['specify-room']);
         foreach ($data['gdlr-room-id'] as $key => $room_id) {
             if (!in_array($room_id, $room_specify)) {
                 unset($data['gdlr-room-id'][$key]);
             }
         }
     }
     if (empty($data['gdlr-room-id'])) {
         return 0;
     }
     // number of
     if ($post_option['coupon-discount-type'] == 'amount') {
         return $post_option['coupon-discount-amount'];
     } else {
         // percent
         $total_price = 0;
         for ($i = 0; $i < sizeOf($data['gdlr-room-id']); $i++) {
             $room_option = json_decode(gdlr_decode_preventslashes(get_post_meta($data['gdlr-room-id'][$i], 'post-option', true)), true);
             $room_option['data'] = array('check-in' => $data['gdlr-check-in'], 'check-out' => $data['gdlr-check-out']);
             $price = gdlrs_get_booking_price($room_option);
             $total_price += $price['total'];
         }
         return $total_price * floatval($post_option['coupon-discount-amount']) / 100;
     }
 }