Advertisement
Guest User

vergina

a guest
Feb 7th, 2018
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 193.92 KB | None | 0 0
  1. <?php
  2.  
  3. /***
  4. * Class Reservation
  5. * --------------
  6. * Description : encapsulates Booking properties
  7. * Updated : 03.07.2014
  8. * Written by : ApPHP
  9. *
  10. * PUBLIC: STATIC: PRIVATE:
  11. * ----------- ----------- -----------
  12. * __construct GetVatPercent
  13. * __destruct GenerateBookingNumber
  14. * AddToReservation GetVatPercentDecimalPoints
  15. * RemoveReservation CheckHotelIdExists
  16. * ShowReservationInfo GetReservationHotelId
  17. * ShowCheckoutInfo
  18. * EmptyCart
  19. * GetCartItems
  20. * GetAdultsInCart
  21. * GetChildrenInCart
  22. * IsCartEmpty
  23. * PlaceBooking
  24. * DoReservation
  25. * SendOrderEmail
  26. * SendCancelOrderEmail
  27. * DrawReservation
  28. * LoadDiscountInfo
  29. * ApplyDiscountCoupon
  30. * RemoveDiscountCoupon
  31. *
  32. **/
  33.  
  34. class Reservation {
  35.  
  36. public $arrReservation;
  37. public $error;
  38. public $message;
  39.  
  40. private $fieldDateFormat;
  41. private $cartItems;
  42. private $roomsCount;
  43. private $cartTotalSum;
  44. private $firstNightSum;
  45. private $currentCustomerID;
  46. private $selectedUser;
  47. private $vatPercent;
  48. private $discountPercent;
  49. private $discountCampaignID;
  50. private $discountCoupon;
  51. private $currencyFormat;
  52. private $lang;
  53. private $paypal_form_type;
  54. private $paypal_form_fields;
  55. private $paypal_form_fields_count;
  56. private $first_night_possible;
  57. private $firstNightCalculationType = 'real';
  58. private $bookingInitialFee = '0';
  59. private $guestTax = '0';
  60. private $vatIncludedInPrice = 'no';
  61. private $maximumAllowedReservations = '10';
  62. private $countMealForChildren = true;
  63.  
  64.  
  65. //==========================================================================
  66. // Class Constructor
  67. //==========================================================================
  68. function __construct()
  69. {
  70. global $objSettings;
  71. global $objLogin;
  72.  
  73. if(!$objLogin->IsLoggedIn()){
  74. $this->currentCustomerID = (int)Session::Get('current_customer_id');
  75. $this->selectedUser = 'customer';
  76. }else if($objLogin->IsLoggedInAsCustomer()){
  77. $this->currentCustomerID = $objLogin->GetLoggedID();
  78. $this->selectedUser = 'customer';
  79. }else{
  80. if(Session::IsExists('sel_current_customer_id') && (int)Session::Get('sel_current_customer_id') != 0){
  81. $this->currentCustomerID = (int)Session::Get('sel_current_customer_id');
  82. $this->selectedUser = 'customer';
  83. }else{
  84. $this->currentCustomerID = $objLogin->GetLoggedID();
  85. $this->selectedUser = 'admin';
  86. }
  87. }
  88.  
  89. // prepare Booking settings
  90. $this->firstNightCalculationType = ModulesSettings::Get('booking', 'first_night_calculating_type');
  91. $this->bookingInitialFee = ModulesSettings::Get('booking', 'booking_initial_fee');
  92. $this->vatIncludedInPrice = ModulesSettings::Get('booking', 'vat_included_in_price');
  93. $this->maximumAllowedReservations = ModulesSettings::Get('booking', 'maximum_allowed_reservations');
  94. $this->guestTax = ModulesSettings::Get('booking', 'special_tax');
  95.  
  96. // prepare currency info
  97. if(Application::Get('currency_code') == ''){
  98. $this->currencyCode = Currencies::GetDefaultCurrency();
  99. $this->currencyRate = '1';
  100. }else{
  101. //$default_currency_info = Currencies::GetDefaultCurrencyInfo();
  102. $this->currencyCode = Application::Get('currency_code');
  103. $this->currencyRate = Application::Get('currency_rate');
  104. }
  105.  
  106. // prepare VAT percent
  107. $this->vatPercent = $this->GetVatPercent();
  108.  
  109. // prepare datetime format
  110. if($objSettings->GetParameter('date_format') == 'mm/dd/yyyy'){
  111. $this->fieldDateFormat = 'M d, Y';
  112. }else{
  113. $this->fieldDateFormat = 'd M, Y';
  114. }
  115.  
  116. $this->lang = Application::Get('lang');
  117. $this->arrReservation = &$_SESSION[INSTALLATION_KEY.'reservation'];
  118. $this->arrReservationInfo = &$_SESSION[INSTALLATION_KEY.'reservation_info'];
  119. $this->cartItems = 0;
  120. $this->roomsCount = 0;
  121. $this->cartTotalSum = 0;
  122. $this->firstNightSum = 0;
  123. $this->first_night_possible = false;
  124. $this->paypal_form_type = 'multiple'; // single | multiple
  125. $this->paypal_form_fields = '';
  126. $this->currencyFormat = get_currency_format();
  127.  
  128. // prepare discount info
  129. $this->LoadDiscountInfo();
  130.  
  131. if(count($this->arrReservation) > 0){
  132. $this->paypal_form_fields_count = 0;
  133. foreach($this->arrReservation as $key => $val){
  134. $room_price_w_meal_extrabeds = ($val['price'] + $val['meal_plan_price'] + $val['extra_beds_charge']);
  135. $this->cartItems += 1;
  136. $this->roomsCount += $val['rooms'];
  137. $this->cartTotalSum += ($room_price_w_meal_extrabeds * $this->currencyRate);
  138. if($this->firstNightCalculationType == 'average'){
  139. $this->firstNightSum += ($room_price_w_meal_extrabeds / $val['nights']);
  140. }else{
  141. $this->firstNightSum += Rooms::GetPriceForDate($key, $val['from_date']);
  142. }
  143. if($val['nights'] > 1) $this->first_night_possible = true;
  144.  
  145. if($this->paypal_form_type == 'multiple' && $val['rooms'] > 0){
  146. $this->paypal_form_fields_count++;
  147. $this->paypal_form_fields .= draw_hidden_field('item_name_'.$this->paypal_form_fields_count, _ROOM_TYPE.': '.$val['room_type'], false);
  148. $this->paypal_form_fields .= draw_hidden_field('quantity_'.$this->paypal_form_fields_count, $val['rooms'], false);
  149. $this->paypal_form_fields .= draw_hidden_field('amount_'.$this->paypal_form_fields_count, number_format((($val['price'] * $this->currencyRate) / $val['rooms']), '2', '.', ','), false);
  150.  
  151. if(!empty($val['meal_plan_price'])){
  152. $this->paypal_form_fields_count++;
  153. $this->paypal_form_fields .= draw_hidden_field('item_name_'.$this->paypal_form_fields_count, _MEAL_PLANS.': '.$val['meal_plan_name'], false);
  154. $this->paypal_form_fields .= draw_hidden_field('quantity_'.$this->paypal_form_fields_count, $val['rooms'], false);
  155. $this->paypal_form_fields .= draw_hidden_field('amount_'.$this->paypal_form_fields_count, number_format($val['meal_plan_price'], '2', '.', ','), false);
  156. }
  157. }
  158. }
  159. }
  160. $this->cartTotalSum = number_format($this->cartTotalSum, 2, '.', '');
  161.  
  162. $this->message = '';
  163. $this->error = '';
  164.  
  165. //echo $this->firstNightSum;
  166. //echo '<pre>';
  167. //print_r($this->arrReservation);
  168. //echo '</pre>';
  169. }
  170.  
  171. //==========================================================================
  172. // Class Destructor
  173. //==========================================================================
  174. function __destruct()
  175. {
  176. // echo 'this object has been destroyed';
  177. }
  178.  
  179. /**
  180. * Add room to reservation
  181. * @param $room_id
  182. * @param $from_date
  183. * @param $to_date
  184. * @param $nights
  185. * @param $rooms
  186. * @param $price
  187. * @param $adults
  188. * @param $children
  189. * @param $meal_plan_id
  190. * @param $hotel_id
  191. * @param $extra_beds
  192. * @param $extra_bed_charge
  193. */
  194. public function AddToReservation($room_id, $from_date, $to_date, $nights, $rooms, $price, $adults, $children, $meal_plan_id, $hotel_id, $extra_beds, $extra_bed_charge)
  195. {
  196. if(!empty($room_id)){
  197. $meal_plan_info = MealPlans::GetPlanInfo($meal_plan_id);
  198. // specify meal multiplier
  199. if($this->countMealForChildren == true){
  200. $meal_multiplier = $nights * $rooms * ($adults + $children);
  201. }else{
  202. $meal_multiplier = $nights * $rooms * $adults;
  203. }
  204.  
  205. // check "allow_separate_gateways" settings
  206. if(ModulesSettings::Get('booking', 'allow_separate_gateways') == 'yes' && count($this->arrReservation) > 0){
  207. if(!$this->CheckHotelIdExists($hotel_id)){
  208. $this->error = draw_important_message(_ALERT_SAME_HOTEL_ROOMS, false);
  209. return false;
  210. }
  211. }
  212.  
  213. if(isset($this->arrReservation[$room_id])){
  214. // add new info for this room
  215. $this->arrReservation[$room_id]['from_date'] = $from_date;
  216. $this->arrReservation[$room_id]['to_date'] = $to_date;
  217. $this->arrReservation[$room_id]['nights'] = $nights;
  218. $this->arrReservation[$room_id]['rooms'] = $rooms;
  219. $this->arrReservation[$room_id]['price'] = $price;
  220. $this->arrReservation[$room_id]['adults'] = $adults;
  221. $this->arrReservation[$room_id]['children'] = $children;
  222. $this->arrReservation[$room_id]['hotel_id'] = (int)$hotel_id;
  223. $this->arrReservation[$room_id]['meal_plan_id'] = (int)$meal_plan_id;
  224. $this->arrReservation[$room_id]['meal_plan_name'] = isset($meal_plan_info['name']) ? $meal_plan_info['name'] : '';
  225. $this->arrReservation[$room_id]['meal_plan_price'] = isset($meal_plan_info['price']) ? number_format($meal_plan_info['price'] * $meal_multiplier, 2, '.', '') : 0;
  226. $this->arrReservation[$room_id]['room_type'] = Rooms::GetRoomInfo($room_id, 'room_type');
  227. $this->arrReservation[$room_id]['extra_beds'] = $extra_beds;
  228. $this->arrReservation[$room_id]['extra_beds_charge'] = number_format($extra_bed_charge * $nights * $rooms, 2, '.', '');
  229. }else{
  230. // just add new room
  231. $this->arrReservation[$room_id] = array(
  232. 'from_date' => $from_date,
  233. 'to_date' => $to_date,
  234. 'nights' => $nights,
  235. 'rooms' => $rooms,
  236. 'price' => $price,
  237. 'adults' => $adults,
  238. 'children' => $children,
  239. 'hotel_id' => (int)$hotel_id,
  240. 'meal_plan_id' => (int)$meal_plan_id,
  241. 'meal_plan_name' => isset($meal_plan_info['name']) ? $meal_plan_info['name'] : '',
  242. 'meal_plan_price' => isset($meal_plan_info['price']) ? number_format($meal_plan_info['price'] * $meal_multiplier, 2, '.', '') : 0,
  243. 'room_type' => Rooms::GetRoomInfo($room_id, 'room_type'),
  244. 'extra_beds' => $extra_beds,
  245. 'extra_beds_charge' => number_format($extra_bed_charge * $nights * $rooms, 2, '.', '')
  246. );
  247. }
  248. $this->error = draw_success_message(_ROOM_WAS_ADDED, false);
  249. }else{
  250. $this->error = draw_important_message(_WRONG_PARAMETER_PASSED, false);
  251. }
  252. }
  253.  
  254. /**
  255. * Remove room from the reservation cart
  256. * @param $room_id
  257. */
  258. public function RemoveReservation($room_id)
  259. {
  260. if((int)$room_id > 0){
  261. if(isset($this->arrReservation[$room_id]) && $this->arrReservation[$room_id] > 0){
  262. unset($this->arrReservation[$room_id]);
  263. $this->error = draw_message(_ROOM_WAS_REMOVED, false);
  264. }else{
  265. $this->error = draw_important_message(_ROOM_NOT_FOUND, false);
  266. }
  267. }else{
  268. $this->error = draw_important_message(_ROOM_NOT_FOUND, false);
  269. }
  270. }
  271.  
  272. /**
  273. * Show Reservation Cart on the screen
  274. */
  275. public function ShowReservationInfo()
  276. {
  277. global $objLogin;
  278.  
  279. $class_left = Application::Get('defined_left');
  280. $class_right = Application::Get('defined_right');
  281. $allow_children = ModulesSettings::Get('rooms', 'allow_children');
  282. $allow_extra_beds = ModulesSettings::Get('rooms', 'allow_extra_beds');
  283. $meal_plans_count = MealPlans::MealPlansCount();
  284. $total_adults = 0;
  285. $total_children = 0;
  286.  
  287. if(count($this->arrReservation) > 0)
  288. {
  289. echo '<table class="reservation_cart" border="0" width="100%" align="center" cellspacing="0" cellpadding="5"><thead>';
  290. echo '<tr class="header">
  291. <th class="'.$class_left.'" width="30px">&nbsp;</th>
  292. <th align="'.$class_left.'">'._ROOM_TYPE.'</th>
  293. <th align="center" width="60px">'._FROM.'</th>
  294. <th align="center" width="60px">'._TO.'</th>
  295. <th width="40px" align="center">&nbsp;'._NIGHTS.'&nbsp;</th>
  296. <th width="40px" align="center">&nbsp;'._ROOMS.'&nbsp;</th>
  297. <th width="70px" colspan="3" align="center">'._OCCUPANCY.'</th>
  298. '.(($meal_plans_count) ? '<th width="60px" align="center">'._MEAL_PLANS.'</th>' : '<th style="padding:0px;">&nbsp;</th>').'
  299. <th width="65px" class="'.$class_right.'">'._PRICE.'</th>
  300. </tr>';
  301.  
  302. echo '<tr style="font-size:10px;background-color:transparent;">
  303. <th colspan="6"></th>
  304. <th align="center">'._ADULT.'</th>
  305. '.(($allow_children == 'yes') ? '<th align="center">'._CHILD.'</th>' : '<th></th>').'
  306. '.(($allow_extra_beds == 'yes') ? '<th align="center">'._EXTRA_BED.'</th>' : '<th></th>').'
  307. <th colspan="2"></th>
  308. </tr>';
  309.  
  310. echo '</thead>
  311. <tr><td colspan="11" nowrap height="5px"></td></tr>';
  312.  
  313. $order_price = 0;
  314. $objRoom = new Rooms();
  315. foreach($this->arrReservation as $key => $val)
  316. {
  317. $sql = 'SELECT
  318. '.TABLE_ROOMS.'.id,
  319. '.TABLE_ROOMS.'.room_type,
  320. '.TABLE_ROOMS.'.room_icon_thumb,
  321. '.TABLE_ROOMS.'.max_adults,
  322. '.TABLE_ROOMS.'.max_children,
  323. '.TABLE_ROOMS.'.default_price as price,
  324. '.TABLE_ROOMS_DESCRIPTION.'.room_type as loc_room_type,
  325. '.TABLE_ROOMS_DESCRIPTION.'.room_short_description as loc_room_short_description,
  326. '.TABLE_HOTELS_DESCRIPTION.'.name as hotel_name
  327. FROM '.TABLE_ROOMS.'
  328. INNER JOIN '.TABLE_ROOMS_DESCRIPTION.' ON '.TABLE_ROOMS.'.id = '.TABLE_ROOMS_DESCRIPTION.'.room_id
  329. INNER JOIN '.TABLE_HOTELS_DESCRIPTION.' ON '.TABLE_ROOMS.'.hotel_id = '.TABLE_HOTELS_DESCRIPTION.'.hotel_id
  330. WHERE
  331. '.TABLE_ROOMS.'.id = '.$key.' AND
  332. '.TABLE_ROOMS_DESCRIPTION.'.language_id = \''.$this->lang.'\' AND
  333. '.TABLE_HOTELS_DESCRIPTION.'.language_id = \''.$this->lang.'\' ';
  334.  
  335. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  336. if($result[1] > 0){
  337. $room_icon_thumb = ($result[0]['room_icon_thumb'] != '') ? $result[0]['room_icon_thumb'] : 'no_image.png';
  338. $room_price_w_meal_extrabeds = ($val['price'] + $val['meal_plan_price'] + $val['extra_beds_charge']);
  339.  
  340. echo '<tr>
  341. <td align="center"><a href="index.php?page=booking&act=remove&rid='.$key.'"><img src="images/remove.gif" width="16" height="16" border="0" title="'._REMOVE_ROOM_FROM_CART.'" alt="remove" /></a></td>
  342. <td>
  343. <b>'.prepare_link('rooms', 'room_id', $result[0]['id'], $result[0]['loc_room_type'], $result[0]['loc_room_type'], '', _CLICK_TO_VIEW).'</b><br />
  344. '.$result[0]['hotel_name'].'
  345. </td>
  346. <td align="center">'.format_date($val['from_date'], $this->fieldDateFormat, '', true).'</td>
  347. <td align="center">'.format_date($val['to_date'], $this->fieldDateFormat, '', true).'</td>
  348. <td align="center">'.$val['nights'].'</td>
  349. <td align="center">'.$val['rooms'].'</td>
  350. <td align="center">'.$val['adults'].'</td>
  351. '.(($allow_children == 'yes') ? '<td align="center">'.$val['children'].'</td>' : '<td></td>').'
  352. '.(($allow_extra_beds == 'yes') ? '<td align="center">'.$val['extra_beds'].'</td>' : '<td></td>').'
  353. '.(($meal_plans_count) ? '<td align="center" style="cursor:help;" title="'.(($val['nights'] > 1) ? _RATE_PER_NIGHT_AVG : _RATE_PER_NIGHT).'">'.$val['meal_plan_name'].'</td>' : '<td></td>').'
  354. <td align="'.$class_right.'">'.Currencies::PriceFormat($room_price_w_meal_extrabeds * $this->currencyRate, '', '', $this->currencyFormat).'&nbsp;<a class="price_link" href="javascript:void(0);" onclick="javascript:appToggleElement(\'row_prices_'.$key.'\')" title="'._CLICK_TO_SEE_PRICES.'">(+)</a></td>
  355. </tr>
  356. <tr><td colspan="11" nowrap height="1px"></td></tr>
  357. <tr><td colspan="11" align="'.$class_left.'">
  358. <span id="row_prices_'.$key.'" style="margin:5px 10px;display:none;">
  359. <table width="100%">
  360. <tr>
  361. <td width="90px"><img src="images/rooms_icons/'.$room_icon_thumb.'" alt="icon" width="80px" height="65px" /></td>
  362. <td>
  363. '._ROOM_PRICE.': '.Currencies::PriceFormat(($val['price'] * $this->currencyRate), '', '', $this->currencyFormat).'<br>
  364. '._MEAL_PLANS.': '.Currencies::PriceFormat(($val['meal_plan_price'] * $this->currencyRate), '', '', $this->currencyFormat).'<br>
  365. '._EXTRA_BEDS.': '.Currencies::PriceFormat(($val['extra_beds_charge'] * $this->currencyRate), '', '', $this->currencyFormat).'<br>
  366. '._RATE_PER_NIGHT.': '.Currencies::PriceFormat(($room_price_w_meal_extrabeds * $this->currencyRate) / $val['nights'], '', '', $this->currencyFormat).'<br>
  367. </td>
  368. </tr>
  369. <tr><td colspan="2">'.Rooms::GetRoomPricesTable($key).'</td></tr>
  370. </table>
  371. </span>
  372. </td>
  373. </tr>';
  374. $order_price += ($room_price_w_meal_extrabeds * $this->currencyRate);
  375. $total_adults += $val['adults'];
  376. $total_children += ($allow_children == 'yes') ? (int)$val['children'] : 0;
  377. }
  378. }
  379.  
  380. // draw sub-total row
  381. echo '<tr>
  382. <td colspan="7"></td>
  383. <td class="td '.$class_left.'" colspan="3"><b>'._SUBTOTAL.': </b></td>
  384. <td class="td '.$class_right.'" align="'.$class_right.'"><b>'.Currencies::PriceFormat($order_price, '', '', $this->currencyFormat).'</b></td>
  385. </tr>';
  386.  
  387. echo '<tr><td colspan="11" nowrap="nowrap" height="15px"></td></tr>';
  388.  
  389. // calculate discount
  390. $discount_value = ($order_price * ($this->discountPercent / 100));
  391. $order_price -= $discount_value;
  392.  
  393. // calculate percent
  394. $vat_cost = (($order_price + $this->bookingInitialFee + ($this->guestTax * ($total_adults + $total_children))) * ($this->vatPercent / 100));
  395. $cart_total = ($order_price + $this->bookingInitialFee + ($this->guestTax * ($total_adults + $total_children))) + $vat_cost;
  396.  
  397. if($this->discountCampaignID != '' || $this->discountCoupon != ''){
  398. echo '<tr>
  399. <td colspan="7"></td>
  400. <td class="td '.$class_left.'" colspan="3"><b><span style="color:#a60000">'._DISCOUNT.': ('.Currencies::PriceFormat($this->discountPercent, '%', 'after', $this->currencyFormat).')</span></b></td>
  401. <td class="td '.$class_right.'" align="'.$class_right.'"><b><span style="color:#a60000">- '.Currencies::PriceFormat($discount_value, '', '', $this->currencyFormat).'</span></b></td>
  402. </tr>';
  403. }
  404. if(!empty($this->bookingInitialFee)){
  405. echo '<tr>
  406. <td colspan="7"></td>
  407. <td class="td '.$class_left.'" colspan="3"><b>'._INITIAL_FEE.': </b></td>
  408. <td class="td '.$class_right.'" align="'.$class_right.'"><b>'.Currencies::PriceFormat($this->bookingInitialFee, '', '', $this->currencyFormat).'</b></td>
  409. </tr>';
  410. }
  411. if(!empty($this->guestTax)){
  412. echo '<tr>
  413. <td colspan="7"></td>
  414. <td class="td '.$class_left.'" colspan="3"><b>'._GUEST_TAX.': </b></td>
  415. <td class="td '.$class_right.'" align="'.$class_right.'"><b>'.Currencies::PriceFormat($this->guestTax * ($total_adults + $total_children), '', '', $this->currencyFormat).'</b></td>
  416. </tr>';
  417. }
  418. if($this->vatIncludedInPrice == 'no'){
  419. echo '<tr>
  420. <td colspan="7"></td>
  421. <td class="td '.$class_left.'" colspan="3"><b>'._VAT.': ('.Currencies::PriceFormat($this->vatPercent, '%', 'after', $this->currencyFormat, $this->GetVatPercentDecimalPoints($this->vatPercent)).')</b></td>
  422. <td class="td '.$class_right.'" align="'.$class_right.'"><b>'.Currencies::PriceFormat($vat_cost, '', '', $this->currencyFormat).'</b></td>
  423. </tr>';
  424. }
  425. echo '<tr><td colspan="11" nowrap height="5px"></td></tr>
  426. <tr class="footer">
  427. <td colspan="7"></td>
  428. <td class="td '.$class_left.'" colspan="3"><b>'._TOTAL.':</b></td>
  429. <td class="td '.$class_right.'" align="'.$class_right.'"><b>'.Currencies::PriceFormat($cart_total, '', '', $this->currencyFormat).'</b></td>
  430. </tr>
  431. <tr><td colspan="11" nowrap height="15px"></td></tr>
  432. <tr>
  433. <td colspan="7"></td>
  434. <td colspan="3"></td>
  435. <td align="'.$class_right.'">
  436. <input type="button" class="form_button" onclick="javascript:appGoTo(\'page=booking_details\')" value="'._BOOK.'" />
  437. </td>
  438. </tr>
  439. </table>';
  440. }else{
  441. draw_message(_RESERVATION_CART_IS_EMPTY_ALERT, true, true);
  442. }
  443. }
  444.  
  445. /**
  446. * Show checkout info
  447. */
  448. public function ShowCheckoutInfo()
  449. {
  450. global $objLogin;
  451.  
  452. $class_left = Application::Get('defined_left');
  453. $class_right = Application::Get('defined_right');
  454.  
  455. $default_payment_system = ModulesSettings::Get('booking', 'default_payment_system');
  456. $pre_payment_type = ModulesSettings::Get('booking', 'pre_payment_type');
  457. $pre_payment_type_post = isset($_POST['pre_payment_type']) ? prepare_input($_POST['pre_payment_type']) : $pre_payment_type;
  458. $pre_payment_value = ModulesSettings::Get('booking', 'pre_payment_value');
  459. $payment_type_poa = ModulesSettings::Get('booking', 'payment_type_poa');
  460. $payment_type_online = ModulesSettings::Get('booking', 'payment_type_online');
  461. $payment_type_bank_transfer = ModulesSettings::Get('booking', 'payment_type_bank_transfer');
  462. $payment_type_paypal = ModulesSettings::Get('booking', 'payment_type_paypal');
  463. $payment_type_2co = ModulesSettings::Get('booking', 'payment_type_2co');
  464. $payment_type_authorize = ModulesSettings::Get('booking', 'payment_type_authorize');
  465. $payment_type = isset($_POST['payment_type']) ? prepare_input($_POST['payment_type']) : $default_payment_system;
  466. $submition_type = isset($_POST['submition_type']) ? prepare_input($_POST['submition_type']) : '';
  467.  
  468. $payment_type_poa = ($payment_type_poa == 'Frontend & Backend' || ($objLogin->IsLoggedInAsAdmin() && $payment_type_poa == 'Backend Only') || (!$objLogin->IsLoggedInAsAdmin() && $payment_type_poa == 'Frontend Only')) ? 'yes' : 'no';
  469. $payment_type_online = ($payment_type_online == 'Frontend & Backend' || ($objLogin->IsLoggedInAsAdmin() && $payment_type_online == 'Backend Only') || (!$objLogin->IsLoggedInAsAdmin() && $payment_type_online == 'Frontend Only')) ? 'yes' : 'no';
  470. $payment_type_bank_transfer = ($payment_type_bank_transfer == 'Frontend & Backend' || ($objLogin->IsLoggedInAsAdmin() && $payment_type_bank_transfer == 'Backend Only') || (!$objLogin->IsLoggedInAsAdmin() && $payment_type_bank_transfer == 'Frontend Only')) ? 'yes' : 'no';
  471. $payment_type_paypal = ($payment_type_paypal == 'Frontend & Backend' || ($objLogin->IsLoggedInAsAdmin() && $payment_type_paypal == 'Backend Only') || (!$objLogin->IsLoggedInAsAdmin() && $payment_type_paypal == 'Frontend Only')) ? 'yes' : 'no';
  472. $payment_type_2co = ($payment_type_2co == 'Frontend & Backend' || ($objLogin->IsLoggedInAsAdmin() && $payment_type_2co == 'Backend Only') || (!$objLogin->IsLoggedInAsAdmin() && $payment_type_2co == 'Frontend Only')) ? 'yes' : 'no';
  473. $payment_type_authorize = ($payment_type_authorize == 'Frontend & Backend' || ($objLogin->IsLoggedInAsAdmin() && $payment_type_authorize == 'Backend Only') || (!$objLogin->IsLoggedInAsAdmin() && $payment_type_authorize == 'Frontend Only')) ? 'yes' : 'no';
  474.  
  475. $payment_type_cnt = (($payment_type_poa === 'yes')+
  476. ($payment_type_online === 'yes')+
  477. ($payment_type_bank_transfer === 'yes')+
  478. ($payment_type_paypal === 'yes')+
  479. ($payment_type_2co === 'yes')+
  480. ($payment_type_authorize === 'yes'));
  481. $payment_types_defined = true;
  482. $allow_children = ModulesSettings::Get('rooms', 'allow_children');
  483. $allow_extra_beds = ModulesSettings::Get('rooms', 'allow_extra_beds');
  484. $meal_plans_count = MealPlans::MealPlansCount();
  485.  
  486. $find_user = isset($_GET['cl']) ? prepare_input($_GET['cl']) : '';
  487. $cid = isset($_GET['cid']) ? prepare_input($_GET['cid']) : '';
  488. if($cid != ''){
  489. if($cid != 'admin'){
  490. $this->currentCustomerID = $cid;
  491. Session::Set('sel_current_customer_id', $cid);
  492. $this->selectedUser = 'customer';
  493. }else{
  494. $this->currentCustomerID = $objLogin->GetLoggedID();
  495. $this->selectedUser = 'admin';
  496. Session::Set('sel_current_customer_id', '');
  497. }
  498. }
  499.  
  500. if($objLogin->IsLoggedInAsAdmin() && $this->selectedUser == 'admin'){
  501. $table_name = TABLE_ACCOUNTS;
  502. $sql='SELECT '.$table_name.'.*
  503. FROM '.$table_name.'
  504. WHERE '.$table_name.'.id = '.(int)$this->currentCustomerID;
  505. }else{
  506. $table_name = TABLE_CUSTOMERS;
  507. $sql='SELECT
  508. '.$table_name.'.*,
  509. cnt.name as country_name,
  510. cnt.vat_value,
  511. IF(st.name IS NOT NULL, st.name, '.$table_name.'.b_state) as b_state
  512. FROM '.$table_name.'
  513. LEFT OUTER JOIN '.TABLE_COUNTRIES.' cnt ON '.$table_name.'.b_country = cnt.abbrv AND cnt.is_active = 1
  514. LEFT OUTER JOIN '.TABLE_STATES.' st ON '.$table_name.'.b_state = st.abbrv AND st.country_id = cnt.id AND st.is_active = 1
  515. WHERE '.$table_name.'.id = '.(int)$this->currentCustomerID;
  516. }
  517. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  518. if($result[1] <= 0){
  519. draw_message(_RESERVATION_CART_IS_EMPTY_ALERT, true, true);
  520. return false;
  521. }
  522.  
  523. if(count($this->arrReservation) > 0){
  524. $extras = Extras::GetAllExtras();
  525. echo "\n".'<script type="text/javascript">'."\n";
  526. echo 'var arrExtras = new Array('.$extras[1].');'."\n";
  527. echo 'var arrExtrasSelected = new Array('.$extras[1].');'."\n";
  528. if($extras[1]){
  529. for($i=0; $i<$extras[1]; $i++){
  530. echo 'arrExtras['.$i.'] = "'.($extras[0][$i]['price'] * $this->currencyRate).'";'."\n";
  531. echo 'arrExtrasSelected['.$i.'] = 0;'."\n";
  532. }
  533. }
  534. echo '</script>'."\n";
  535.  
  536. echo '<form id="checkout-form" action="index.php?page=booking_payment" method="post">
  537. '.draw_hidden_field('task', 'do_booking', false).'
  538. '.draw_hidden_field('submition_type', '', false).'
  539. '.draw_hidden_field('selected_user', $this->selectedUser, false).'
  540. '.draw_token_field(false);
  541.  
  542. echo '<table class="reservation_cart" border="0" width="99%" align="center" cellspacing="0" cellpadding="5">
  543. <tr>
  544. <td colspan="2"><h4>'._BILLING_DETAILS.' &nbsp;';
  545. if($objLogin->IsLoggedIn()){
  546. if($objLogin->IsLoggedInAsCustomer()){
  547. echo '<a style="font-size:13px;" href="javascript:void(0);" onclick="javascript:appGoTo(\'customer=my_account\')">['._EDIT_WORD.']</a> ';
  548. }else if($objLogin->IsLoggedInAsAdmin()){
  549.  
  550. echo '<br>'._CHANGE_CUSTOMER.':
  551. <input type="text" id="find_user" name="find_user" value="" size="10" maxlength="40" />
  552. <input type="button" class="button" value="'._SEARCH.'" onclick="javascript:appGoTo(\'page=booking_checkout&cl=\'+jQuery(\'#find_user\').val())" />
  553. <select name="sel_customer" id="sel_customer">';
  554. if($find_user == ''){
  555. if($this->selectedUser == 'admin'){
  556. echo '<option value="admin">'.$result[0]['first_name'].' '.$result[0]['last_name'].' ('.$result[0]['user_name'].')</option>';
  557. }else{
  558. echo '<option value="'.$result[0]['id'].'">ID:'.$result[0]['id'].' '.$result[0]['first_name'].' '.$result[0]['last_name'].' ('.(($result[0]['user_name'] != '') ? $result[0]['user_name'] : _WITHOUT_ACCOUNT).')'.'</option>';
  559. }
  560. }else{
  561. $objCustomers = new Customers();
  562. $result_customers = $objCustomers->GetAllCustomers(' AND (last_name like \''.$find_user.'%\' OR first_name like \''.$find_user.'%\' OR user_name like \''.$find_user.'%\') ');
  563. if($result_customers[1] > 0){
  564. for($i = 0; $i < $result_customers[1]; $i++){
  565. echo '<option value="'.$result_customers[0][$i]['id'].'">ID:'.$result_customers[0][$i]['id'].' '.$result_customers[0][$i]['first_name'].' '.$result_customers[0][$i]['last_name'].' ('.(($result_customers[0][$i]['user_name'] != '') ? $result_customers[0][$i]['user_name'] : _WITHOUT_ACCOUNT).')'.'</option>';
  566. }
  567. }else{
  568. echo '<option value="admin">'.$result[0]['first_name'].' '.$result[0]['last_name'].' ('.$result[0]['user_name'].')</option>';
  569. }
  570. }
  571. echo '</select> ';
  572. if($find_user != '') echo '<input type="button" class="button" value="'._APPLY.'" onclick="javascript:appGoTo(\'page=booking_checkout&cid=\'+jQuery(\'#sel_customer\').val())"/> ';
  573. echo '<input type="button" class="button" value="'._SET_ADMIN.'" onclick="javascript:appGoTo(\'page=booking_checkout&cid=admin\')"/>';
  574. if($find_user != '' && $result_customers[1] == 0) echo ' '._NO_CUSTOMER_FOUND;
  575. }
  576. }else{
  577. echo '<a style="font-size:13px;" href="javascript:void(0);" onclick="javascript:appGoTo(\'page=booking_details\',\'&m=edit\')">['._EDIT_WORD.']</a> ';
  578. }
  579. echo '</h4>
  580. </td>
  581. </tr>
  582. <tr>
  583. <td style="padding-left:10px;">
  584. '._FIRST_NAME.': '.$result[0]['first_name'].'<br />
  585. '._LAST_NAME.': '.$result[0]['last_name'].'<br />';
  586. if(!$objLogin->IsLoggedInAsAdmin()){
  587. echo _ADDRESS.': '.$result[0]['b_address'].'<br />';
  588. //echo _ADDRESS_2.': '.$result[0]['b_address_2'].'<br />';
  589. echo _CITY.': '.$result[0]['b_city'].'<br />';
  590. //echo _ZIP_CODE.': '.$result[0]['b_zipcode'].'<br />';
  591. echo _COUNTRY.': '.$result[0]['country_name'].'<br />';
  592. //echo _STATE.': '.$result[0]['b_state'].'<br />';
  593. }
  594. echo '</td>
  595. <td></td>
  596. </tr>
  597. </table><br />';
  598.  
  599. echo '<table class="reservation_cart" border="0" width="99%" align="center" cellspacing="0" cellpadding="5">
  600. <tr><td colspan="10"><h4>'._RESERVATION_DETAILS.'</h4></td></tr>
  601. <tr class="header">
  602. <th class="'.$class_left.'" width="40px">&nbsp;</th>
  603. <th align="'.$class_left.'">'._ROOM_TYPE.'</th>
  604. <th align="center">'._FROM.'</th>
  605. <th align="center">'._TO.'</th>
  606. <th width="60px" align="center">'._NIGHTS.'</th>
  607. <th width="50px" align="center">'._ROOMS.'</th>
  608. <th width="70px" colspan="3" align="center">'._OCCUPANCY.'</th>
  609. '.(($meal_plans_count) ? '<th width="60px" align="center">'._MEAL_PLANS.'</th>' : '<th style="padding:0px;">&nbsp;</th>').'
  610. <th class="'.$class_right.'" width="80px" align="'.$class_right.'">'._PRICE.'</th>
  611. </tr>
  612. <tr><td colspan="11" nowrap="nowrap" height="5px"></td></tr>';
  613.  
  614. echo '<tr style="font-size:10px;background-color:transparent;">
  615. <th colspan="6"></th>
  616. <th align="center">'._ADULT.'</th>
  617. '.(($allow_children == 'yes') ? '<th align="center">'._CHILD.'</th>' : '<th></th>').'
  618. '.(($allow_extra_beds == 'yes') ? '<th align="center">'._EXTRA_BEDS.'</th>' : '<th></th>').'
  619. <th colspan="2"></th>
  620. </tr>';
  621.  
  622. $order_price = 0;
  623. $total_adults = 0;
  624. $total_children = 0;
  625. foreach($this->arrReservation as $key => $val){
  626. $sql = 'SELECT
  627. '.TABLE_ROOMS.'.id,
  628. '.TABLE_ROOMS.'.room_type,
  629. '.TABLE_ROOMS.'.room_icon_thumb,
  630. '.TABLE_ROOMS.'.max_adults,
  631. '.TABLE_ROOMS.'.max_children,
  632. '.TABLE_ROOMS.'.default_price as price,
  633. '.TABLE_ROOMS_DESCRIPTION.'.room_type as loc_room_type,
  634. '.TABLE_ROOMS_DESCRIPTION.'.room_short_description as loc_room_short_description,
  635. '.TABLE_HOTELS_DESCRIPTION.'.name as hotel_name
  636. FROM '.TABLE_ROOMS.'
  637. INNER JOIN '.TABLE_ROOMS_DESCRIPTION.' ON '.TABLE_ROOMS.'.id = '.TABLE_ROOMS_DESCRIPTION.'.room_id
  638. INNER JOIN '.TABLE_HOTELS_DESCRIPTION.' ON '.TABLE_ROOMS.'.hotel_id = '.TABLE_HOTELS_DESCRIPTION.'.hotel_id
  639. WHERE
  640. '.TABLE_ROOMS.'.id = '.(int)$key.' AND
  641. '.TABLE_ROOMS_DESCRIPTION.'.language_id = \''.$this->lang.'\' AND
  642. '.TABLE_HOTELS_DESCRIPTION.'.language_id = \''.$this->lang.'\' ';
  643.  
  644. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  645. if($result[1] > 0){
  646. $room_icon_thumb = ($result[0]['room_icon_thumb'] != '') ? $result[0]['room_icon_thumb'] : 'no_image.png';
  647. $room_price_w_meal_extrabeds = ($val['price'] + $val['meal_plan_price'] + $val['extra_beds_charge']);
  648. echo '<tr>
  649. <td><img src="images/rooms_icons/'.$room_icon_thumb.'" alt="icon" width="32px" height="32px" /></td>
  650. <td>
  651. <b>'.prepare_link('rooms', 'room_id', $result[0]['id'], $result[0]['loc_room_type'], $result[0]['loc_room_type'], '', _CLICK_TO_VIEW).'</b><br>
  652. '.$result[0]['hotel_name'].'
  653. </td>
  654. <td align="center">'.format_date($val['from_date'], $this->fieldDateFormat, '', true).'</td>
  655. <td align="center">'.format_date($val['to_date'], $this->fieldDateFormat, '', true).'</td>
  656. <td align="center">'.$val['nights'].'</td>
  657. <td align="center">'.$val['rooms'].'</td>
  658. <td align="center">'.$val['adults'].'</td>
  659. '.(($allow_children == 'yes') ? '<td align="center">'.$val['children'].'</td>' : '<td></td>').'
  660. '.(($allow_extra_beds == 'yes') ? '<td align="center">'.$val['extra_beds'].'</td>' : '<td></td>').'
  661. '.(($meal_plans_count) ? '<td align="center">'.$val['meal_plan_name'].'</td>' : '<td></td>').'
  662. <td align="'.$class_right.'">'.Currencies::PriceFormat($room_price_w_meal_extrabeds * $this->currencyRate, '', '', $this->currencyFormat).'&nbsp;</td>
  663. </tr>
  664. <tr><td colspan="11" nowrap height="3px"></td></tr>';
  665. $order_price += ($room_price_w_meal_extrabeds * $this->currencyRate);
  666. $total_adults += $val['adults'];
  667. $total_children += ($allow_children == 'yes') ? $val['children'] : 0;
  668. }
  669. }
  670.  
  671. // draw sub-total row
  672. echo '<tr>
  673. <td colspan="7"></td>
  674. <td class="td '.$class_left.'" colspan="3"><b>'._SUBTOTAL.':</b></td>
  675. <td class="td '.$class_right.'" align="'.$class_right.'">
  676. <b>'.Currencies::PriceFormat($order_price, '', '', $this->currencyFormat).'</b>
  677. </td>
  678. </tr>';
  679.  
  680. //echo '<tr><td colspan="10" nowrap height="5px"></td></tr>';
  681.  
  682. // EXTRAS
  683. // ------------------------------------------------------------
  684. if($extras[1]){
  685. echo '<tr><td colspan="11" nowrap height="10px"></td></tr>';
  686. echo '<tr><td colspan="11"><h4>'._EXTRAS.'</h4></td></tr>';
  687. echo '<tr><td colspan="11"><table width="340px">';
  688. for($i=0; $i<$extras[1]; $i++){
  689. $extras_id = (($submition_type == 'apply_coupon') && isset($_POST['extras_'.$extras[0][$i]['id']])) ? $_POST['extras_'.$extras[0][$i]['id']] : 0;
  690. echo '<tr>';
  691. echo '<td wrap="wrap">'.$extras[0][$i]['name'].' <span class="help" title="'.$extras[0][$i]['description'].'">[?]</span></td>';
  692. echo '<td>&nbsp;</td>';
  693. echo '<td align="right">'.Currencies::PriceFormat($extras[0][$i]['price'] * $this->currencyRate, '', '', $this->currencyFormat).'</td>';
  694. echo '<td>&nbsp;</td>';
  695. echo '<td>'.draw_numbers_select_field('extras_'.$extras[0][$i]['id'], $extras_id, '0', $extras[0][$i]['maximum_count'], 1, 'extras_ddl', 'onchange="appUpdateTotalSum('.$i.',this.value,'.(int)$extras[1].')"', false).'</td>';
  696. echo '</tr>';
  697. }
  698. echo '</table></td></tr>';
  699. }
  700.  
  701. // calculate discount
  702. $discount_value = ($order_price * ($this->discountPercent / 100));
  703. $order_price -= $discount_value;
  704.  
  705. // calculate percent
  706. $vat_cost = (($order_price + $this->bookingInitialFee + ($this->guestTax * ($total_adults + $total_children))) * ($this->vatPercent / 100));
  707. $cart_total = ($order_price + $this->bookingInitialFee + ($this->guestTax * ($total_adults + $total_children))) + $vat_cost;
  708.  
  709. if($this->discountCampaignID != '' || $this->discountCoupon != ''){
  710. echo '<tr>
  711. <td colspan="7"></td>
  712. <td class="td '.$class_left.'" colspan="3"><b><span style="color:#a60000">'._DISCOUNT.': ('.Currencies::PriceFormat($this->discountPercent, '%', 'after', $this->currencyFormat).')</span></b></td>
  713. <td class="td '.$class_right.'" align="'.$class_right.'"><b><span style="color:#a60000">- '.Currencies::PriceFormat($discount_value, '', '', $this->currencyFormat).'</span></b></td>
  714. </tr>';
  715. }
  716. if(!empty($this->bookingInitialFee)){
  717. echo '<tr>
  718. <td colspan="7"></td>
  719. <td class="td '.$class_left.'" colspan="3"><b>'._INITIAL_FEE.': </b></td>
  720. <td class="td '.$class_right.'" align="'.$class_right.'"><b>'.Currencies::PriceFormat($this->bookingInitialFee, '', '', $this->currencyFormat).'</b></td>
  721. </tr>';
  722. }
  723. if(!empty($this->guestTax)){
  724. echo '<tr>
  725. <td colspan="7"></td>
  726. <td class="td '.$class_left.'" colspan="3"><b>'._GUEST_TAX.': </b></td>
  727. <td class="td '.$class_right.'" align="'.$class_right.'">
  728. <b><label id="guest_tax" data-price="'.(float)($this->guestTax * ($total_adults + $total_children)).'">'.Currencies::PriceFormat(($this->guestTax * ($total_adults + $total_children)), '', '', $this->currencyFormat).'</label></b>
  729. </td>
  730. </tr>';
  731. }
  732. if($this->vatIncludedInPrice == 'no'){
  733. echo '<tr>
  734. <td colspan="7"></td>
  735. <td class="td '.$class_left.'" colspan="3"><b>'._VAT.': ('.Currencies::PriceFormat($this->vatPercent, '%', 'after', $this->currencyFormat, $this->GetVatPercentDecimalPoints($this->vatPercent)).')</b></td>
  736. <td class="td '.$class_right.'" align="'.$class_right.'">
  737. <b><label id="reservation_vat">'.Currencies::PriceFormat($vat_cost, '', '', $this->currencyFormat).'</label></b>
  738. </td>
  739. </tr>';
  740. }
  741. echo '<tr><td colspan="11" nowrap height="5px"></td></tr>
  742. <tr class="footer">
  743. <td colspan="7"></td>
  744. <td class="td '.$class_left.'" colspan="3"><b>'._TOTAL.':</b></td>
  745. <td class="td '.$class_right.'" align="'.$class_right.'">
  746. <b><label id="reservation_total">'.Currencies::PriceFormat($cart_total, '', '', $this->currencyFormat).'</label></b>
  747. </td>
  748. </tr>';
  749.  
  750. // PAYMENT DETAILS
  751. // ------------------------------------------------------------
  752. echo '<tr><td colspan="11" nowrap height="12px"></td></tr>';
  753. echo '<tr><td colspan="11"><h4>'._PAYMENT_DETAILS.'</h4></td></tr>';
  754. echo '<tr><td colspan="11">';
  755. echo '<table border="0" width="100%">';
  756. if($payment_type_cnt > 1){
  757. echo '<tr><td width="130px" nowrap>'._PAYMENT_TYPE.': &nbsp;</td><td>
  758. <select name="payment_type" id="payment_type">';
  759. if($payment_type_poa == 'yes') echo '<option value="poa" '.(($payment_type == 'poa') ? 'selected="selected"' : '').'>'._PAY_ON_ARRIVAL.'</option>';
  760. if($payment_type_online == 'yes') echo '<option value="online" '.(($payment_type == 'online') ? 'selected="selected"' : '').'>'._ONLINE_ORDER.'</option>';
  761. if($payment_type_bank_transfer == 'yes') echo '<option value="bank.transfer" '.(($payment_type == 'bank.transfer') ? 'selected="selected"' : '').'>'._BANK_TRANSFER.'</option>';
  762. if($payment_type_paypal == 'yes') echo '<option value="paypal" '.(($payment_type == 'paypal') ? 'selected="selected"' : '').'>'._PAYPAL.'</option>';
  763. if($payment_type_2co == 'yes') echo '<option value="2co" '.(($payment_type == '2co') ? 'selected="selected"' : '').'>2CO</option>';
  764. if($payment_type_authorize == 'yes') echo '<option value="authorize.net" '.(($payment_type == 'authorize.net') ? 'selected="selected"' : '').'>Authorize.Net</option>';
  765. echo '</select>';
  766. echo '</td></tr>';
  767. }else if($payment_type_cnt == 1){
  768. if($payment_type_poa == 'yes') $payment_type_hidden = 'poa';
  769. else if($payment_type_online == 'yes') $payment_type_hidden = 'online';
  770. else if($payment_type_bank_transfer == 'yes') $payment_type_hidden = 'bank.transfer';
  771. else if($payment_type_paypal == 'yes') $payment_type_hidden = 'paypal';
  772. else if($payment_type_2co == 'yes') $payment_type_hidden = '2co';
  773. else if($payment_type_authorize == 'yes') $payment_type_hidden = 'authorize.net';
  774. else{
  775. $payment_type_hidden = '';
  776. $payment_types_defined = false;
  777. }
  778. echo '<tr><td>'.draw_hidden_field('payment_type', $payment_type_hidden, false, 'payment_type').'</td></tr>';
  779. }else{
  780. $payment_types_defined = false;
  781. echo '<tr><td colspan="2">'.draw_important_message(_NO_PAYMENT_METHODS_ALERT, false).'</td></tr>';
  782. }
  783. echo '<tr>';
  784. if($pre_payment_type == 'first night' && $this->first_night_possible){
  785. echo '<td>'._PAYMENT_METHOD.': </td>';
  786. echo '<td>';
  787. echo '<input type="radio" name="pre_payment_type" id="pre_payment_fully" value="full price" checked="checked /> <label for="pre_payment_fully">'._FULL_PRICE.'</label> &nbsp;&nbsp;';
  788. echo '<input type="radio" name="pre_payment_type" id="pre_payment_partially" value="first night" /> <label for="pre_payment_partially">'._FIRST_NIGHT.'</label>';
  789. echo draw_hidden_field('pre_payment_value', $pre_payment_value, false, 'pre_payment_full');
  790. echo '</td>';
  791. }else if($pre_payment_type == 'percentage' && $pre_payment_value > '0' && $pre_payment_value < '100'){
  792. echo '<td>'._PAYMENT_METHOD.': </td>';
  793. echo '<td>';
  794. echo '<input type="radio" name="pre_payment_type" id="pre_payment_fully" value="full price" checked="checked" /> <label for="pre_payment_fully">'._FULL_PRICE.'</label> &nbsp;&nbsp;';
  795. echo '<input type="radio" name="pre_payment_type" id="pre_payment_partially" value="percentage" /> <label for="pre_payment_partially">'._PRE_PAYMENT.' ('.Currencies::PriceFormat($pre_payment_value, '%', 'after', $this->currencyFormat).')</label>';
  796. echo draw_hidden_field('pre_payment_value', $pre_payment_value, false, 'pre_payment_full');
  797. echo '</td>';
  798. }else if($pre_payment_type == 'fixed sum' && $pre_payment_value > '0'){
  799. echo '<td>'._PAYMENT_METHOD.': </td>';
  800. echo '<td>';
  801. echo '<input type="radio" name="pre_payment_type" id="pre_payment_fully" value="full price" checked="checked" /> <label for="pre_payment_fully">'._FULL_PRICE.'</label> &nbsp;&nbsp;';
  802. echo '<input type="radio" name="pre_payment_type" id="pre_payment_partially" value="fixed sum" /> <label for="pre_payment_partially">'._PRE_PAYMENT.' ('.Currencies::PriceFormat($pre_payment_value * $this->currencyRate, '', '', $this->currencyFormat).')</label>';
  803. echo draw_hidden_field('pre_payment_value', $pre_payment_value, false, 'pre_payment_full');
  804. echo '</td>';
  805. }else{
  806. echo '<td colspan="2">';
  807. // full price payment
  808. if($payment_type_cnt <= 1 && $payment_types_defined) echo _FULL_PRICE;
  809. echo draw_hidden_field('pre_payment_type', 'full price', false, 'pre_payment_fully');
  810. echo draw_hidden_field('pre_payment_value', '100', false, 'pre_payment_full');
  811. echo '</td>';
  812. }
  813. echo '</tr>';
  814. echo '</table></td></tr>';
  815.  
  816. if($payment_types_defined){
  817. // PROMO CODES OR DISCOUNT COUPONS
  818. // ------------------------------------------------------------
  819. echo '<tr><td colspan="11" nowrap height="12px"></td></tr>';
  820. echo '<tr><td colspan="11"><h4>'._PROMO_CODE_OR_COUPON.'</h4></td></tr>';
  821. echo '<tr><td colspan="11">'._PROMO_COUPON_NOTICE.'</td></tr>';
  822. echo '<tr>';
  823. echo '<td colspan="11">';
  824. if(!empty($this->discountCoupon)){
  825. echo '<input type="text" class="discount_coupon" name="discount_coupon" id="discount_coupon" value="'.$this->discountCoupon.'" readonly="readonly" maxlength="32" autocomplete="off" />&nbsp;&nbsp;&nbsp;';
  826. echo '<input type="button" class="button" id="discount_button" value="'._REMOVE.'" onclick="appSubmitCoupon(\'remove_coupon\')" />';
  827. }else{
  828. echo '<input type="text" class="discount_coupon" name="discount_coupon" id="discount_coupon" value="'.$this->discountCoupon.'" maxlength="32" autocomplete="off" />&nbsp;&nbsp;&nbsp;';
  829. echo '<input type="button" class="button" id="discount_button" value="'._APPLY.'" onclick="appSubmitCoupon(\'apply_coupon\')" />';
  830. }
  831. echo '</td>';
  832. echo '</tr>';
  833.  
  834. echo '<tr><td colspan="11" nowrap height="15px"></td></tr>
  835. <tr valign="middle">
  836. <td colspan="11" nowrap height="15px">
  837. <h4 style="cursor:pointer;" onclick="appToggleElement(\'additional_info\')">'._ADDITIONAL_INFO.' +</h4>
  838. <textarea name="additional_info" id="additional_info" style="display:none;width:100%;height:75px"></textarea>
  839. </td>
  840. </tr>
  841. <tr><td colspan="11" nowrap height="5px"></td></tr>
  842. <tr valign="middle">
  843. <td colspan="8" align="'.$class_right.'"></td>
  844. <td align="'.$class_right.'" colspan="3">
  845. '.(($payment_types_defined) ? '<input class="button" type="submit" value="'._SUBMIT_BOOKING.'" />' : '').'
  846. </td>
  847. </tr>';
  848. echo '</table>';
  849. echo '<input type="hidden" id="hid_vat_percent" value="'.$this->vatPercent.'" />';
  850. echo '<input type="hidden" id="hid_booking_initial_fee" value="'.$this->bookingInitialFee.'" />';
  851. echo '<input type="hidden" id="hid_booking_guest_tax" value="'.($this->guestTax * ($total_adults + $total_children)).'" />';
  852. echo '<input type="hidden" id="hid_order_price" value="'.$order_price.'" />';
  853. echo '<input type="hidden" id="hid_currency_symbol" value="'.Application::Get('currency_symbol').'" />';
  854. echo '<input type="hidden" id="hid_currency_format" value="'.$this->currencyFormat.'" />';
  855. echo '</form><br>';
  856.  
  857. if($submition_type == 'apply_coupon'){
  858. echo "\n".'<script type="text/javascript">'."\n";
  859. for($i=0; $i<$extras[1]; $i++){
  860. $extras_id = isset($_POST['extras_'.$extras[0][$i]['id']]) ? $_POST['extras_'.$extras[0][$i]['id']] : 0;
  861. if($extras_id > 0){
  862. echo 'appUpdateTotalSum('.$i.','.$extras_id.','.$extras[1].')'.";\n";
  863. }
  864. }
  865. echo '</script>'."\n";
  866. }
  867. }else{
  868. echo '</table>';
  869. echo '</form>';
  870. return '';
  871. }
  872. }else{
  873. draw_message(_RESERVATION_CART_IS_EMPTY_ALERT, true, true);
  874. }
  875. }
  876.  
  877. /**
  878. * Empty Reservation Cart
  879. */
  880. public function EmptyCart()
  881. {
  882. $this->arrReservation = array();
  883. $this->arrReservationInfo = array();
  884. Session::Set('current_customer_id', '');
  885. }
  886.  
  887. /**
  888. * Returns amount of items in Reservation Cart
  889. */
  890. public function GetCartItems()
  891. {
  892. return $this->cartItems;
  893. }
  894.  
  895. /**
  896. * Returns total number of adults in Reservation Cart
  897. */
  898. public function GetAdultsInCart()
  899. {
  900. $adults_number = 0;
  901.  
  902. if(count($this->arrReservation) > 0){
  903. foreach($this->arrReservation as $key => $val){
  904. $adults_number += isset($val['adults']) ? (int)$val['adults'] : 0;
  905. }
  906. }
  907.  
  908. return $adults_number;
  909. }
  910.  
  911. /**
  912. * Returns total number of children in Reservation Cart
  913. */
  914. public function GetChildrenInCart()
  915. {
  916. $children_number = 0;
  917.  
  918. if(count($this->arrReservation) > 0){
  919. foreach($this->arrReservation as $key => $val){
  920. $children_number += isset($val['children']) ? (int)$val['children'] : 0;
  921. }
  922. }
  923. return $children_number;
  924. }
  925.  
  926. /**
  927. * Checks if cart is empty
  928. */
  929. public function IsCartEmpty()
  930. {
  931. return ($this->cartItems > 0) ? false : true;
  932. }
  933.  
  934. /**
  935. * Draw reservation info
  936. * @param $payment_type
  937. * @param $additional_info
  938. * @param $extras
  939. * @param $pre_payment_type
  940. * @param $pre_payment_value
  941. * @param $draw
  942. */
  943. public function DrawReservation($payment_type, $additional_info, $extras = array(), $pre_payment_type = '', $pre_payment_value = '', $draw = true)
  944. {
  945. global $objLogin;
  946.  
  947. $class_left = Application::Get('defined_left');
  948. $class_right = Application::Get('defined_right');
  949. $output = '';
  950.  
  951. $cc_type = isset($_POST['cc_type']) ? prepare_input($_POST['cc_type']) : '';
  952. $cc_holder_name = isset($_POST['cc_holder_name']) ? prepare_input($_POST['cc_holder_name']) : '';
  953. $cc_number = isset($_POST['cc_number']) ? prepare_input($_POST['cc_number']) : '';
  954. $cc_expires_month = isset($_POST['cc_expires_month']) ? prepare_input($_POST['cc_expires_month']) : '01';
  955. $cc_expires_year = isset($_POST['cc_expires_year']) ? prepare_input($_POST['cc_expires_year']) : date('Y');
  956. $cc_cvv_code = isset($_POST['cc_cvv_code']) ? prepare_input($_POST['cc_cvv_code']) : '';
  957.  
  958. $paypal_email = ModulesSettings::Get('booking', 'paypal_email');
  959. $credit_card_required = ModulesSettings::Get('booking', 'online_credit_card_required');
  960. $two_checkout_vendor = ModulesSettings::Get('booking', 'two_checkout_vendor');
  961. $authorize_login_id = ModulesSettings::Get('booking', 'authorize_login_id');
  962. $authorize_transaction_key = ModulesSettings::Get('booking', 'authorize_transaction_key');
  963. $bank_transfer_info = ModulesSettings::Get('booking', 'bank_transfer_info');
  964. $mode = ModulesSettings::Get('booking', 'mode');
  965.  
  966. // specify API login and key for separate hotels
  967. if(ModulesSettings::Get('booking', 'allow_separate_gateways') == 'yes'){
  968. $hotel_id = $this->GetReservationHotelId();
  969. $info = HotelPaymentGateways::GetPaymentInfo($hotel_id, $payment_type);
  970.  
  971. if($payment_type == 'paypal'){
  972. $paypal_email = isset($info[0]['api_login']) ? $info[0]['api_login'] : '';
  973. }else if($payment_type == '2co'){
  974. $two_checkout_vendor = $info[0]['api_login'];
  975. }else if($payment_type == 'authorize.net'){
  976. $authorize_login_id = $info[0]['api_login'];
  977. $authorize_transaction_key = isset($info[0]['api_key']) ? $info[0]['api_key'] : '';
  978. }else if($payment_type == 'bank.transfer'){
  979. $bank_transfer_info = isset($info[0]['payment_info']) ? $info[0]['payment_info'] : '';
  980. }
  981. }
  982.  
  983. // prepare customers info
  984. $sql='SELECT * FROM '.TABLE_CUSTOMERS.' WHERE id = '.(int)$this->currentCustomerID;
  985. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  986. $customer_info = array();
  987. $customer_info['first_name'] = isset($result[0]['first_name']) ? $result[0]['first_name'] : '';
  988. $customer_info['last_name'] = isset($result[0]['last_name']) ? $result[0]['last_name'] : '';
  989. $customer_info['address1'] = isset($result[0]['b_address']) ? $result[0]['b_address'] : '';
  990. $customer_info['address2'] = isset($result[0]['b_address2']) ? $result[0]['b_address2'] : '';
  991. $customer_info['city'] = isset($result[0]['b_city']) ? $result[0]['b_city'] : '';
  992. $customer_info['state'] = isset($result[0]['b_state']) ? $result[0]['b_state'] : '';
  993. $customer_info['zip'] = isset($result[0]['b_zipcode']) ? $result[0]['b_zipcode'] : '';
  994. $customer_info['country'] = isset($result[0]['b_country']) ? $result[0]['b_country'] : '';
  995. $customer_info['email'] = isset($result[0]['email']) ? $result[0]['email'] : '';
  996. $customer_info['company'] = isset($result[0]['company']) ? $result[0]['company'] : '';
  997. $customer_info['phone'] = isset($result[0]['phone']) ? $result[0]['phone'] : '';
  998. $customer_info['fax'] = isset($result[0]['fax']) ? $result[0]['fax'] : '';
  999.  
  1000. if($cc_holder_name == ''){
  1001. if($objLogin->IsLoggedIn()){
  1002. $cc_holder_name = $objLogin->GetLoggedFirstName().' '.$objLogin->GetLoggedLastName();
  1003. }else{
  1004. $cc_holder_name = $customer_info['first_name'].' '.$customer_info['last_name'];
  1005. }
  1006. }
  1007.  
  1008. // check if prepared booking exists and replace it
  1009. $sql='SELECT id, booking_number
  1010. FROM '.TABLE_BOOKINGS.'
  1011. WHERE customer_id = '.(int)$this->currentCustomerID.' AND
  1012. status = 0 AND
  1013. is_admin_reservation = '.(($this->selectedUser == 'admin') ? '1' : '0').'
  1014. ORDER BY id DESC';
  1015. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  1016. if($result[1] > 0){
  1017. $booking_number = $result[0]['booking_number'];
  1018. $order_price = $this->cartTotalSum;
  1019.  
  1020. // Calculate total number of adults
  1021. $total_adults = $this->GetAdultsInCart();
  1022.  
  1023. // Calculate total number of children
  1024. $total_children = $this->GetChildrenInCart();
  1025.  
  1026. // prepare extras
  1027. $extras_text = '';
  1028. $extras_param = '';
  1029. $extras_sub_total = 0;
  1030. if(count($extras) > 0){
  1031. $extras_text_header = '<tr><td colspan="3" nowrap height="10px"></td></tr>
  1032. <tr><td colspan="3"><h4>'._EXTRAS.'</h4></td></tr>
  1033. <tr><td colspan="3">';
  1034. $extras_text_middle = '';
  1035. foreach($extras as $key => $val){
  1036. $extr = Extras::GetExtrasInfo($key);
  1037. if($val){
  1038. $extras_sub_total += ($extr['price'] * $this->currencyRate) * $val;
  1039. $extras_text_middle .= '<tr><td nowrap="nowrap">'.$extr['name'].'&nbsp;</td>';
  1040. $extras_text_middle .= '<td> : </td>';
  1041. $extras_text_middle .= '<td> '.Currencies::PriceFormat($extr['price'] * $this->currencyRate, '', '', $this->currencyFormat).' x '.$val;
  1042. $extras_text_middle .= draw_hidden_field('extras_'.$key, $val, false)."\n";
  1043. $extras_param .= draw_hidden_field('extras_'.$key, $val, false)."\n";
  1044. $extras_text_middle .= '</td></tr>';
  1045. }
  1046. }
  1047. $extras_text_footer = '<tr><td>'._EXTRAS_SUBTOTAL.' </td><td> : </td><td> <b>'.Currencies::PriceFormat($extras_sub_total, '', '', $this->currencyFormat).'</b></td></tr>';
  1048. $extras_text_footer .= '</td></tr>';
  1049.  
  1050. if($extras_sub_total >= 0){
  1051. $extras_text = $extras_text_header.$extras_text_middle.$extras_text_footer;
  1052. }
  1053. }
  1054.  
  1055. // calculate discount
  1056. $discount_value = ($order_price * ($this->discountPercent / 100));
  1057. $order_price_after_discount = $order_price - $discount_value;
  1058.  
  1059. // calculate VAT
  1060. $cart_total_wo_vat = round($order_price_after_discount + $extras_sub_total, 2);
  1061. $vat_cost = (($cart_total_wo_vat + $this->bookingInitialFee + ($this->guestTax * ($total_adults + $total_children))) * ($this->vatPercent / 100));
  1062. $cart_total = round($cart_total_wo_vat, 2) + $this->bookingInitialFee + ($this->guestTax * ($total_adults + $total_children)) + $vat_cost;
  1063.  
  1064. if($pre_payment_type == 'first night'){
  1065. $is_prepayment = true;
  1066. $cart_total = ($this->firstNightSum * (1 + $this->vatPercent / 100));
  1067. $prepayment_text = _FIRST_NIGHT;
  1068. }else if(($pre_payment_type == 'percentage') && (int)$pre_payment_value > 0 && (int)$pre_payment_value < 100){
  1069. $is_prepayment = true;
  1070. $cart_total = ($cart_total * ($pre_payment_value / 100));
  1071. $prepayment_text = $pre_payment_value.'%';
  1072. }else if(($pre_payment_type == 'fixed sum') && (int)$pre_payment_value > 0){
  1073. $is_prepayment = true;
  1074. $cart_total = round($pre_payment_value * $this->currencyRate, 2);
  1075. $prepayment_text = _FIXED_SUM;
  1076. }else{
  1077. $prepayment_text = '';
  1078. $is_prepayment = false;
  1079. }
  1080.  
  1081. $pp_params = array(
  1082. 'api_login' => '',
  1083. 'transaction_key' => '',
  1084. 'payment_info' => $bank_transfer_info,
  1085.  
  1086. 'booking_number' => $booking_number,
  1087.  
  1088. 'address1' => $customer_info['address1'],
  1089. 'address2' => $customer_info['address2'],
  1090. 'city' => $customer_info['city'],
  1091. 'zip' => $customer_info['zip'],
  1092. 'country' => $customer_info['country'],
  1093. 'state' => $customer_info['state'],
  1094. 'first_name' => $customer_info['first_name'],
  1095. 'last_name' => $customer_info['last_name'],
  1096. 'email' => $customer_info['email'],
  1097. 'company' => $customer_info['company'],
  1098. 'phone' => $customer_info['phone'],
  1099. 'fax' => $customer_info['fax'],
  1100.  
  1101. 'notify' => '',
  1102. 'return' => 'index.php?page=booking_return',
  1103. //'cancel_return' => 'index.php?page=booking_cancel',
  1104. 'cancel_return' => 'index.php?page=booking',
  1105.  
  1106. 'paypal_form_type' => '',
  1107. 'paypal_form_fields' => '',
  1108. 'paypal_form_fields_count' => '',
  1109.  
  1110. 'credit_card_required' => '',
  1111. 'cc_type' => '',
  1112. 'cc_holder_name' => '',
  1113. 'cc_number' => '',
  1114. 'cc_cvv_code' => '',
  1115. 'cc_expires_month' => '',
  1116. 'cc_expires_year' => '',
  1117.  
  1118. 'currency_code' => Application::Get('currency_code'),
  1119. 'additional_info' => $additional_info,
  1120. 'discount_value' => $discount_value,
  1121. 'extras_param' => $extras_param,
  1122. 'extras_sub_total' => $extras_sub_total,
  1123. 'vat_cost' => $vat_cost,
  1124. 'cart_total' => number_format((float)$cart_total, (int)Application::Get('currency_decimals'), '.', ''),
  1125. 'is_prepayment' => $is_prepayment,
  1126. 'pre_payment_type' => $pre_payment_type,
  1127. 'pre_payment_value' => $pre_payment_value,
  1128. );
  1129.  
  1130. $fisrt_part = '<table border="0" width="97%" align="center">
  1131. <tr><td width="20%">'._BOOKING_DATE.' </td><td width="2%"> : </td><td> '.format_date(date('Y-m-d H:i:s'), $this->fieldDateFormat, '', true).'</td></tr>
  1132. <tr><td>'._ROOMS.' </td><td> : </td><td> '.(int)$this->roomsCount.'</td></tr>
  1133. <tr><td>'._BOOKING_PRICE.' </td><td width="2%"> : </td><td> '.Currencies::PriceFormat($order_price, '', '', $this->currencyFormat).'</td></tr>';
  1134. if($discount_value != ''){
  1135. $fisrt_part .= '<tr><td>'._DISCOUNT.' </td><td> : </td><td> - '.Currencies::PriceFormat($discount_value, '', '', $this->currencyFormat).' ('.Currencies::PriceFormat($this->discountPercent, '%', 'after', $this->currencyFormat).')</td></tr>';
  1136. $fisrt_part .= '<tr><td>'._BOOKING_SUBTOTAL.' </td><td> : </td><td> <b>'.Currencies::PriceFormat($order_price_after_discount, '', '', $this->currencyFormat).'</b></td></tr>';
  1137. }
  1138.  
  1139. $fisrt_part .= ((count($extras) > 0) ? $extras_text : '').'
  1140. <tr><td colspan="3" nowrap height="10px"></td></tr>
  1141. <tr><td colspan="3"><h4>'._TOTAL.'</h4></td></tr>
  1142. <tr><td>'._SUBTOTAL.' </td><td> : </td><td> '.Currencies::PriceFormat($cart_total_wo_vat, '', '', $this->currencyFormat).'</td></tr>';
  1143. if(!empty($this->bookingInitialFee)){
  1144. $fisrt_part .= '<tr><td>'._INITIAL_FEE.' </td><td> : </td><td> '.Currencies::PriceFormat($this->bookingInitialFee, '', '', $this->currencyFormat).'</td></tr>';
  1145. }
  1146. if(!empty($this->guestTax)){
  1147. $fisrt_part .= '<tr><td>'._GUEST_TAX.' </td><td> : </td><td> '.Currencies::PriceFormat(($this->guestTax * ($total_adults + $total_children)), '', '', $this->currencyFormat).'</td></tr>';
  1148. }
  1149. if($this->vatIncludedInPrice == 'no'){
  1150. $fisrt_part .= '<tr><td>'._VAT.' ('.Currencies::PriceFormat($this->vatPercent, '%', 'after', $this->currencyFormat, $this->GetVatPercentDecimalPoints($this->vatPercent)).') </td><td> : </td><td> '.Currencies::PriceFormat($vat_cost, '', '', $this->currencyFormat).'</td></tr>';
  1151. }
  1152. if($is_prepayment){
  1153. $fisrt_part .= '<tr><td>'._PAYMENT_SUM.' </td><td> : </td><td> <b>'.Currencies::PriceFormat($order_price_after_discount + $extras_sub_total + $this->bookingInitialFee + ($this->guestTax * ($total_adults + $total_children)) + $vat_cost, '', '', $this->currencyFormat).'</b></td></tr>';
  1154. $fisrt_part .= '<tr><td>'._PRE_PAYMENT.'</td><td> : </td> <td>'.Currencies::PriceFormat($cart_total, '', '', $this->currencyFormat).' ('.$prepayment_text.')</td></tr>';
  1155. }else{
  1156. $fisrt_part .= '<tr><td>'._PAYMENT_SUM.' </td><td> : </td><td> <b>'.Currencies::PriceFormat($order_price_after_discount + $extras_sub_total + $this->bookingInitialFee + ($this->guestTax * ($total_adults + $total_children)) + $vat_cost, '', '', $this->currencyFormat).'</b></td></tr>';
  1157. ///echo '<tr><td>'._PRE_PAYMENT.'</td><td> : </td> <td>'._FULL_PRICE.'</td></tr>';
  1158. }
  1159. if($additional_info != ''){
  1160. $fisrt_part .= '<tr><td colspan="3" nowrap height="10px"></td></tr>';
  1161. $fisrt_part .= '<tr><td colspan="3"><h4>'._ADDITIONAL_INFO.'</h4>'.$additional_info.'</td></tr>';
  1162. }
  1163.  
  1164. $second_part = '</table><br />';
  1165.  
  1166. if($payment_type == 'poa'){
  1167.  
  1168. $output .= $fisrt_part;
  1169. $output .= PaymentIPN::DrawPaymentForm('poa', $pp_params, (($mode == 'TEST MODE') ? 'test' : 'real'), false);
  1170. $output .= $second_part;
  1171.  
  1172. }else if($payment_type == 'online'){
  1173.  
  1174. $output .= $fisrt_part;
  1175. $pp_params['credit_card_required'] = $credit_card_required;
  1176. $pp_params['cc_type'] = $cc_type;
  1177. $pp_params['cc_holder_name'] = $cc_holder_name;
  1178. $pp_params['cc_number'] = $cc_number;
  1179. $pp_params['cc_cvv_code'] = $cc_cvv_code;
  1180. $pp_params['cc_expires_month'] = $cc_expires_month;
  1181. $pp_params['cc_expires_year'] = $cc_expires_year;
  1182. $output .= PaymentIPN::DrawPaymentForm('online', $pp_params, (($mode == 'TEST MODE') ? 'test' : 'real'), false);
  1183. $output .= $second_part;
  1184.  
  1185. }else if($payment_type == 'paypal'){
  1186.  
  1187. $output .= $fisrt_part;
  1188. $pp_params['api_login'] = $paypal_email;
  1189. $pp_params['notify'] = 'index.php?page=booking_notify_paypal';
  1190. $pp_params['paypal_form_type'] = $this->paypal_form_type;
  1191. $pp_params['paypal_form_fields'] = $this->paypal_form_fields;
  1192. $pp_params['paypal_form_fields_count'] = $this->paypal_form_fields_count;
  1193. $output .= PaymentIPN::DrawPaymentForm('paypal', $pp_params, (($mode == 'TEST MODE') ? 'test' : 'real'), false);
  1194. $output .= $second_part;
  1195.  
  1196. }else if($payment_type == '2co'){
  1197.  
  1198. $output .= $fisrt_part;
  1199. $pp_params['api_login'] = $two_checkout_vendor;
  1200. $pp_params['notify'] = 'index.php?page=booking_notify_2co';
  1201. $output .= PaymentIPN::DrawPaymentForm('2co', $pp_params, (($mode == 'TEST MODE') ? 'test' : 'real'), false);
  1202. $output .= $second_part;
  1203.  
  1204. }else if($payment_type == 'authorize.net'){
  1205.  
  1206. $output .= $fisrt_part;
  1207. $pp_params['api_login'] = $authorize_login_id;
  1208. $pp_params['transaction_key'] = $authorize_transaction_key;
  1209. $pp_params['notify'] = 'index.php?page=booking_notify_autorize_net';
  1210. // authorize.net accepts only USD, so we need to convert the sum into USD
  1211. $pp_params['cart_total'] = number_format((($pp_params['cart_total'] * Application::Get('currency_rate'))), '2', '.', ',');
  1212. $output .= PaymentIPN::DrawPaymentForm('authorize.net', $pp_params, (($mode == 'TEST MODE') ? 'test' : 'real'), false);
  1213. $output .= $second_part;
  1214.  
  1215. }else if($payment_type == 'bank.transfer'){
  1216.  
  1217. $output .= $fisrt_part;
  1218. $output .= PaymentIPN::DrawPaymentForm('bank.transfer', $pp_params, (($mode == 'TEST MODE') ? 'test' : 'real'), false);
  1219. $output .= $second_part;
  1220. }
  1221. }else{
  1222. ///echo $sql.database_error();
  1223. $output .= draw_important_message(_ORDER_ERROR, false);
  1224. }
  1225.  
  1226. if($draw) echo $output;
  1227. else return $output;
  1228. }
  1229.  
  1230. /**
  1231. * Place booking
  1232. * @param $additional_info
  1233. * @param $cc_params
  1234. */
  1235. public function PlaceBooking($additional_info = '', $cc_params = array())
  1236. {
  1237. global $objLogin;
  1238. $additional_info = substr_by_word($additional_info, 1024);
  1239.  
  1240. if(SITE_MODE == 'demo'){
  1241. $this->message = draw_important_message(_OPERATION_BLOCKED, false);
  1242. return false;
  1243. }
  1244.  
  1245. // check if prepared booking exists
  1246. $sql = 'SELECT id, booking_number, payment_type
  1247. FROM '.TABLE_BOOKINGS.'
  1248. WHERE customer_id = '.(int)$this->currentCustomerID.' AND
  1249. is_admin_reservation = '.(($this->selectedUser == 'admin') ? '1' : '0').' AND
  1250. status = 0
  1251. ORDER BY id DESC';
  1252.  
  1253. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  1254. if($result[1] > 0){
  1255. $booking_number = $result[0]['booking_number'];
  1256. if($this->selectedUser == 'admin'){
  1257. // For admin always make status - 2 - reserved
  1258. $status = 2;
  1259. }else{
  1260. $status = ($result[0]['payment_type'] == 0) ? 1 : 2;
  1261. }
  1262. $sql = 'UPDATE '.TABLE_BOOKINGS.'
  1263. SET
  1264. status_changed = \''.date('Y-m-d H:i:s').'\',
  1265. additional_info = \''.$additional_info.'\',
  1266. cc_type = \''.$cc_params['cc_type'].'\',
  1267. cc_holder_name = \''.$cc_params['cc_holder_name'].'\',
  1268. cc_number = AES_ENCRYPT(\''.$cc_params['cc_number'].'\', \''.PASSWORDS_ENCRYPT_KEY.'\'),
  1269. cc_expires_month = \''.$cc_params['cc_expires_month'].'\',
  1270. cc_expires_year = \''.$cc_params['cc_expires_year'].'\',
  1271. cc_cvv_code = AES_ENCRYPT(\''.$cc_params['cc_cvv_code'].'\', \''.PASSWORDS_ENCRYPT_KEY.'\'),
  1272. status = \''.$status.'\'
  1273. WHERE booking_number = \''.$booking_number.'\'';
  1274. database_void_query($sql);
  1275.  
  1276. // update customer bookings/rooms amount
  1277. $sql = 'UPDATE '.TABLE_CUSTOMERS.' SET
  1278. orders_count = orders_count + 1,
  1279. rooms_count = rooms_count + '.$this->roomsCount.'
  1280. WHERE id = '.(int)$this->currentCustomerID;
  1281. database_void_query($sql);
  1282. if(!$objLogin->IsLoggedIn()){
  1283. // clear selected user ID for non-registered visitors
  1284. Session::Set('sel_current_customer_id', '');
  1285. }
  1286.  
  1287. $this->message = draw_success_message(str_replace('_BOOKING_NUMBER_', '<b>'.$booking_number.'</b>', _ORDER_PLACED_MSG), false);
  1288. if($this->SendOrderEmail($booking_number, 'placed', $this->currentCustomerID)){
  1289. $this->message .= draw_success_message(_EMAIL_SUCCESSFULLY_SENT, false);
  1290. }else{
  1291. if($objLogin->IsLoggedInAsAdmin()){
  1292. $this->message .= draw_important_message(_EMAIL_SEND_ERROR, false);
  1293. }
  1294. }
  1295. }else{
  1296. $this->message = draw_important_message(_EMAIL_SEND_ERROR, false);
  1297. }
  1298.  
  1299. if(SITE_MODE == 'development' && database_error() != '') $this->message .= '<br>'.$sql.'<br>'.database_error();
  1300.  
  1301. $this->EmptyCart();
  1302. }
  1303.  
  1304. /**
  1305. * Makes reservation
  1306. * @param $payment_type
  1307. * @param $additional_info
  1308. * @param $extras
  1309. * @param $pre_payment_type
  1310. * @param $pre_payment_value
  1311. */
  1312. public function DoReservation($payment_type = '', $additional_info = '', $extras = array(), $pre_payment_type = '', $pre_payment_value = '')
  1313. {
  1314. global $objLogin;
  1315.  
  1316. if(SITE_MODE == 'demo'){
  1317. $this->error = draw_important_message(_OPERATION_BLOCKED, false);
  1318. return false;
  1319. }
  1320.  
  1321. // check the maximum allowed room reservation per customer
  1322. if($this->selectedUser == 'customer'){
  1323. $sql = 'SELECT COUNT(*) as cnt FROM '.TABLE_BOOKINGS.' WHERE customer_id = '.(int)$this->currentCustomerID.' AND status < 3';
  1324. $result = database_query($sql, DATA_ONLY);
  1325. $cnt = isset($result[0]['cnt']) ? (int)$result[0]['cnt'] : 0;
  1326. if($cnt >= $this->maximumAllowedReservations){
  1327. $this->error = draw_important_message(_MAX_RESERVATIONS_ERROR, false);
  1328. return false;
  1329. }
  1330. }
  1331.  
  1332. $booking_placed = false;
  1333. $booking_number = '';
  1334. $additional_info = substr_by_word($additional_info, 1024);
  1335.  
  1336. $order_price = $this->cartTotalSum;
  1337.  
  1338. // calculate extras
  1339. $extras_sub_total = '0';
  1340. $extras_info = array();
  1341. foreach($extras as $key => $val){
  1342. $extr = Extras::GetExtrasInfo($key);
  1343. $extras_sub_total += ($extr['price'] * $this->currencyRate) * $val;
  1344. $extras_info[$key] = $val;
  1345. }
  1346. ///$order_price += $extras_sub_total;
  1347.  
  1348. // calculate discount
  1349. $discount_value = ($order_price * ($this->discountPercent / 100));
  1350. $order_price_after_discount = $order_price - $discount_value;
  1351.  
  1352. // Calculate total number of adults
  1353. $total_adults = $this->GetAdultsInCart();
  1354.  
  1355. // Calculate total number of children
  1356. $total_children = $this->GetChildrenInCart();
  1357.  
  1358. // calculate VAT
  1359. $cart_total_wo_vat = round($order_price_after_discount + $extras_sub_total, 2);
  1360. $vat_cost = (($cart_total_wo_vat + $this->bookingInitialFee + ($this->guestTax * ($total_adults + $total_children))) * ($this->vatPercent / 100));
  1361. $cart_total = round($cart_total_wo_vat, 2) + $this->bookingInitialFee + ($this->guestTax * ($total_adults + $total_children)) + $vat_cost;
  1362.  
  1363. if($pre_payment_type == 'first night'){
  1364. $cart_total = ($this->firstNightSum * (1 + $this->vatPercent / 100));
  1365. }else if(($pre_payment_type == 'percentage') && (int)$pre_payment_value > 0 && (int)$pre_payment_value < 100){
  1366. $cart_total = ($cart_total * ($pre_payment_value / 100));
  1367. }else if(($pre_payment_type == 'fixed sum') && (int)$pre_payment_value > 0){
  1368. $cart_total = round($pre_payment_value * $this->currencyRate, 2);
  1369. }else{
  1370. // $cart_total
  1371. }
  1372.  
  1373. if($this->cartItems > 0){
  1374. // add order to database
  1375. if(in_array($payment_type, array('poa', 'online', 'paypal', '2co', 'authorize.net', 'bank.transfer'))){
  1376. if($payment_type == 'bank.transfer'){
  1377. $payed_by = '5';
  1378. $status = '0';
  1379. }else if($payment_type == 'authorize.net'){
  1380. $payed_by = '4';
  1381. $status = '0';
  1382. }else if($payment_type == '2co'){
  1383. $payed_by = '3';
  1384. $status = '0';
  1385. }else if($payment_type == 'paypal'){
  1386. $payed_by = '2';
  1387. $status = '0';
  1388. }else if($payment_type == 'online'){
  1389. $payed_by = '1';
  1390. $status = '0';
  1391. }else{
  1392. $payed_by = '0';
  1393. $status = '0';
  1394. }
  1395.  
  1396. // check if prepared booking exists and replace it
  1397. $sql = 'SELECT id, booking_number
  1398. FROM '.TABLE_BOOKINGS.'
  1399. WHERE customer_id = '.(int)$this->currentCustomerID.' AND
  1400. is_admin_reservation = '.(($this->selectedUser == 'admin') ? '1' : '0').' AND
  1401. status = 0
  1402. ORDER BY id DESC';
  1403. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  1404. if($result[1] > 0){
  1405. $booking_number = $result[0]['booking_number'];
  1406. // booking exists - replace it with new
  1407. $sql = 'DELETE FROM '.TABLE_BOOKINGS_ROOMS.' WHERE booking_number = \''.$booking_number.'\'';
  1408. if(!database_void_query($sql)){ /* echo 'error!'; */ }
  1409.  
  1410. $sql = 'UPDATE '.TABLE_BOOKINGS.' SET ';
  1411. $sql_end = ' WHERE booking_number = \''.$booking_number.'\'';
  1412. $is_new_record = false;
  1413. }else{
  1414. $sql = 'INSERT INTO '.TABLE_BOOKINGS.' SET booking_number = \'\',';
  1415. $sql_end = '';
  1416. $is_new_record = true;
  1417. }
  1418.  
  1419. $sql .= 'booking_description = \''._ROOMS_RESERVATION.'\',
  1420. order_price = '.number_format((float)$order_price, (int)Application::Get('currency_decimals'), '.', '').',
  1421. pre_payment_type = \''.$pre_payment_type.'\',
  1422. pre_payment_value = \''.(($pre_payment_type != 'full price') ? $pre_payment_value : '0').'\',
  1423. discount_campaign_id = '.(int)$this->discountCampaignID.',
  1424. discount_percent = '.$this->discountPercent.',
  1425. discount_fee = '.$discount_value.',
  1426. vat_fee = '.$vat_cost.',
  1427. vat_percent = '.$this->vatPercent.',
  1428. initial_fee = '.$this->bookingInitialFee.',
  1429. guest_tax = '.($this->guestTax * ($total_adults + $total_children)).',
  1430. extras = \''.serialize($extras_info).'\',
  1431. extras_fee = \''.$extras_sub_total.'\',
  1432. payment_sum = '.number_format((float)$cart_total, (int)Application::Get('currency_decimals'), '.', '').',
  1433. additional_payment = 0,
  1434. currency = \''.$this->currencyCode.'\',
  1435. rooms_amount = '.(int)$this->roomsCount.',
  1436. customer_id = '.(int)$this->currentCustomerID.',
  1437. is_admin_reservation = '.(($this->selectedUser == 'admin') ? '1' : '0').',
  1438. transaction_number = \'\',
  1439. created_date = \''.date('Y-m-d H:i:s').'\',
  1440. payment_type = '.$payed_by.',
  1441. payment_method = 0,
  1442. coupon_code = \''.$this->discountCoupon.'\',
  1443. additional_info = \''.$additional_info.'\',
  1444. cc_type = \'\',
  1445. cc_holder_name = \'\',
  1446. cc_number = \'\',
  1447. cc_expires_month = \'\',
  1448. cc_expires_year = \'\',
  1449. cc_cvv_code = \'\',
  1450. status = '.(int)$status.',
  1451. status_description = \'\'';
  1452. $sql .= $sql_end;
  1453.  
  1454. // handle booking details
  1455. if(database_void_query($sql)){
  1456. if($is_new_record){
  1457. $insert_id = database_insert_id();
  1458. $booking_number = $this->GenerateBookingNumber($insert_id);
  1459. $sql = 'UPDATE '.TABLE_BOOKINGS.' SET booking_number = \''.$booking_number.'\' WHERE id = '.(int)$insert_id;
  1460. if(!database_void_query($sql)){
  1461. $this->error = draw_important_message(_ORDER_ERROR, false);
  1462. }
  1463. }
  1464.  
  1465. $sql = 'INSERT INTO '.TABLE_BOOKINGS_ROOMS.'
  1466. (id, booking_number, hotel_id, room_id, room_numbers, checkin, checkout, adults, children, rooms, price, extra_beds, extra_beds_charge, meal_plan_id, meal_plan_price)
  1467. VALUES ';
  1468. $items_count = 0;
  1469. foreach($this->arrReservation as $key => $val){
  1470. $sql .= ($items_count++ > 0) ? ',' : '';
  1471. $sql .= '(NULL, \''.$booking_number.'\', '.(int)$val['hotel_id'].', '.(int)$key.', \'\', \''.$val['from_date'].'\', \''.$val['to_date'].'\', \''.$val['adults'].'\', \''.$val['children'].'\', '.(int)$val['rooms'].', '.($val['price'] * $this->currencyRate).', '.(int)$val['extra_beds'].', '.($val['extra_beds_charge'] * $this->currencyRate).', '.(int)$val['meal_plan_id'].', '.($val['meal_plan_price'] * $this->currencyRate).')';
  1472. }
  1473. if(database_void_query($sql)){
  1474. $booking_placed = true;
  1475. }else{
  1476. $this->error = draw_important_message(_ORDER_ERROR, false);
  1477. }
  1478. }else{
  1479. $this->error = draw_important_message(_ORDER_ERROR, false);
  1480. }
  1481. }else{
  1482. $this->error = draw_important_message(_ORDER_ERROR, false);
  1483. }
  1484. }else{
  1485. $this->error = draw_message(_RESERVATION_CART_IS_EMPTY_ALERT, false, true);
  1486. }
  1487.  
  1488. if(SITE_MODE == 'development' && !empty($this->error)) $this->error .= '<br>'.$sql.'<br>'.database_error();
  1489.  
  1490. return $booking_placed;
  1491. }
  1492.  
  1493. /**
  1494. * Sends booking email
  1495. * @param booking_number
  1496. * @param $order_type
  1497. * @param $customer_id
  1498. */
  1499. public function SendOrderEmail($booking_number, $order_type = 'placed', $customer_id = '')
  1500. {
  1501. global $objSettings;
  1502.  
  1503. $lang = Application::Get('lang');
  1504. $return = true;
  1505. $personal_information = '';
  1506. $allow_children = ModulesSettings::Get('rooms', 'allow_children');
  1507. $allow_extra_beds = ModulesSettings::Get('rooms', 'allow_extra_beds');
  1508. $hotels_count = Hotels::HotelsCount();
  1509. $meal_plans_count = MealPlans::MealPlansCount();
  1510.  
  1511. $arr_payment_types = array(
  1512. '0'=>_PAY_ON_ARRIVAL,
  1513. '1'=>_ONLINE_ORDER,
  1514. '2'=>_PAYPAL,
  1515. '3'=>'2CO',
  1516. '4'=>'Authorize.Net',
  1517. '5'=>_BANK_TRANSFER
  1518. );
  1519.  
  1520. $arr_statuses = array(
  1521. '0'=>_PREBOOKING,
  1522. '1'=>_PENDING,
  1523. '2'=>_RESERVED,
  1524. '3'=>_COMPLETED,
  1525. '4'=>_REFUNDED,
  1526. '5'=>_PAYMENT_ERROR,
  1527. '6'=>_CANCELED,
  1528. '-1'=>_UNKNOWN
  1529. );
  1530.  
  1531. // send email to customer
  1532. $sql = 'SELECT
  1533. '.TABLE_BOOKINGS.'.id,
  1534. '.TABLE_BOOKINGS.'.booking_number,
  1535. '.TABLE_BOOKINGS.'.booking_description,
  1536. '.TABLE_BOOKINGS.'.order_price,
  1537. '.TABLE_BOOKINGS.'.discount_fee,
  1538. '.TABLE_BOOKINGS.'.discount_percent,
  1539. '.TABLE_BOOKINGS.'.coupon_code,
  1540. '.TABLE_BOOKINGS.'.vat_fee,
  1541. '.TABLE_BOOKINGS.'.vat_percent,
  1542. '.TABLE_BOOKINGS.'.initial_fee,
  1543. '.TABLE_BOOKINGS.'.guest_tax,
  1544. '.TABLE_BOOKINGS.'.extras,
  1545. '.TABLE_BOOKINGS.'.extras_fee,
  1546. '.TABLE_BOOKINGS.'.payment_sum,
  1547. '.TABLE_BOOKINGS.'.currency,
  1548. '.TABLE_BOOKINGS.'.rooms_amount,
  1549. '.TABLE_BOOKINGS.'.customer_id,
  1550. '.TABLE_BOOKINGS.'.transaction_number,
  1551. '.TABLE_BOOKINGS.'.created_date,
  1552. '.TABLE_BOOKINGS.'.payment_date,
  1553. '.TABLE_BOOKINGS.'.payment_type,
  1554. '.TABLE_BOOKINGS.'.payment_method,
  1555. '.TABLE_BOOKINGS.'.status,
  1556. '.TABLE_BOOKINGS.'.status_description,
  1557. '.TABLE_BOOKINGS.'.email_sent,
  1558. '.TABLE_BOOKINGS.'.additional_info,
  1559. '.TABLE_BOOKINGS.'.is_admin_reservation,
  1560. CASE
  1561. WHEN '.TABLE_BOOKINGS.'.payment_method = 0 THEN \''._PAYMENT_COMPANY_ACCOUNT.'\'
  1562. WHEN '.TABLE_BOOKINGS.'.payment_method = 1 THEN \''._CREDIT_CARD.'\'
  1563. WHEN '.TABLE_BOOKINGS.'.payment_method = 2 THEN \''._ECHECK.'\'
  1564. ELSE \''._UNKNOWN.'\'
  1565. END as mod_payment_method,
  1566. IF((('.TABLE_BOOKINGS.'.order_price - '.TABLE_BOOKINGS.'.discount_fee) + '.TABLE_BOOKINGS.'.initial_fee + '.TABLE_BOOKINGS.'.extras_fee + '.TABLE_BOOKINGS.'.vat_fee - ('.TABLE_BOOKINGS.'.payment_sum + '.TABLE_BOOKINGS.'.additional_payment) > 0),
  1567. (('.TABLE_BOOKINGS.'.order_price - '.TABLE_BOOKINGS.'.discount_fee) + '.TABLE_BOOKINGS.'.initial_fee + '.TABLE_BOOKINGS.'.extras_fee + '.TABLE_BOOKINGS.'.vat_fee - ('.TABLE_BOOKINGS.'.payment_sum + '.TABLE_BOOKINGS.'.additional_payment)),
  1568. 0
  1569. ) as mod_have_to_pay,
  1570. '.TABLE_CUSTOMERS.'.first_name,
  1571. '.TABLE_CUSTOMERS.'.last_name,
  1572. '.TABLE_CUSTOMERS.'.user_name as customer_name,
  1573. '.TABLE_CUSTOMERS.'.email,
  1574. '.TABLE_CUSTOMERS.'.preferred_language,
  1575. '.TABLE_CUSTOMERS.'.b_address,
  1576. '.TABLE_CUSTOMERS.'.b_address_2,
  1577. '.TABLE_CUSTOMERS.'.b_city,
  1578. '.TABLE_CUSTOMERS.'.b_zipcode,
  1579. '.TABLE_CUSTOMERS.'.phone,
  1580. '.TABLE_CUSTOMERS.'.fax,
  1581. '.TABLE_CURRENCIES.'.symbol,
  1582. '.TABLE_CURRENCIES.'.symbol_placement,
  1583. '.TABLE_CAMPAIGNS.'.campaign_name,
  1584. '.TABLE_COUNTRIES.'.name as b_country,
  1585. IF('.TABLE_STATES.'.name IS NOT NULL, '.TABLE_STATES.'.name, '.TABLE_CUSTOMERS.'.b_state) as b_state
  1586. FROM '.TABLE_BOOKINGS.'
  1587. INNER JOIN '.TABLE_CURRENCIES.' ON '.TABLE_BOOKINGS.'.currency = '.TABLE_CURRENCIES.'.code
  1588. LEFT OUTER JOIN '.TABLE_CAMPAIGNS.' ON '.TABLE_BOOKINGS.'.discount_campaign_id = '.TABLE_CAMPAIGNS.'.id
  1589. LEFT OUTER JOIN '.TABLE_CUSTOMERS.' ON '.TABLE_BOOKINGS.'.customer_id = '.TABLE_CUSTOMERS.'.id
  1590. LEFT OUTER JOIN '.TABLE_COUNTRIES.' ON '.TABLE_CUSTOMERS.'.b_country = '.TABLE_COUNTRIES.'.abbrv AND '.TABLE_COUNTRIES.'.is_active = 1
  1591. LEFT OUTER JOIN '.TABLE_STATES.' ON '.TABLE_CUSTOMERS.'.b_state = '.TABLE_STATES.'.abbrv AND '.TABLE_STATES.'.country_id = '.TABLE_COUNTRIES.'.id AND '.TABLE_STATES.'.is_active = 1
  1592. WHERE
  1593. '.TABLE_BOOKINGS.'.customer_id = '.$customer_id.' AND
  1594. '.TABLE_BOOKINGS.'.booking_number = \''.$booking_number.'\'';
  1595.  
  1596. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  1597. if($result[1] > 0){
  1598. $recipient = $result[0]['email'];
  1599. $first_name = $result[0]['first_name'];
  1600. $last_name = $result[0]['last_name'];
  1601. $email_sent = $result[0]['email_sent'];
  1602. $status = $result[0]['status'];
  1603. $status_description = $result[0]['status_description'];
  1604. $preferred_language = $result[0]['preferred_language'];
  1605. $is_admin_reservation = $result[0]['is_admin_reservation'];
  1606. $payment_type = (int)$result[0]['payment_type'];
  1607.  
  1608. if(ModulesSettings::Get('booking', 'mode') == 'TEST MODE'){
  1609. $personal_information .= '<div style="text-align:center;padding:10px;color:#a60000;border:1px dashed #a60000;width:100px">TEST MODE!</div><br />';
  1610. }
  1611.  
  1612. $personal_information .= '<b>'._PERSONAL_INFORMATION.':</b>';
  1613. $personal_information .= '<br />-----------------------------<br />';
  1614. $personal_information .= _FIRST_NAME.' : '.$result[0]['first_name'].'<br />';
  1615. $personal_information .= _LAST_NAME.' : '.$result[0]['last_name'].'<br />';
  1616. $personal_information .= _EMAIL_ADDRESS.' : '.$result[0]['email'].'<br />';
  1617.  
  1618. $billing_information = '<b>'._BILLING_DETAILS.':</b>';
  1619. $billing_information .= '<br />-----------------------------<br />';
  1620. $billing_information .= _ADDRESS.' : '.$result[0]['b_address'].' '.$result[0]['b_address_2'].'<br />';
  1621. $billing_information .= _CITY.' : '.$result[0]['b_city'].'<br />';
  1622. $billing_information .= _STATE.' : '.$result[0]['b_state'].'<br />';
  1623. $billing_information .= _COUNTRY.' : '.$result[0]['b_country'].'<br />';
  1624. $billing_information .= _ZIP_CODE.' : '.$result[0]['b_zipcode'].'<br />';
  1625. if(!empty($result[0]['phone'])) $billing_information .= _PHONE.' : '.$result[0]['phone'].'<br />';
  1626. if(!empty($result[0]['fax'])) $billing_information .= _FAX.' : '.$result[0]['fax'].'<br />';
  1627.  
  1628. $booking_details = _BOOKING_DESCRIPTION.': '.$result[0]['booking_description'].'<br />';
  1629. $booking_details .= _CREATED_DATE.': '.format_datetime($result[0]['created_date'], $this->fieldDateFormat.' H:i:s', '', true).'<br />';
  1630. $payment_date = format_datetime($result[0]['payment_date'], $this->fieldDateFormat.' H:i:s', '', true);
  1631. if(empty($payment_date)) $payment_date = _NOT_PAID_YET;
  1632. $booking_details .= _PAYMENT_DATE.': '.$payment_date.'<br />';
  1633. $booking_details .= _PAYMENT_TYPE.': '.((isset($arr_payment_types[$payment_type])) ? $arr_payment_types[$payment_type] : '').'<br />';
  1634. $booking_details .= _PAYMENT_METHOD.': '.$result[0]['mod_payment_method'].'<br />';
  1635. $booking_details .= _CURRENCY.': '.$result[0]['currency'].'<br />';
  1636. $booking_details .= _ROOMS.': '.$result[0]['rooms_amount'].'<br />';
  1637. $booking_details .= _BOOKING_PRICE.': '.Currencies::PriceFormat($result[0]['order_price'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  1638. $booking_details .= (($result[0]['campaign_name'] != '') ? _DISCOUNT.': - '.Currencies::PriceFormat($result[0]['discount_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).' ('.Currencies::PriceFormat($result[0]['discount_percent'], '%', 'after', $this->currencyFormat).' - '.$result[0]['campaign_name'].')<br />' : '');
  1639. $booking_details .= (($result[0]['coupon_code'] != '') ? _DISCOUNT.': - '.Currencies::PriceFormat($result[0]['discount_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).' ('.Currencies::PriceFormat($result[0]['discount_percent'], '%', 'after', $this->currencyFormat).' - '._COUPON_CODE.': '.$result[0]['coupon_code'].')<br />' : '');
  1640. $booking_details .= _BOOKING_SUBTOTAL.(($result[0]['campaign_name'] != '') ? ' ('._AFTER_DISCOUNT.')' : '').': '.Currencies::PriceFormat($result[0]['order_price'] - $result[0]['discount_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  1641.  
  1642. if(!empty($result[0]['extras'])) $booking_details .= _EXTRAS_SUBTOTAL.': '.Currencies::PriceFormat($result[0]['extras_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  1643.  
  1644. if(!empty($this->bookingInitialFee)) $booking_details .= _INITIAL_FEE.': '.Currencies::PriceFormat($result[0]['initial_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  1645. if(!empty($this->guestTax)) $booking_details .= _GUEST_TAX.': '.Currencies::PriceFormat($result[0]['guest_tax'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  1646. if($this->vatIncludedInPrice == 'no'){
  1647. $booking_details .= _VAT.': '.Currencies::PriceFormat($result[0]['vat_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).' ('.Currencies::PriceFormat($result[0]['vat_percent'], '%', 'after', $this->currencyFormat, $this->GetVatPercentDecimalPoints($result[0]['vat_percent'])).')<br />';
  1648. }
  1649. $booking_details .= _PAYMENT_SUM.': '.Currencies::PriceFormat($result[0]['payment_sum'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  1650. $booking_details .= _PAYMENT_REQUIRED.': '.Currencies::PriceFormat($result[0]['mod_have_to_pay'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  1651. if($result[0]['additional_info'] != '') $booking_details .= _ADDITIONAL_INFO.': '.nl2br($result[0]['additional_info']).'<br />';
  1652. $booking_details .= '<br />';
  1653.  
  1654. // display list of extras in order
  1655. // -----------------------------------------------------------------------------
  1656. $booking_details .= Extras::GetExtrasList(unserialize($result[0]['extras']), $result[0]['currency'], 'email');
  1657.  
  1658. // display list of rooms in order
  1659. // -----------------------------------------------------------------------------
  1660. $booking_details .= '<b>'._RESERVATION_DETAILS.':</b>';
  1661. $booking_details .= '<br />-----------------------------<br />';
  1662. $sql = 'SELECT
  1663. '.TABLE_BOOKINGS_ROOMS.'.booking_number,
  1664. '.TABLE_BOOKINGS_ROOMS.'.rooms,
  1665. '.TABLE_BOOKINGS_ROOMS.'.adults,
  1666. '.TABLE_BOOKINGS_ROOMS.'.children,
  1667. '.TABLE_BOOKINGS_ROOMS.'.extra_beds,
  1668. '.TABLE_BOOKINGS_ROOMS.'.checkin,
  1669. '.TABLE_BOOKINGS_ROOMS.'.checkout,
  1670. '.TABLE_BOOKINGS_ROOMS.'.price,
  1671. '.TABLE_BOOKINGS_ROOMS.'.meal_plan_price,
  1672. '.TABLE_BOOKINGS_ROOMS.'.extra_beds_charge,
  1673. '.TABLE_BOOKINGS.'.currency,
  1674. '.TABLE_CURRENCIES.'.symbol,
  1675. '.TABLE_ROOMS_DESCRIPTION.'.room_type,
  1676. '.TABLE_HOTELS.'.email as hotel_email,
  1677. '.TABLE_HOTELS_DESCRIPTION.'.name as hotel_name,
  1678. '.TABLE_MEAL_PLANS_DESCRIPTION.'.name as meal_plan_name,
  1679. '.TABLE_HOTELS_DESCRIPTION.'.name as hotel_name
  1680. FROM '.TABLE_BOOKINGS.'
  1681. INNER JOIN '.TABLE_BOOKINGS_ROOMS.' ON '.TABLE_BOOKINGS.'.booking_number = '.TABLE_BOOKINGS_ROOMS.'.booking_number
  1682. INNER JOIN '.TABLE_ROOMS.' ON '.TABLE_BOOKINGS_ROOMS.'.room_id = '.TABLE_ROOMS.'.id
  1683. INNER JOIN '.TABLE_ROOMS_DESCRIPTION.' ON '.TABLE_ROOMS.'.id = '.TABLE_ROOMS_DESCRIPTION.'.room_id AND '.TABLE_ROOMS_DESCRIPTION.'.language_id = \''.$this->lang.'\'
  1684. LEFT OUTER JOIN '.TABLE_CURRENCIES.' ON '.TABLE_BOOKINGS.'.currency = '.TABLE_CURRENCIES.'.code
  1685. LEFT OUTER JOIN '.TABLE_CUSTOMERS.' ON '.TABLE_BOOKINGS.'.customer_id = '.TABLE_CUSTOMERS.'.id
  1686. LEFT OUTER JOIN '.TABLE_HOTELS.' ON '.TABLE_BOOKINGS_ROOMS.'.hotel_id = '.TABLE_HOTELS.'.id
  1687. LEFT OUTER JOIN '.TABLE_HOTELS_DESCRIPTION.' ON '.TABLE_BOOKINGS_ROOMS.'.hotel_id = '.TABLE_HOTELS_DESCRIPTION.'.hotel_id AND '.TABLE_HOTELS_DESCRIPTION.'.language_id = \''.$this->lang.'\'
  1688. LEFT OUTER JOIN '.TABLE_MEAL_PLANS_DESCRIPTION.' ON '.TABLE_BOOKINGS_ROOMS.'.meal_plan_id = '.TABLE_MEAL_PLANS_DESCRIPTION.'.meal_plan_id AND '.TABLE_MEAL_PLANS_DESCRIPTION.'.language_id = \''.$this->lang.'\'
  1689. WHERE
  1690. '.TABLE_BOOKINGS.'.booking_number = \''.$result[0]['booking_number'].'\' ';
  1691.  
  1692. $result = database_query($sql, DATA_AND_ROWS, ALL_ROWS);
  1693. ///echo $sql.'----------'.database_error();
  1694. $hotelowner_emails = array();
  1695. if($result[1] > 0){
  1696. $booking_details .= '<table style="border:1px" cellspacing="2">';
  1697. $booking_details .= '<tr align="center">';
  1698. $booking_details .= '<th>#</th>';
  1699. $booking_details .= '<th align="left">'._ROOM_TYPE.'</th>';
  1700. if($hotels_count > 1) $booking_details .= '<th align="left">'._HOTEL.'</th>';
  1701. $booking_details .= '<th>'._CHECK_IN.'</th>';
  1702. $booking_details .= '<th>'._CHECK_OUT.'</th>';
  1703. $booking_details .= '<th>'._NIGHTS.'</th>';
  1704. $booking_details .= '<th>'._ROOMS.'</th>';
  1705. $booking_details .= '<th>'._ADULT.'</th>';
  1706. $booking_details .= (($allow_children == 'yes') ? '<th>'._CHILD.'</th>' : '');
  1707. $booking_details .= (($allow_extra_beds == 'yes') ? '<th>'._EXTRA_BEDS.'</th>' : '');
  1708. $booking_details .= (($meal_plans_count) ? '<th>'._MEAL_PLANS.'</th>' : '');
  1709. $booking_details .= '<th align="right">'._PER_NIGHT.'</th>';
  1710. $booking_details .= '<th align="right">'._PRICE.'</th>';
  1711. $booking_details .= '</tr>';
  1712. for($i=0; $i < $result[1]; $i++){
  1713. $nights = nights_diff($result[0][$i]['checkin'], $result[0][$i]['checkout']);
  1714. $booking_details .= '<tr align="center">';
  1715. $booking_details .= '<td width="30px">'.($i+1).'.</td>';
  1716. $booking_details .= '<td align="left">'.$result[0][$i]['room_type'].'</td>';
  1717. if($hotels_count > 1) $booking_details .= '<td align="left">'.$result[0][$i]['hotel_name'].'</td>';
  1718. if(!empty($result[0][$i]['hotel_email'])) $hotelowner_emails[] = $result[0][$i]['hotel_email'];
  1719. $booking_details .= '<td>'.format_datetime($result[0][$i]['checkin'], $this->fieldDateFormat, '', false).'</td>';
  1720. $booking_details .= '<td>'.format_datetime($result[0][$i]['checkout'], $this->fieldDateFormat, '', false).'</td>';
  1721. $booking_details .= '<td>'.$nights.'</td>';
  1722. $booking_details .= '<td>'.$result[0][$i]['rooms'].'</td>';
  1723. $booking_details .= '<td>'.$result[0][$i]['adults'].'</td>';
  1724. $booking_details .= (($allow_children == 'yes') ? '<td>'.$result[0][$i]['children'].'</td>' : '');
  1725. $booking_details .= (($allow_extra_beds == 'yes' && !empty($result[0][$i]['extra_beds'])) ? '<td>'.$result[0][$i]['extra_beds'].' ('.Currencies::PriceFormat($result[0][$i]['extra_beds_charge'], $result[0][$i]['symbol'], '', $this->currencyFormat).')</td>' : '<td>0</td>');
  1726. $booking_details .= (($meal_plans_count) ? '<td>'.(!empty($result[0][$i]['meal_plan_name']) ? $result[0][$i]['meal_plan_name'].' (' : '').Currencies::PriceFormat($result[0][$i]['meal_plan_price'], $result[0][$i]['symbol'], '', $this->currencyFormat).')</td>' : '');
  1727. $booking_details .= '<td align="right">'.Currencies::PriceFormat(($result[0][$i]['price'] / $nights), $result[0][$i]['symbol'], '', $this->currencyFormat).'</td>';
  1728. $booking_details .= '<td align="right">'.Currencies::PriceFormat(($result[0][$i]['price'] + $result[0][$i]['meal_plan_price'] + $result[0][$i]['extra_beds_charge']), $result[0][$i]['symbol'], '', $this->currencyFormat).'</td>';
  1729. $booking_details .= '</tr>';
  1730. }
  1731. $booking_details .= '</table>';
  1732. }
  1733.  
  1734. // add info for bank transfer payments
  1735. if($payment_type == 5){
  1736. $booking_details .= '<br />';
  1737. $booking_details .= '<b>'._BANK_PAYMENT_INFO.':</b>';
  1738. $booking_details .= '<br />-----------------------------<br />';
  1739. $booking_details .= ModulesSettings::Get('booking', 'bank_transfer_info');
  1740. }
  1741.  
  1742. $send_order_copy_to_admin = ModulesSettings::Get('booking', 'send_order_copy_to_admin');
  1743. ////////////////////////////////////////////////////////////
  1744. $sender = $objSettings->GetParameter('admin_email');
  1745. ///$recipient = $result[0]['email'];
  1746.  
  1747. if($order_type == 'reserved'){
  1748. // exit if email already sent
  1749. if($email_sent == '1') return true;
  1750. $email_template = 'order_status_changed';
  1751. $admin_copy_subject = 'Customer order status has been changed (admin copy)';
  1752. $status_description = isset($arr_statuses[$status]) ? '<b>'.$arr_statuses[$status].'</b>' : _UNKNOWN;
  1753. }else if($order_type == 'completed'){
  1754. // exit if email already sent
  1755. if($email_sent == '1') return true;
  1756. $email_template = 'order_paid';
  1757. $admin_copy_subject = 'Customer order has been paid (admin copy)';
  1758. }else if($order_type == 'canceled'){
  1759. $email_template = 'order_canceled';
  1760. $admin_copy_subject = 'Customer has canceled order (admin copy)';
  1761. }else if($order_type == 'payment_error'){
  1762. $email_template = 'payment_error';
  1763. $admin_copy_subject = 'Customer order payment error (admin copy)';
  1764. }else if($order_type == 'refunded'){
  1765. $email_template = 'order_refunded';
  1766. $admin_copy_subject = 'Customer order has been refunded (admin copy)';
  1767. }else{
  1768. $email_template = 'order_placed_online';
  1769. $order_type = isset($arr_payment_types[$payment_type]) ? $arr_payment_types[$payment_type] : '';
  1770. $admin_copy_subject = 'Customer has placed "'.$order_type.'" order (admin copy)';
  1771. if(isset($arr_statuses[$status])) $status_description = _STATUS.': '.$arr_statuses[$status];
  1772. }
  1773.  
  1774. ////////////////////////////////////////////////////////////
  1775. if(!$is_admin_reservation){
  1776.  
  1777. $hotel_description = '';
  1778. if(Hotels::HotelsCount() == 1){
  1779. $hotel_info = Hotels::GetHotelFullInfo(0, $preferred_language);
  1780. $hotel_description .= $hotel_info['name'].'<br>';
  1781. $hotel_description .= $hotel_info['address'].'<br>';
  1782. $hotel_description .= _PHONE.':'.$hotel_info['phone'];
  1783. if($hotel_info['fax'] != '') $hotel_description .= ', '._FAX.':'.$hotel_info['fax'];
  1784. }
  1785.  
  1786. $arr_send_email = array('customer');
  1787. if($send_order_copy_to_admin == 'yes'){
  1788. $arr_send_email[] = 'admin_copy';
  1789. $arr_send_email[] = 'hotelowner_copy';
  1790. }
  1791.  
  1792. $copy_subject = '';
  1793. $default_lang = Languages::GetDefaultLang();
  1794. foreach($arr_send_email as $key){
  1795. if($key == 'admin_copy'){
  1796. $email_language = $default_lang;
  1797. $recipient = $sender;
  1798. $copy_subject = $admin_copy_subject;
  1799. }else if($key == 'hotelowner_copy'){
  1800. $email_language = $default_lang;
  1801. $recipient = implode(',', array_unique($hotelowner_emails));
  1802. $copy_subject = $admin_copy_subject;
  1803. }else{
  1804. $email_language = $preferred_language;
  1805. }
  1806.  
  1807. send_email(
  1808. $recipient,
  1809. $sender,
  1810. $email_template,
  1811. array(
  1812. '{FIRST NAME}' => $first_name,
  1813. '{LAST NAME}' => $last_name,
  1814. '{BOOKING NUMBER}' => $booking_number,
  1815. '{BOOKING DETAILS}' => $booking_details,
  1816. '{STATUS DESCRIPTION}' => $status_description,
  1817. '{PERSONAL INFORMATION}' => $personal_information,
  1818. '{BILLING INFORMATION}' => $billing_information,
  1819. '{BASE URL}' => APPHP_BASE,
  1820. '{HOTEL INFO}' => ((!empty($hotel_description)) ? '<br>-----<br>'.$hotel_description : ''),
  1821. ),
  1822. $email_language,
  1823. '',
  1824. $copy_subject
  1825. );
  1826. }
  1827. }
  1828. ////////////////////////////////////////////////////////////
  1829.  
  1830. if(in_array($order_type, array('completed', 'reserved')) && !$email_sent){
  1831. // exit if email already sent
  1832. $sql = 'UPDATE '.TABLE_BOOKINGS.' SET email_sent = 1 WHERE booking_number = \''.$booking_number.'\'';
  1833. database_void_query($sql);
  1834. }
  1835.  
  1836. ////////////////////////////////////////////////////////////
  1837. return $return;
  1838. }
  1839. return false;
  1840. }
  1841.  
  1842. /**
  1843. * Send cancel booking email
  1844. * @param $rid
  1845. */
  1846. public function SendCancelOrderEmail($rid)
  1847. {
  1848. $sql = 'SELECT booking_number, customer_id, is_admin_reservation FROM '.TABLE_BOOKINGS.' WHERE id = '.(int)$rid;
  1849. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  1850. if($result[1] > 0){
  1851. $booking_number = $result[0]['booking_number'];
  1852. $customer_id = $result[0]['customer_id'];
  1853. $is_admin_reservation = $result[0]['is_admin_reservation'];
  1854.  
  1855. if($is_admin_reservation){
  1856. $this->error = ''; // show empty error on email sending operation
  1857. return false;
  1858. }else if($this->SendOrderEmail($booking_number, 'canceled', $customer_id)){
  1859. return true;
  1860. }
  1861. }
  1862. $this->error = _EMAIL_SEND_ERROR;
  1863. return false;
  1864. }
  1865.  
  1866. /**
  1867. * Returns VAT percent
  1868. */
  1869. private function GetVatPercent()
  1870. {
  1871. if($this->vatIncludedInPrice == 'no'){
  1872. $sql='SELECT
  1873. cl.*,
  1874. count.name as country_name,
  1875. count.vat_value
  1876. FROM '.TABLE_CUSTOMERS.' cl
  1877. LEFT OUTER JOIN '.TABLE_COUNTRIES.' count ON cl.b_country = count.abbrv AND count.is_active = 1
  1878. WHERE cl.id = '.(int)$this->currentCustomerID;
  1879. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  1880. if($result[1] > 0){
  1881. $vat_percent = isset($result[0]['vat_value']) ? $result[0]['vat_value'] : '0';
  1882. }else{
  1883. $vat_percent = ModulesSettings::Get('booking', 'vat_value');
  1884. }
  1885. }else{
  1886. $vat_percent = '0';
  1887. }
  1888. return $vat_percent;
  1889. }
  1890.  
  1891. /**
  1892. * Generate booking number
  1893. * @param $booking_id
  1894. */
  1895. private function GenerateBookingNumber($booking_id = '0')
  1896. {
  1897. $booking_number_type = ModulesSettings::Get('booking', 'booking_number_type');
  1898. if($booking_number_type == 'sequential'){
  1899. return str_pad($booking_id, 10, '0', STR_PAD_LEFT);
  1900. }else{
  1901. return strtoupper(get_random_string(10));
  1902. }
  1903. }
  1904.  
  1905. /**
  1906. * Get VAT Percent decimal points
  1907. * @param $vat_percent
  1908. */
  1909. private function GetVatPercentDecimalPoints($vat_percent = '0')
  1910. {
  1911. return (substr($vat_percent, -1) == '0') ? 2 : 3;
  1912. }
  1913.  
  1914. /**
  1915. * Checks if the given hotel id already exists in reservation cart
  1916. * @param $hotel_id
  1917. */
  1918. public function CheckHotelIdExists($hotel_id = 0)
  1919. {
  1920. foreach($this->arrReservation as $key => $val){
  1921. if($val['hotel_id'] == $hotel_id){
  1922. return true;
  1923. }
  1924. }
  1925. return false;
  1926. }
  1927.  
  1928. /**
  1929. * Returns reservation hotel ID
  1930. * @param $hotel_id
  1931. */
  1932. public function GetReservationHotelId()
  1933. {
  1934. foreach($this->arrReservation as $key => $val){
  1935. if(isset($val['hotel_id'])){
  1936. return $val['hotel_id'];
  1937. }
  1938. }
  1939. return 0;
  1940. }
  1941.  
  1942. /**
  1943. * Load discount info
  1944. */
  1945. public function LoadDiscountInfo($from_date = '', $to_date = '')
  1946. {
  1947. $this->discountCoupon = '';
  1948. $this->discountCampaignID = '';
  1949. $this->discountPercent = '0';
  1950.  
  1951. // prepare discount info
  1952. if(isset($this->arrReservationInfo['coupon_code']) && $this->arrReservationInfo['coupon_code'] != ''){
  1953. $this->discountCampaignID = '';
  1954. $this->discountCoupon = $this->arrReservationInfo['coupon_code'];
  1955. $this->discountPercent = $this->arrReservationInfo['discount_percent'];
  1956. }else{
  1957. $campaign_info = Campaigns::GetCampaignInfo('', $from_date, $to_date, 'global');
  1958. if(!empty($campaign_info['id'])){
  1959. $allow_discount = true;
  1960. if(!empty($campaign_info['hotel_id']) && is_array($this->arrReservation)){
  1961. foreach($this->arrReservation as $key => $val){
  1962. if($val['hotel_id'] != $campaign_info['hotel_id']){
  1963. $allow_discount = false;
  1964. break;
  1965. }
  1966. }
  1967. }
  1968.  
  1969. if($allow_discount){
  1970. $this->discountCoupon = '';
  1971. $this->discountCampaignID = $campaign_info['id'];
  1972. $this->discountPercent = $campaign_info['discount_percent'];
  1973. $this->arrReservationInfo = array(
  1974. 'coupon_code' => '',
  1975. 'discount_percent' => ''
  1976. );
  1977. }else{
  1978. //echo draw_important_message('Discount can be applied only for single hotel', false);
  1979. }
  1980. }
  1981. }
  1982. }
  1983.  
  1984. /**
  1985. * Applies discount coupon number
  1986. */
  1987. public function ApplyDiscountCoupon($coupon_code = '')
  1988. {
  1989. $result = Coupons::GetCouponInfo($coupon_code);
  1990. if(count($result) > 0){
  1991.  
  1992. $allow_discount = true;
  1993. if(!empty($result['hotel_id'])){
  1994. foreach($this->arrReservation as $key => $val){
  1995. if($val['hotel_id'] != $result['hotel_id']){
  1996. $allow_discount = false;
  1997. break;
  1998. }
  1999. }
  2000. }
  2001.  
  2002. if($allow_discount){
  2003. $this->discountCampaignID = '';
  2004. $this->discountPercent = $result['discount_percent'];
  2005. $this->discountCoupon = $coupon_code;
  2006. $this->arrReservationInfo = array(
  2007. 'coupon_code' => $coupon_code,
  2008. 'discount_percent'=> $result['discount_percent']
  2009. );
  2010. return true;
  2011. }else{
  2012. $this->error = 'This discount coupon can be applied only for single hotel';
  2013. return false;
  2014. }
  2015. }else{
  2016. $this->discountCoupon = '';
  2017. $this->arrReservationInfo = array(
  2018. 'coupon_code' => '',
  2019. 'discount_percent'=> ''
  2020. );
  2021.  
  2022. $this->LoadDiscountInfo();
  2023. $this->error = _WRONG_COUPON_CODE;
  2024. return false;
  2025. }
  2026. }
  2027.  
  2028. /**
  2029. * Removes discount coupon number
  2030. */
  2031. public function RemoveDiscountCoupon($coupon_code = '')
  2032. {
  2033. if(empty($coupon_code)){
  2034. return false;
  2035. }else{
  2036. $this->discountCoupon = '';
  2037. $this->arrReservationInfo = array();
  2038. $this->LoadDiscountInfo();
  2039.  
  2040. return true;
  2041. }
  2042. }
  2043. }
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049. ^^^^^^^^^^ AKIS
  2050.  
  2051.  
  2052.  
  2053.  
  2054. <?php
  2055.  
  2056. /***
  2057. * Class Reservation
  2058. * --------------
  2059. * Description : encapsulates Booking properties
  2060. * Updated : 03.07.2014
  2061. * Written by : ApPHP
  2062. *
  2063. * PUBLIC: STATIC: PRIVATE:
  2064. * ----------- ----------- -----------
  2065. * __construct GetVatPercent
  2066. * __destruct GenerateBookingNumber
  2067. * AddToReservation GetVatPercentDecimalPoints
  2068. * RemoveReservation CheckHotelIdExists
  2069. * ShowReservationInfo GetReservationHotelId
  2070. * ShowCheckoutInfo
  2071. * EmptyCart
  2072. * GetCartItems
  2073. * GetAdultsInCart
  2074. * GetChildrenInCart
  2075. * IsCartEmpty
  2076. * PlaceBooking
  2077. * DoReservation
  2078. * SendOrderEmail
  2079. * SendCancelOrderEmail
  2080. * DrawReservation
  2081. * LoadDiscountInfo
  2082. * ApplyDiscountCoupon
  2083. * RemoveDiscountCoupon
  2084. *
  2085. **/
  2086.  
  2087. class Reservation {
  2088.  
  2089. public $arrReservation;
  2090. public $error;
  2091. public $message;
  2092.  
  2093. private $fieldDateFormat;
  2094. private $cartItems;
  2095. private $roomsCount;
  2096. private $cartTotalSum;
  2097. private $firstNightSum;
  2098. private $currentCustomerID;
  2099. private $selectedUser;
  2100. private $vatPercent;
  2101. private $discountPercent;
  2102. private $discountCampaignID;
  2103. private $discountCoupon;
  2104. private $currencyFormat;
  2105. private $lang;
  2106. private $paypal_form_type;
  2107. private $paypal_form_fields;
  2108. private $paypal_form_fields_count;
  2109. private $first_night_possible;
  2110. private $firstNightCalculationType = 'real';
  2111. private $bookingInitialFee = '0';
  2112. private $guestTax = '0';
  2113. private $vatIncludedInPrice = 'no';
  2114. private $maximumAllowedReservations = '10';
  2115. private $countMealForChildren = true;
  2116.  
  2117.  
  2118. //==========================================================================
  2119. // Class Constructor
  2120. //==========================================================================
  2121. function __construct()
  2122. {
  2123. global $objSettings;
  2124. global $objLogin;
  2125.  
  2126. if(!$objLogin->IsLoggedIn()){
  2127. $this->currentCustomerID = (int)Session::Get('current_customer_id');
  2128. $this->selectedUser = 'customer';
  2129. }else if($objLogin->IsLoggedInAsCustomer()){
  2130. $this->currentCustomerID = $objLogin->GetLoggedID();
  2131. $this->selectedUser = 'customer';
  2132. }else{
  2133. if(Session::IsExists('sel_current_customer_id') && (int)Session::Get('sel_current_customer_id') != 0){
  2134. $this->currentCustomerID = (int)Session::Get('sel_current_customer_id');
  2135. $this->selectedUser = 'customer';
  2136. }else{
  2137. $this->currentCustomerID = $objLogin->GetLoggedID();
  2138. $this->selectedUser = 'admin';
  2139. }
  2140. }
  2141.  
  2142. // prepare Booking settings
  2143. $this->firstNightCalculationType = ModulesSettings::Get('booking', 'first_night_calculating_type');
  2144. $this->bookingInitialFee = ModulesSettings::Get('booking', 'booking_initial_fee');
  2145. $this->vatIncludedInPrice = ModulesSettings::Get('booking', 'vat_included_in_price');
  2146. $this->maximumAllowedReservations = ModulesSettings::Get('booking', 'maximum_allowed_reservations');
  2147. $this->guestTax = ModulesSettings::Get('booking', 'special_tax');
  2148.  
  2149. // prepare currency info
  2150. if(Application::Get('currency_code') == ''){
  2151. $this->currencyCode = Currencies::GetDefaultCurrency();
  2152. $this->currencyRate = '1';
  2153. }else{
  2154. //$default_currency_info = Currencies::GetDefaultCurrencyInfo();
  2155. $this->currencyCode = Application::Get('currency_code');
  2156. $this->currencyRate = Application::Get('currency_rate');
  2157. }
  2158.  
  2159. // prepare VAT percent
  2160. $this->vatPercent = $this->GetVatPercent();
  2161.  
  2162. // prepare datetime format
  2163. if($objSettings->GetParameter('date_format') == 'mm/dd/yyyy'){
  2164. $this->fieldDateFormat = 'M d, Y';
  2165. }else{
  2166. $this->fieldDateFormat = 'd M, Y';
  2167. }
  2168.  
  2169. $this->lang = Application::Get('lang');
  2170. $this->arrReservation = &$_SESSION[INSTALLATION_KEY.'reservation'];
  2171. $this->arrReservationInfo = &$_SESSION[INSTALLATION_KEY.'reservation_info'];
  2172. $this->cartItems = 0;
  2173. $this->roomsCount = 0;
  2174. $this->cartTotalSum = 0;
  2175. $this->firstNightSum = 0;
  2176. $this->first_night_possible = false;
  2177. $this->paypal_form_type = 'multiple'; // single | multiple
  2178. $this->paypal_form_fields = '';
  2179. $this->currencyFormat = get_currency_format();
  2180.  
  2181. // prepare discount info
  2182. $this->LoadDiscountInfo();
  2183.  
  2184. if(count($this->arrReservation) > 0){
  2185. $this->paypal_form_fields_count = 0;
  2186. foreach($this->arrReservation as $key => $val){
  2187. $room_price_w_meal_extrabeds = ($val['price'] + $val['meal_plan_price'] + $val['extra_beds_charge']);
  2188. $this->cartItems += 1;
  2189. $this->roomsCount += $val['rooms'];
  2190. $this->cartTotalSum += ($room_price_w_meal_extrabeds * $this->currencyRate);
  2191. if($this->firstNightCalculationType == 'average'){
  2192. $this->firstNightSum += ($room_price_w_meal_extrabeds / $val['nights']);
  2193. }else{
  2194. $this->firstNightSum += Rooms::GetPriceForDate($key, $val['from_date']);
  2195. }
  2196. if($val['nights'] > 1) $this->first_night_possible = true;
  2197.  
  2198. if($this->paypal_form_type == 'multiple' && $val['rooms'] > 0){
  2199. $this->paypal_form_fields_count++;
  2200. $this->paypal_form_fields .= draw_hidden_field('item_name_'.$this->paypal_form_fields_count, _ROOM_TYPE.': '.$val['room_type'], false);
  2201. $this->paypal_form_fields .= draw_hidden_field('quantity_'.$this->paypal_form_fields_count, $val['rooms'], false);
  2202. $this->paypal_form_fields .= draw_hidden_field('amount_'.$this->paypal_form_fields_count, number_format((($val['price'] * $this->currencyRate) / $val['rooms']), '2', '.', ','), false);
  2203.  
  2204. if(!empty($val['meal_plan_price'])){
  2205. $this->paypal_form_fields_count++;
  2206. $this->paypal_form_fields .= draw_hidden_field('item_name_'.$this->paypal_form_fields_count, _MEAL_PLANS.': '.$val['meal_plan_name'], false);
  2207. $this->paypal_form_fields .= draw_hidden_field('quantity_'.$this->paypal_form_fields_count, $val['rooms'], false);
  2208. $this->paypal_form_fields .= draw_hidden_field('amount_'.$this->paypal_form_fields_count, number_format($val['meal_plan_price'], '2', '.', ','), false);
  2209. }
  2210. }
  2211. }
  2212. }
  2213. $this->cartTotalSum = number_format($this->cartTotalSum, 2, '.', '');
  2214.  
  2215. $this->message = '';
  2216. $this->error = '';
  2217.  
  2218. //echo $this->firstNightSum;
  2219. //echo '<pre>';
  2220. //print_r($this->arrReservation);
  2221. //echo '</pre>';
  2222. }
  2223.  
  2224. //==========================================================================
  2225. // Class Destructor
  2226. //==========================================================================
  2227. function __destruct()
  2228. {
  2229. // echo 'this object has been destroyed';
  2230. }
  2231.  
  2232. /**
  2233. * Add room to reservation
  2234. * @param $room_id
  2235. * @param $from_date
  2236. * @param $to_date
  2237. * @param $nights
  2238. * @param $rooms
  2239. * @param $price
  2240. * @param $adults
  2241. * @param $children
  2242. * @param $meal_plan_id
  2243. * @param $hotel_id
  2244. * @param $extra_beds
  2245. * @param $extra_bed_charge
  2246. */
  2247. public function AddToReservation($room_id, $from_date, $to_date, $nights, $rooms, $price, $adults, $children, $meal_plan_id, $hotel_id, $extra_beds, $extra_bed_charge)
  2248. {
  2249. if(!empty($room_id)){
  2250. $meal_plan_info = MealPlans::GetPlanInfo($meal_plan_id);
  2251. // specify meal multiplier
  2252. if($this->countMealForChildren == true){
  2253. $meal_multiplier = $nights * $rooms * ($adults + $children);
  2254. }else{
  2255. $meal_multiplier = $nights * $rooms * $adults;
  2256. }
  2257.  
  2258. // check "allow_separate_gateways" settings
  2259. if(ModulesSettings::Get('booking', 'allow_separate_gateways') == 'yes' && count($this->arrReservation) > 0){
  2260. if(!$this->CheckHotelIdExists($hotel_id)){
  2261. $this->error = draw_important_message(_ALERT_SAME_HOTEL_ROOMS, false);
  2262. return false;
  2263. }
  2264. }
  2265.  
  2266. if(isset($this->arrReservation[$room_id])){
  2267. // add new info for this room
  2268. $this->arrReservation[$room_id]['from_date'] = $from_date;
  2269. $this->arrReservation[$room_id]['to_date'] = $to_date;
  2270. $this->arrReservation[$room_id]['nights'] = $nights;
  2271. $this->arrReservation[$room_id]['rooms'] = $rooms;
  2272. $this->arrReservation[$room_id]['price'] = $price;
  2273. $this->arrReservation[$room_id]['adults'] = $adults;
  2274. $this->arrReservation[$room_id]['children'] = $children;
  2275. $this->arrReservation[$room_id]['hotel_id'] = (int)$hotel_id;
  2276. $this->arrReservation[$room_id]['meal_plan_id'] = (int)$meal_plan_id;
  2277. $this->arrReservation[$room_id]['meal_plan_name'] = isset($meal_plan_info['name']) ? $meal_plan_info['name'] : '';
  2278. $this->arrReservation[$room_id]['meal_plan_price'] = isset($meal_plan_info['price']) ? number_format($meal_plan_info['price'] * $meal_multiplier, 2, '.', '') : 0;
  2279. $this->arrReservation[$room_id]['room_type'] = Rooms::GetRoomInfo($room_id, 'room_type');
  2280. $this->arrReservation[$room_id]['extra_beds'] = $extra_beds;
  2281. $this->arrReservation[$room_id]['extra_beds_charge'] = number_format($extra_bed_charge * $nights * $rooms, 2, '.', '');
  2282. }else{
  2283. // just add new room
  2284. $this->arrReservation[$room_id] = array(
  2285. 'from_date' => $from_date,
  2286. 'to_date' => $to_date,
  2287. 'nights' => $nights,
  2288. 'rooms' => $rooms,
  2289. 'price' => $price,
  2290. 'adults' => $adults,
  2291. 'children' => $children,
  2292. 'hotel_id' => (int)$hotel_id,
  2293. 'meal_plan_id' => (int)$meal_plan_id,
  2294. 'meal_plan_name' => isset($meal_plan_info['name']) ? $meal_plan_info['name'] : '',
  2295. 'meal_plan_price' => isset($meal_plan_info['price']) ? number_format($meal_plan_info['price'] * $meal_multiplier, 2, '.', '') : 0,
  2296. 'room_type' => Rooms::GetRoomInfo($room_id, 'room_type'),
  2297. 'extra_beds' => $extra_beds,
  2298. 'extra_beds_charge' => number_format($extra_bed_charge * $nights * $rooms, 2, '.', '')
  2299. );
  2300. }
  2301. $this->error = draw_success_message(_ROOM_WAS_ADDED, false);
  2302. }else{
  2303. $this->error = draw_important_message(_WRONG_PARAMETER_PASSED, false);
  2304. }
  2305. }
  2306.  
  2307. /**
  2308. * Remove room from the reservation cart
  2309. * @param $room_id
  2310. */
  2311. public function RemoveReservation($room_id)
  2312. {
  2313. if((int)$room_id > 0){
  2314. if(isset($this->arrReservation[$room_id]) && $this->arrReservation[$room_id] > 0){
  2315. unset($this->arrReservation[$room_id]);
  2316. $this->error = draw_message(_ROOM_WAS_REMOVED, false);
  2317. }else{
  2318. $this->error = draw_important_message(_ROOM_NOT_FOUND, false);
  2319. }
  2320. }else{
  2321. $this->error = draw_important_message(_ROOM_NOT_FOUND, false);
  2322. }
  2323. }
  2324.  
  2325. /**
  2326. * Show Reservation Cart on the screen
  2327. */
  2328. public function ShowReservationInfo()
  2329. {
  2330. global $objLogin;
  2331.  
  2332. $class_left = Application::Get('defined_left');
  2333. $class_right = Application::Get('defined_right');
  2334. $allow_children = ModulesSettings::Get('rooms', 'allow_children');
  2335. $allow_extra_beds = ModulesSettings::Get('rooms', 'allow_extra_beds');
  2336. $meal_plans_count = MealPlans::MealPlansCount();
  2337. $total_adults = 0;
  2338. $total_children = 0;
  2339.  
  2340. if(count($this->arrReservation) > 0)
  2341. {
  2342. echo '<table class="reservation_cart" border="0" width="100%" align="center" cellspacing="0" cellpadding="5"><thead>';
  2343. echo '<tr class="header">
  2344. <th class="'.$class_left.'" width="30px">&nbsp;</th>
  2345. <th align="'.$class_left.'">'._ROOM_TYPE.'</th>
  2346. <th align="center" width="60px">'._FROM.'</th>
  2347. <th align="center" width="60px">'._TO.'</th>
  2348. <th width="40px" align="center">&nbsp;'._NIGHTS.'&nbsp;</th>
  2349. <th width="40px" align="center">&nbsp;'._ROOMS.'&nbsp;</th>
  2350. <th width="70px" colspan="3" align="center">'._OCCUPANCY.'</th>
  2351. '.(($meal_plans_count) ? '<th width="60px" align="center">'._MEAL_PLANS.'</th>' : '<th style="padding:0px;">&nbsp;</th>').'
  2352. <th width="65px" class="'.$class_right.'">'._PRICE.'</th>
  2353. </tr>';
  2354.  
  2355. echo '<tr style="font-size:10px;background-color:transparent;">
  2356. <th colspan="6"></th>
  2357. <th align="center">'._ADULT.'</th>
  2358. '.(($allow_children == 'yes') ? '<th align="center">'._CHILD.'</th>' : '<th></th>').'
  2359. '.(($allow_extra_beds == 'yes') ? '<th align="center">'._EXTRA_BED.'</th>' : '<th></th>').'
  2360. <th colspan="2"></th>
  2361. </tr>';
  2362.  
  2363. echo '</thead>
  2364. <tr><td colspan="11" nowrap height="5px"></td></tr>';
  2365.  
  2366. $order_price = 0;
  2367. $objRoom = new Rooms();
  2368. foreach($this->arrReservation as $key => $val)
  2369. {
  2370. $sql = 'SELECT
  2371. '.TABLE_ROOMS.'.id,
  2372. '.TABLE_ROOMS.'.room_type,
  2373. '.TABLE_ROOMS.'.room_icon_thumb,
  2374. '.TABLE_ROOMS.'.max_adults,
  2375. '.TABLE_ROOMS.'.max_children,
  2376. '.TABLE_ROOMS.'.default_price as price,
  2377. '.TABLE_ROOMS_DESCRIPTION.'.room_type as loc_room_type,
  2378. '.TABLE_ROOMS_DESCRIPTION.'.room_short_description as loc_room_short_description,
  2379. '.TABLE_HOTELS_DESCRIPTION.'.name as hotel_name
  2380. FROM '.TABLE_ROOMS.'
  2381. INNER JOIN '.TABLE_ROOMS_DESCRIPTION.' ON '.TABLE_ROOMS.'.id = '.TABLE_ROOMS_DESCRIPTION.'.room_id
  2382. INNER JOIN '.TABLE_HOTELS_DESCRIPTION.' ON '.TABLE_ROOMS.'.hotel_id = '.TABLE_HOTELS_DESCRIPTION.'.hotel_id
  2383. WHERE
  2384. '.TABLE_ROOMS.'.id = '.$key.' AND
  2385. '.TABLE_ROOMS_DESCRIPTION.'.language_id = \''.$this->lang.'\' AND
  2386. '.TABLE_HOTELS_DESCRIPTION.'.language_id = \''.$this->lang.'\' ';
  2387.  
  2388. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  2389. if($result[1] > 0){
  2390. $room_icon_thumb = ($result[0]['room_icon_thumb'] != '') ? $result[0]['room_icon_thumb'] : 'no_image.png';
  2391. $room_price_w_meal_extrabeds = ($val['price'] + $val['meal_plan_price'] + $val['extra_beds_charge']);
  2392.  
  2393. echo '<tr>
  2394. <td align="center"><a href="index.php?page=booking&act=remove&rid='.$key.'"><img src="images/remove.gif" width="16" height="16" border="0" title="'._REMOVE_ROOM_FROM_CART.'" alt="remove" /></a></td>
  2395. <td>
  2396. <b>'.prepare_link('rooms', 'room_id', $result[0]['id'], $result[0]['loc_room_type'], $result[0]['loc_room_type'], '', _CLICK_TO_VIEW).'</b><br />
  2397. '.$result[0]['hotel_name'].'
  2398. </td>
  2399. <td align="center">'.format_date($val['from_date'], $this->fieldDateFormat, '', true).'</td>
  2400. <td align="center">'.format_date($val['to_date'], $this->fieldDateFormat, '', true).'</td>
  2401. <td align="center">'.$val['nights'].'</td>
  2402. <td align="center">'.$val['rooms'].'</td>
  2403. <td align="center">'.$val['adults'].'</td>
  2404. '.(($allow_children == 'yes') ? '<td align="center">'.$val['children'].'</td>' : '<td></td>').'
  2405. '.(($allow_extra_beds == 'yes') ? '<td align="center">'.$val['extra_beds'].'</td>' : '<td></td>').'
  2406. '.(($meal_plans_count) ? '<td align="center" style="cursor:help;" title="'.(($val['nights'] > 1) ? _RATE_PER_NIGHT_AVG : _RATE_PER_NIGHT).'">'.$val['meal_plan_name'].'</td>' : '<td></td>').'
  2407. <td align="'.$class_right.'">'.Currencies::PriceFormat($room_price_w_meal_extrabeds * $this->currencyRate, '', '', $this->currencyFormat).'&nbsp;<a class="price_link" href="javascript:void(0);" onclick="javascript:appToggleElement(\'row_prices_'.$key.'\')" title="'._CLICK_TO_SEE_PRICES.'">(+)</a></td>
  2408. </tr>
  2409. <tr><td colspan="11" nowrap height="1px"></td></tr>
  2410. <tr><td colspan="11" align="'.$class_left.'">
  2411. <span id="row_prices_'.$key.'" style="margin:5px 10px;display:none;">
  2412. <table width="100%">
  2413. <tr>
  2414. <td width="90px"><img src="images/rooms_icons/'.$room_icon_thumb.'" alt="icon" width="80px" height="65px" /></td>
  2415. <td>
  2416. '._ROOM_PRICE.': '.Currencies::PriceFormat(($val['price'] * $this->currencyRate), '', '', $this->currencyFormat).'<br>
  2417. '._MEAL_PLANS.': '.Currencies::PriceFormat(($val['meal_plan_price'] * $this->currencyRate), '', '', $this->currencyFormat).'<br>
  2418. '._EXTRA_BEDS.': '.Currencies::PriceFormat(($val['extra_beds_charge'] * $this->currencyRate), '', '', $this->currencyFormat).'<br>
  2419. '._RATE_PER_NIGHT.': '.Currencies::PriceFormat(($room_price_w_meal_extrabeds * $this->currencyRate) / $val['nights'], '', '', $this->currencyFormat).'<br>
  2420. </td>
  2421. </tr>
  2422. <tr><td colspan="2">'.Rooms::GetRoomPricesTable($key).'</td></tr>
  2423. </table>
  2424. </span>
  2425. </td>
  2426. </tr>';
  2427. $order_price += ($room_price_w_meal_extrabeds * $this->currencyRate);
  2428. $total_adults += $val['adults'];
  2429. $total_children += ($allow_children == 'yes') ? (int)$val['children'] : 0;
  2430. }
  2431. }
  2432.  
  2433. // draw sub-total row
  2434. echo '<tr>
  2435. <td colspan="7"></td>
  2436. <td class="td '.$class_left.'" colspan="3"><b>'._SUBTOTAL.': </b></td>
  2437. <td class="td '.$class_right.'" align="'.$class_right.'"><b>'.Currencies::PriceFormat($order_price, '', '', $this->currencyFormat).'</b></td>
  2438. </tr>';
  2439.  
  2440. echo '<tr><td colspan="11" nowrap="nowrap" height="15px"></td></tr>';
  2441.  
  2442. // calculate discount
  2443. $discount_value = ($order_price * ($this->discountPercent / 100));
  2444. $order_price -= $discount_value;
  2445.  
  2446. // calculate percent
  2447. $vat_cost = (($order_price + $this->bookingInitialFee + ($this->guestTax * ($total_adults + $total_children))) * ($this->vatPercent / 100));
  2448. $cart_total = ($order_price + $this->bookingInitialFee + ($this->guestTax * $val['nights'] * $val['rooms'])) + $vat_cost;
  2449.  
  2450. if($this->discountCampaignID != '' || $this->discountCoupon != ''){
  2451. echo '<tr>
  2452. <td colspan="7"></td>
  2453. <td class="td '.$class_left.'" colspan="3"><b><span style="color:#a60000">'._DISCOUNT.': ('.Currencies::PriceFormat($this->discountPercent, '%', 'after', $this->currencyFormat).')</span></b></td>
  2454. <td class="td '.$class_right.'" align="'.$class_right.'"><b><span style="color:#a60000">- '.Currencies::PriceFormat($discount_value, '', '', $this->currencyFormat).'</span></b></td>
  2455. </tr>';
  2456. }
  2457. if(!empty($this->bookingInitialFee)){
  2458. echo '<tr>
  2459. <td colspan="7"></td>
  2460. <td class="td '.$class_left.'" colspan="3"><b>'._INITIAL_FEE.': </b></td>
  2461. <td class="td '.$class_right.'" align="'.$class_right.'"><b>'.Currencies::PriceFormat($this->bookingInitialFee, '', '', $this->currencyFormat).'</b></td>
  2462. </tr>';
  2463. }
  2464. if(!empty($this->guestTax)){
  2465. echo '<tr>
  2466. <td colspan="7"></td>
  2467. <td class="td '.$class_left.'" colspan="3"><b>'._GUEST_TAX.': </b></td>
  2468. <td class="td '.$class_right.'" align="'.$class_right.'"><b>'.Currencies::PriceFormat($this->guestTax * $val['nights'] * $val['rooms'], '', '', $this->currencyFormat).'</b></td>
  2469. </tr>';
  2470. }
  2471. if($this->vatIncludedInPrice == 'no'){
  2472. echo '<tr>
  2473. <td colspan="7"></td>
  2474. <td class="td '.$class_left.'" colspan="3"><b>'._VAT.': ('.Currencies::PriceFormat($this->vatPercent, '%', 'after', $this->currencyFormat, $this->GetVatPercentDecimalPoints($this->vatPercent)).')</b></td>
  2475. <td class="td '.$class_right.'" align="'.$class_right.'"><b>'.Currencies::PriceFormat($vat_cost, '', '', $this->currencyFormat).'</b></td>
  2476. </tr>';
  2477. }
  2478. echo '<tr><td colspan="11" nowrap height="5px"></td></tr>
  2479. <tr class="footer">
  2480. <td colspan="7"></td>
  2481. <td class="td '.$class_left.'" colspan="3"><b>'._TOTAL.':</b></td>
  2482. <td class="td '.$class_right.'" align="'.$class_right.'"><b>'.Currencies::PriceFormat($cart_total, '', '', $this->currencyFormat).'</b></td>
  2483. </tr>
  2484. <tr><td colspan="11" nowrap height="15px"></td></tr>
  2485. <tr>
  2486. <td colspan="7"></td>
  2487. <td colspan="3"></td>
  2488. <td align="'.$class_right.'">
  2489. <input type="button" class="form_button" onclick="javascript:appGoTo(\'page=booking_details\')" value="'._BOOK.'" />
  2490. </td>
  2491. </tr>
  2492. </table>';
  2493. }else{
  2494. draw_message(_RESERVATION_CART_IS_EMPTY_ALERT, true, true);
  2495. }
  2496. }
  2497.  
  2498. /**
  2499. * Show checkout info
  2500. */
  2501. public function ShowCheckoutInfo()
  2502. {
  2503. global $objLogin;
  2504.  
  2505. $class_left = Application::Get('defined_left');
  2506. $class_right = Application::Get('defined_right');
  2507.  
  2508. $default_payment_system = ModulesSettings::Get('booking', 'default_payment_system');
  2509. $pre_payment_type = ModulesSettings::Get('booking', 'pre_payment_type');
  2510. $pre_payment_type_post = isset($_POST['pre_payment_type']) ? prepare_input($_POST['pre_payment_type']) : $pre_payment_type;
  2511. $pre_payment_value = ModulesSettings::Get('booking', 'pre_payment_value');
  2512. $payment_type_poa = ModulesSettings::Get('booking', 'payment_type_poa');
  2513. $payment_type_online = ModulesSettings::Get('booking', 'payment_type_online');
  2514. $payment_type_bank_transfer = ModulesSettings::Get('booking', 'payment_type_bank_transfer');
  2515. $payment_type_paypal = ModulesSettings::Get('booking', 'payment_type_paypal');
  2516. $payment_type_2co = ModulesSettings::Get('booking', 'payment_type_2co');
  2517. $payment_type_authorize = ModulesSettings::Get('booking', 'payment_type_authorize');
  2518. $payment_type = isset($_POST['payment_type']) ? prepare_input($_POST['payment_type']) : $default_payment_system;
  2519. $submition_type = isset($_POST['submition_type']) ? prepare_input($_POST['submition_type']) : '';
  2520.  
  2521. $payment_type_poa = ($payment_type_poa == 'Frontend & Backend' || ($objLogin->IsLoggedInAsAdmin() && $payment_type_poa == 'Backend Only') || (!$objLogin->IsLoggedInAsAdmin() && $payment_type_poa == 'Frontend Only')) ? 'yes' : 'no';
  2522. $payment_type_online = ($payment_type_online == 'Frontend & Backend' || ($objLogin->IsLoggedInAsAdmin() && $payment_type_online == 'Backend Only') || (!$objLogin->IsLoggedInAsAdmin() && $payment_type_online == 'Frontend Only')) ? 'yes' : 'no';
  2523. $payment_type_bank_transfer = ($payment_type_bank_transfer == 'Frontend & Backend' || ($objLogin->IsLoggedInAsAdmin() && $payment_type_bank_transfer == 'Backend Only') || (!$objLogin->IsLoggedInAsAdmin() && $payment_type_bank_transfer == 'Frontend Only')) ? 'yes' : 'no';
  2524. $payment_type_paypal = ($payment_type_paypal == 'Frontend & Backend' || ($objLogin->IsLoggedInAsAdmin() && $payment_type_paypal == 'Backend Only') || (!$objLogin->IsLoggedInAsAdmin() && $payment_type_paypal == 'Frontend Only')) ? 'yes' : 'no';
  2525. $payment_type_2co = ($payment_type_2co == 'Frontend & Backend' || ($objLogin->IsLoggedInAsAdmin() && $payment_type_2co == 'Backend Only') || (!$objLogin->IsLoggedInAsAdmin() && $payment_type_2co == 'Frontend Only')) ? 'yes' : 'no';
  2526. $payment_type_authorize = ($payment_type_authorize == 'Frontend & Backend' || ($objLogin->IsLoggedInAsAdmin() && $payment_type_authorize == 'Backend Only') || (!$objLogin->IsLoggedInAsAdmin() && $payment_type_authorize == 'Frontend Only')) ? 'yes' : 'no';
  2527.  
  2528. $payment_type_cnt = (($payment_type_poa === 'yes')+
  2529. ($payment_type_online === 'yes')+
  2530. ($payment_type_bank_transfer === 'yes')+
  2531. ($payment_type_paypal === 'yes')+
  2532. ($payment_type_2co === 'yes')+
  2533. ($payment_type_authorize === 'yes'));
  2534. $payment_types_defined = true;
  2535. $allow_children = ModulesSettings::Get('rooms', 'allow_children');
  2536. $allow_extra_beds = ModulesSettings::Get('rooms', 'allow_extra_beds');
  2537. $meal_plans_count = MealPlans::MealPlansCount();
  2538.  
  2539. $find_user = isset($_GET['cl']) ? prepare_input($_GET['cl']) : '';
  2540. $cid = isset($_GET['cid']) ? prepare_input($_GET['cid']) : '';
  2541. if($cid != ''){
  2542. if($cid != 'admin'){
  2543. $this->currentCustomerID = $cid;
  2544. Session::Set('sel_current_customer_id', $cid);
  2545. $this->selectedUser = 'customer';
  2546. }else{
  2547. $this->currentCustomerID = $objLogin->GetLoggedID();
  2548. $this->selectedUser = 'admin';
  2549. Session::Set('sel_current_customer_id', '');
  2550. }
  2551. }
  2552.  
  2553. if($objLogin->IsLoggedInAsAdmin() && $this->selectedUser == 'admin'){
  2554. $table_name = TABLE_ACCOUNTS;
  2555. $sql='SELECT '.$table_name.'.*
  2556. FROM '.$table_name.'
  2557. WHERE '.$table_name.'.id = '.(int)$this->currentCustomerID;
  2558. }else{
  2559. $table_name = TABLE_CUSTOMERS;
  2560. $sql='SELECT
  2561. '.$table_name.'.*,
  2562. cnt.name as country_name,
  2563. cnt.vat_value,
  2564. IF(st.name IS NOT NULL, st.name, '.$table_name.'.b_state) as b_state
  2565. FROM '.$table_name.'
  2566. LEFT OUTER JOIN '.TABLE_COUNTRIES.' cnt ON '.$table_name.'.b_country = cnt.abbrv AND cnt.is_active = 1
  2567. LEFT OUTER JOIN '.TABLE_STATES.' st ON '.$table_name.'.b_state = st.abbrv AND st.country_id = cnt.id AND st.is_active = 1
  2568. WHERE '.$table_name.'.id = '.(int)$this->currentCustomerID;
  2569. }
  2570. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  2571. if($result[1] <= 0){
  2572. draw_message(_RESERVATION_CART_IS_EMPTY_ALERT, true, true);
  2573. return false;
  2574. }
  2575.  
  2576. if(count($this->arrReservation) > 0){
  2577. $extras = Extras::GetAllExtras();
  2578. echo "\n".'<script type="text/javascript">'."\n";
  2579. echo 'var arrExtras = new Array('.$extras[1].');'."\n";
  2580. echo 'var arrExtrasSelected = new Array('.$extras[1].');'."\n";
  2581. if($extras[1]){
  2582. for($i=0; $i<$extras[1]; $i++){
  2583. echo 'arrExtras['.$i.'] = "'.($extras[0][$i]['price'] * $this->currencyRate).'";'."\n";
  2584. echo 'arrExtrasSelected['.$i.'] = 0;'."\n";
  2585. }
  2586. }
  2587. echo '</script>'."\n";
  2588.  
  2589. echo '<form id="checkout-form" action="index.php?page=booking_payment" method="post">
  2590. '.draw_hidden_field('task', 'do_booking', false).'
  2591. '.draw_hidden_field('submition_type', '', false).'
  2592. '.draw_hidden_field('selected_user', $this->selectedUser, false).'
  2593. '.draw_token_field(false);
  2594.  
  2595. echo '<table class="reservation_cart" border="0" width="99%" align="center" cellspacing="0" cellpadding="5">
  2596. <tr>
  2597. <td colspan="2"><h4>'._BILLING_DETAILS.' &nbsp;';
  2598. if($objLogin->IsLoggedIn()){
  2599. if($objLogin->IsLoggedInAsCustomer()){
  2600. echo '<a style="font-size:13px;" href="javascript:void(0);" onclick="javascript:appGoTo(\'customer=my_account\')">['._EDIT_WORD.']</a> ';
  2601. }else if($objLogin->IsLoggedInAsAdmin()){
  2602.  
  2603. echo '<br>'._CHANGE_CUSTOMER.':
  2604. <input type="text" id="find_user" name="find_user" value="" size="10" maxlength="40" />
  2605. <input type="button" class="button" value="'._SEARCH.'" onclick="javascript:appGoTo(\'page=booking_checkout&cl=\'+jQuery(\'#find_user\').val())" />
  2606. <select name="sel_customer" id="sel_customer">';
  2607. if($find_user == ''){
  2608. if($this->selectedUser == 'admin'){
  2609. echo '<option value="admin">'.$result[0]['first_name'].' '.$result[0]['last_name'].' ('.$result[0]['user_name'].')</option>';
  2610. }else{
  2611. echo '<option value="'.$result[0]['id'].'">ID:'.$result[0]['id'].' '.$result[0]['first_name'].' '.$result[0]['last_name'].' ('.(($result[0]['user_name'] != '') ? $result[0]['user_name'] : _WITHOUT_ACCOUNT).')'.'</option>';
  2612. }
  2613. }else{
  2614. $objCustomers = new Customers();
  2615. $result_customers = $objCustomers->GetAllCustomers(' AND (last_name like \''.$find_user.'%\' OR first_name like \''.$find_user.'%\' OR user_name like \''.$find_user.'%\') ');
  2616. if($result_customers[1] > 0){
  2617. for($i = 0; $i < $result_customers[1]; $i++){
  2618. echo '<option value="'.$result_customers[0][$i]['id'].'">ID:'.$result_customers[0][$i]['id'].' '.$result_customers[0][$i]['first_name'].' '.$result_customers[0][$i]['last_name'].' ('.(($result_customers[0][$i]['user_name'] != '') ? $result_customers[0][$i]['user_name'] : _WITHOUT_ACCOUNT).')'.'</option>';
  2619. }
  2620. }else{
  2621. echo '<option value="admin">'.$result[0]['first_name'].' '.$result[0]['last_name'].' ('.$result[0]['user_name'].')</option>';
  2622. }
  2623. }
  2624. echo '</select> ';
  2625. if($find_user != '') echo '<input type="button" class="button" value="'._APPLY.'" onclick="javascript:appGoTo(\'page=booking_checkout&cid=\'+jQuery(\'#sel_customer\').val())"/> ';
  2626. echo '<input type="button" class="button" value="'._SET_ADMIN.'" onclick="javascript:appGoTo(\'page=booking_checkout&cid=admin\')"/>';
  2627. if($find_user != '' && $result_customers[1] == 0) echo ' '._NO_CUSTOMER_FOUND;
  2628. }
  2629. }else{
  2630. echo '<a style="font-size:13px;" href="javascript:void(0);" onclick="javascript:appGoTo(\'page=booking_details\',\'&m=edit\')">['._EDIT_WORD.']</a> ';
  2631. }
  2632. echo '</h4>
  2633. </td>
  2634. </tr>
  2635. <tr>
  2636. <td style="padding-left:10px;">
  2637. '._FIRST_NAME.': '.$result[0]['first_name'].'<br />
  2638. '._LAST_NAME.': '.$result[0]['last_name'].'<br />';
  2639. if(!$objLogin->IsLoggedInAsAdmin()){
  2640. echo _ADDRESS.': '.$result[0]['b_address'].'<br />';
  2641. //echo _ADDRESS_2.': '.$result[0]['b_address_2'].'<br />';
  2642. echo _CITY.': '.$result[0]['b_city'].'<br />';
  2643. //echo _ZIP_CODE.': '.$result[0]['b_zipcode'].'<br />';
  2644. echo _COUNTRY.': '.$result[0]['country_name'].'<br />';
  2645. //echo _STATE.': '.$result[0]['b_state'].'<br />';
  2646. }
  2647. echo '</td>
  2648. <td></td>
  2649. </tr>
  2650. </table><br />';
  2651.  
  2652. echo '<table class="reservation_cart" border="0" width="99%" align="center" cellspacing="0" cellpadding="5">
  2653. <tr><td colspan="10"><h4>'._RESERVATION_DETAILS.'</h4></td></tr>
  2654. <tr class="header">
  2655. <th class="'.$class_left.'" width="40px">&nbsp;</th>
  2656. <th align="'.$class_left.'">'._ROOM_TYPE.'</th>
  2657. <th align="center">'._FROM.'</th>
  2658. <th align="center">'._TO.'</th>
  2659. <th width="60px" align="center">'._NIGHTS.'</th>
  2660. <th width="50px" align="center">'._ROOMS.'</th>
  2661. <th width="70px" colspan="3" align="center">'._OCCUPANCY.'</th>
  2662. '.(($meal_plans_count) ? '<th width="60px" align="center">'._MEAL_PLANS.'</th>' : '<th style="padding:0px;">&nbsp;</th>').'
  2663. <th class="'.$class_right.'" width="80px" align="'.$class_right.'">'._PRICE.'</th>
  2664. </tr>
  2665. <tr><td colspan="11" nowrap="nowrap" height="5px"></td></tr>';
  2666.  
  2667. echo '<tr style="font-size:10px;background-color:transparent;">
  2668. <th colspan="6"></th>
  2669. <th align="center">'._ADULT.'</th>
  2670. '.(($allow_children == 'yes') ? '<th align="center">'._CHILD.'</th>' : '<th></th>').'
  2671. '.(($allow_extra_beds == 'yes') ? '<th align="center">'._EXTRA_BEDS.'</th>' : '<th></th>').'
  2672. <th colspan="2"></th>
  2673. </tr>';
  2674.  
  2675. $order_price = 0;
  2676. $total_adults = 0;
  2677. $total_children = 0;
  2678. foreach($this->arrReservation as $key => $val){
  2679. $sql = 'SELECT
  2680. '.TABLE_ROOMS.'.id,
  2681. '.TABLE_ROOMS.'.room_type,
  2682. '.TABLE_ROOMS.'.room_icon_thumb,
  2683. '.TABLE_ROOMS.'.max_adults,
  2684. '.TABLE_ROOMS.'.max_children,
  2685. '.TABLE_ROOMS.'.default_price as price,
  2686. '.TABLE_ROOMS_DESCRIPTION.'.room_type as loc_room_type,
  2687. '.TABLE_ROOMS_DESCRIPTION.'.room_short_description as loc_room_short_description,
  2688. '.TABLE_HOTELS_DESCRIPTION.'.name as hotel_name
  2689. FROM '.TABLE_ROOMS.'
  2690. INNER JOIN '.TABLE_ROOMS_DESCRIPTION.' ON '.TABLE_ROOMS.'.id = '.TABLE_ROOMS_DESCRIPTION.'.room_id
  2691. INNER JOIN '.TABLE_HOTELS_DESCRIPTION.' ON '.TABLE_ROOMS.'.hotel_id = '.TABLE_HOTELS_DESCRIPTION.'.hotel_id
  2692. WHERE
  2693. '.TABLE_ROOMS.'.id = '.(int)$key.' AND
  2694. '.TABLE_ROOMS_DESCRIPTION.'.language_id = \''.$this->lang.'\' AND
  2695. '.TABLE_HOTELS_DESCRIPTION.'.language_id = \''.$this->lang.'\' ';
  2696.  
  2697. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  2698. if($result[1] > 0){
  2699. $room_icon_thumb = ($result[0]['room_icon_thumb'] != '') ? $result[0]['room_icon_thumb'] : 'no_image.png';
  2700. $room_price_w_meal_extrabeds = ($val['price'] + $val['meal_plan_price'] + $val['extra_beds_charge']);
  2701. echo '<tr>
  2702. <td><img src="images/rooms_icons/'.$room_icon_thumb.'" alt="icon" width="32px" height="32px" /></td>
  2703. <td>
  2704. <b>'.prepare_link('rooms', 'room_id', $result[0]['id'], $result[0]['loc_room_type'], $result[0]['loc_room_type'], '', _CLICK_TO_VIEW).'</b><br>
  2705. '.$result[0]['hotel_name'].'
  2706. </td>
  2707. <td align="center">'.format_date($val['from_date'], $this->fieldDateFormat, '', true).'</td>
  2708. <td align="center">'.format_date($val['to_date'], $this->fieldDateFormat, '', true).'</td>
  2709. <td align="center">'.$val['nights'].'</td>
  2710. <td align="center">'.$val['rooms'].'</td>
  2711. <td align="center">'.$val['adults'].'</td>
  2712. '.(($allow_children == 'yes') ? '<td align="center">'.$val['children'].'</td>' : '<td></td>').'
  2713. '.(($allow_extra_beds == 'yes') ? '<td align="center">'.$val['extra_beds'].'</td>' : '<td></td>').'
  2714. '.(($meal_plans_count) ? '<td align="center">'.$val['meal_plan_name'].'</td>' : '<td></td>').'
  2715. <td align="'.$class_right.'">'.Currencies::PriceFormat($room_price_w_meal_extrabeds * $this->currencyRate, '', '', $this->currencyFormat).'&nbsp;</td>
  2716. </tr>
  2717. <tr><td colspan="11" nowrap height="3px"></td></tr>';
  2718. $order_price += ($room_price_w_meal_extrabeds * $this->currencyRate);
  2719. $total_adults += $val['adults'];
  2720. $total_children += ($allow_children == 'yes') ? $val['children'] : 0;
  2721. }
  2722. }
  2723.  
  2724. // draw sub-total row
  2725. echo '<tr>
  2726. <td colspan="7"></td>
  2727. <td class="td '.$class_left.'" colspan="3"><b>'._SUBTOTAL.':</b></td>
  2728. <td class="td '.$class_right.'" align="'.$class_right.'">
  2729. <b>'.Currencies::PriceFormat($order_price, '', '', $this->currencyFormat).'</b>
  2730. </td>
  2731. </tr>';
  2732.  
  2733. //echo '<tr><td colspan="10" nowrap height="5px"></td></tr>';
  2734.  
  2735. // EXTRAS
  2736. // ------------------------------------------------------------
  2737. if($extras[1]){
  2738. echo '<tr><td colspan="11" nowrap height="10px"></td></tr>';
  2739. echo '<tr><td colspan="11"><h4>'._EXTRAS.'</h4></td></tr>';
  2740. echo '<tr><td colspan="11"><table width="340px">';
  2741. for($i=0; $i<$extras[1]; $i++){
  2742. $extras_id = (($submition_type == 'apply_coupon') && isset($_POST['extras_'.$extras[0][$i]['id']])) ? $_POST['extras_'.$extras[0][$i]['id']] : 0;
  2743. echo '<tr>';
  2744. echo '<td wrap="wrap">'.$extras[0][$i]['name'].' <span class="help" title="'.$extras[0][$i]['description'].'">[?]</span></td>';
  2745. echo '<td>&nbsp;</td>';
  2746. echo '<td align="right">'.Currencies::PriceFormat($extras[0][$i]['price'] * $this->currencyRate, '', '', $this->currencyFormat).'</td>';
  2747. echo '<td>&nbsp;</td>';
  2748. echo '<td>'.draw_numbers_select_field('extras_'.$extras[0][$i]['id'], $extras_id, '0', $extras[0][$i]['maximum_count'], 1, 'extras_ddl', 'onchange="appUpdateTotalSum('.$i.',this.value,'.(int)$extras[1].')"', false).'</td>';
  2749. echo '</tr>';
  2750. }
  2751. echo '</table></td></tr>';
  2752. }
  2753.  
  2754. // calculate discount
  2755. $discount_value = ($order_price * ($this->discountPercent / 100));
  2756. $order_price -= $discount_value;
  2757.  
  2758. // calculate percent
  2759. $vat_cost = (($order_price + $this->bookingInitialFee + ($this->guestTax * $val['nights'] * $val['rooms'])) * ($this->vatPercent / 100));
  2760. $cart_total = ($order_price + $this->bookingInitialFee + ($this->guestTax * $val['nights'] * $val['rooms'])) + $vat_cost;
  2761.  
  2762. if($this->discountCampaignID != '' || $this->discountCoupon != ''){
  2763. echo '<tr>
  2764. <td colspan="7"></td>
  2765. <td class="td '.$class_left.'" colspan="3"><b><span style="color:#a60000">'._DISCOUNT.': ('.Currencies::PriceFormat($this->discountPercent, '%', 'after', $this->currencyFormat).')</span></b></td>
  2766. <td class="td '.$class_right.'" align="'.$class_right.'"><b><span style="color:#a60000">- '.Currencies::PriceFormat($discount_value, '', '', $this->currencyFormat).'</span></b></td>
  2767. </tr>';
  2768. }
  2769. if(!empty($this->bookingInitialFee)){
  2770. echo '<tr>
  2771. <td colspan="7"></td>
  2772. <td class="td '.$class_left.'" colspan="3"><b>'._INITIAL_FEE.': </b></td>
  2773. <td class="td '.$class_right.'" align="'.$class_right.'"><b>'.Currencies::PriceFormat($this->bookingInitialFee, '', '', $this->currencyFormat).'</b></td>
  2774. </tr>';
  2775. }
  2776. if(!empty($this->guestTax)){
  2777. echo '<tr>
  2778. <td colspan="7"></td>
  2779. <td class="td '.$class_left.'" colspan="3"><b>'._GUEST_TAX.': </b></td>
  2780. <td class="td '.$class_right.'" align="'.$class_right.'">
  2781. <b><label id="guest_tax" data-price="'.(float)($this->guestTax * $val['nights'] * $val['rooms']).'">'.Currencies::PriceFormat(($this->guestTax * $val['nights'] * $val['rooms']), '', '', $this->currencyFormat).'</label></b>
  2782. </td>
  2783. </tr>';
  2784. }
  2785. if($this->vatIncludedInPrice == 'no'){
  2786. echo '<tr>
  2787. <td colspan="7"></td>
  2788. <td class="td '.$class_left.'" colspan="3"><b>'._VAT.': ('.Currencies::PriceFormat($this->vatPercent, '%', 'after', $this->currencyFormat, $this->GetVatPercentDecimalPoints($this->vatPercent)).')</b></td>
  2789. <td class="td '.$class_right.'" align="'.$class_right.'">
  2790. <b><label id="reservation_vat">'.Currencies::PriceFormat($vat_cost, '', '', $this->currencyFormat).'</label></b>
  2791. </td>
  2792. </tr>';
  2793. }
  2794. echo '<tr><td colspan="11" nowrap height="5px"></td></tr>
  2795. <tr class="footer">
  2796. <td colspan="7"></td>
  2797. <td class="td '.$class_left.'" colspan="3"><b>'._TOTAL.':</b></td>
  2798. <td class="td '.$class_right.'" align="'.$class_right.'">
  2799. <b><label id="reservation_total">'.Currencies::PriceFormat($cart_total, '', '', $this->currencyFormat).'</label></b>
  2800. </td>
  2801. </tr>';
  2802.  
  2803. // PAYMENT DETAILS
  2804. // ------------------------------------------------------------
  2805. echo '<tr><td colspan="11" nowrap height="12px"></td></tr>';
  2806. echo '<tr><td colspan="11"><h4>'._PAYMENT_DETAILS.'</h4></td></tr>';
  2807. echo '<tr><td colspan="11">';
  2808. echo '<table border="0" width="100%">';
  2809. if($payment_type_cnt > 1){
  2810. echo '<tr><td width="130px" nowrap>'._PAYMENT_TYPE.': &nbsp;</td><td>
  2811. <select name="payment_type" id="payment_type">';
  2812. if($payment_type_poa == 'yes') echo '<option value="poa" '.(($payment_type == 'poa') ? 'selected="selected"' : '').'>'._PAY_ON_ARRIVAL.'</option>';
  2813. if($payment_type_online == 'yes') echo '<option value="online" '.(($payment_type == 'online') ? 'selected="selected"' : '').'>'._ONLINE_ORDER.'</option>';
  2814. if($payment_type_bank_transfer == 'yes') echo '<option value="bank.transfer" '.(($payment_type == 'bank.transfer') ? 'selected="selected"' : '').'>'._BANK_TRANSFER.'</option>';
  2815. if($payment_type_paypal == 'yes') echo '<option value="paypal" '.(($payment_type == 'paypal') ? 'selected="selected"' : '').'>'._PAYPAL.'</option>';
  2816. if($payment_type_2co == 'yes') echo '<option value="2co" '.(($payment_type == '2co') ? 'selected="selected"' : '').'>2CO</option>';
  2817. if($payment_type_authorize == 'yes') echo '<option value="authorize.net" '.(($payment_type == 'authorize.net') ? 'selected="selected"' : '').'>Authorize.Net</option>';
  2818. echo '</select>';
  2819. echo '</td></tr>';
  2820. }else if($payment_type_cnt == 1){
  2821. if($payment_type_poa == 'yes') $payment_type_hidden = 'poa';
  2822. else if($payment_type_online == 'yes') $payment_type_hidden = 'online';
  2823. else if($payment_type_bank_transfer == 'yes') $payment_type_hidden = 'bank.transfer';
  2824. else if($payment_type_paypal == 'yes') $payment_type_hidden = 'paypal';
  2825. else if($payment_type_2co == 'yes') $payment_type_hidden = '2co';
  2826. else if($payment_type_authorize == 'yes') $payment_type_hidden = 'authorize.net';
  2827. else{
  2828. $payment_type_hidden = '';
  2829. $payment_types_defined = false;
  2830. }
  2831. echo '<tr><td>'.draw_hidden_field('payment_type', $payment_type_hidden, false, 'payment_type').'</td></tr>';
  2832. }else{
  2833. $payment_types_defined = false;
  2834. echo '<tr><td colspan="2">'.draw_important_message(_NO_PAYMENT_METHODS_ALERT, false).'</td></tr>';
  2835. }
  2836. echo '<tr>';
  2837. if($pre_payment_type == 'first night' && $this->first_night_possible){
  2838. echo '<td>'._PAYMENT_METHOD.': </td>';
  2839. echo '<td>';
  2840. echo '<input type="radio" name="pre_payment_type" id="pre_payment_fully" value="full price" checked="checked /> <label for="pre_payment_fully">'._FULL_PRICE.'</label> &nbsp;&nbsp;';
  2841. echo '<input type="radio" name="pre_payment_type" id="pre_payment_partially" value="first night" /> <label for="pre_payment_partially">'._FIRST_NIGHT.'</label>';
  2842. echo draw_hidden_field('pre_payment_value', $pre_payment_value, false, 'pre_payment_full');
  2843. echo '</td>';
  2844. }else if($pre_payment_type == 'percentage' && $pre_payment_value > '0' && $pre_payment_value < '100'){
  2845. echo '<td>'._PAYMENT_METHOD.': </td>';
  2846. echo '<td>';
  2847. echo '<input type="radio" name="pre_payment_type" id="pre_payment_fully" value="full price" checked="checked" /> <label for="pre_payment_fully">'._FULL_PRICE.'</label> &nbsp;&nbsp;';
  2848. echo '<input type="radio" name="pre_payment_type" id="pre_payment_partially" value="percentage" /> <label for="pre_payment_partially">'._PRE_PAYMENT.' ('.Currencies::PriceFormat($pre_payment_value, '%', 'after', $this->currencyFormat).')</label>';
  2849. echo draw_hidden_field('pre_payment_value', $pre_payment_value, false, 'pre_payment_full');
  2850. echo '</td>';
  2851. }else if($pre_payment_type == 'fixed sum' && $pre_payment_value > '0'){
  2852. echo '<td>'._PAYMENT_METHOD.': </td>';
  2853. echo '<td>';
  2854. echo '<input type="radio" name="pre_payment_type" id="pre_payment_fully" value="full price" checked="checked" /> <label for="pre_payment_fully">'._FULL_PRICE.'</label> &nbsp;&nbsp;';
  2855. echo '<input type="radio" name="pre_payment_type" id="pre_payment_partially" value="fixed sum" /> <label for="pre_payment_partially">'._PRE_PAYMENT.' ('.Currencies::PriceFormat($pre_payment_value * $this->currencyRate, '', '', $this->currencyFormat).')</label>';
  2856. echo draw_hidden_field('pre_payment_value', $pre_payment_value, false, 'pre_payment_full');
  2857. echo '</td>';
  2858. }else{
  2859. echo '<td colspan="2">';
  2860. // full price payment
  2861. if($payment_type_cnt <= 1 && $payment_types_defined) echo _FULL_PRICE;
  2862. echo draw_hidden_field('pre_payment_type', 'full price', false, 'pre_payment_fully');
  2863. echo draw_hidden_field('pre_payment_value', '100', false, 'pre_payment_full');
  2864. echo '</td>';
  2865. }
  2866. echo '</tr>';
  2867. echo '</table></td></tr>';
  2868.  
  2869. if($payment_types_defined){
  2870. // PROMO CODES OR DISCOUNT COUPONS
  2871. // ------------------------------------------------------------
  2872. echo '<tr><td colspan="11" nowrap height="12px"></td></tr>';
  2873. echo '<tr><td colspan="11"><h4>'._PROMO_CODE_OR_COUPON.'</h4></td></tr>';
  2874. echo '<tr><td colspan="11">'._PROMO_COUPON_NOTICE.'</td></tr>';
  2875. echo '<tr>';
  2876. echo '<td colspan="11">';
  2877. if(!empty($this->discountCoupon)){
  2878. echo '<input type="text" class="discount_coupon" name="discount_coupon" id="discount_coupon" value="'.$this->discountCoupon.'" readonly="readonly" maxlength="32" autocomplete="off" />&nbsp;&nbsp;&nbsp;';
  2879. echo '<input type="button" class="button" id="discount_button" value="'._REMOVE.'" onclick="appSubmitCoupon(\'remove_coupon\')" />';
  2880. }else{
  2881. echo '<input type="text" class="discount_coupon" name="discount_coupon" id="discount_coupon" value="'.$this->discountCoupon.'" maxlength="32" autocomplete="off" />&nbsp;&nbsp;&nbsp;';
  2882. echo '<input type="button" class="button" id="discount_button" value="'._APPLY.'" onclick="appSubmitCoupon(\'apply_coupon\')" />';
  2883. }
  2884. echo '</td>';
  2885. echo '</tr>';
  2886.  
  2887. echo '<tr><td colspan="11" nowrap height="15px"></td></tr>
  2888. <tr valign="middle">
  2889. <td colspan="11" nowrap height="15px">
  2890. <h4 style="cursor:pointer;" onclick="appToggleElement(\'additional_info\')">'._ADDITIONAL_INFO.' +</h4>
  2891. <textarea name="additional_info" id="additional_info" style="display:none;width:100%;height:75px"></textarea>
  2892. </td>
  2893. </tr>
  2894. <tr><td colspan="11" nowrap height="5px"></td></tr>
  2895. <tr valign="middle">
  2896. <td colspan="8" align="'.$class_right.'"></td>
  2897. <td align="'.$class_right.'" colspan="3">
  2898. '.(($payment_types_defined) ? '<input class="button" type="submit" value="'._SUBMIT_BOOKING.'" />' : '').'
  2899. </td>
  2900. </tr>';
  2901. echo '</table>';
  2902. echo '<input type="hidden" id="hid_vat_percent" value="'.$this->vatPercent.'" />';
  2903. echo '<input type="hidden" id="hid_booking_initial_fee" value="'.$this->bookingInitialFee.'" />';
  2904. echo '<input type="hidden" id="hid_booking_guest_tax" value="'.($this->guestTax * $val['nights'] * $val['rooms']).'" />';
  2905. echo '<input type="hidden" id="hid_order_price" value="'.$order_price.'" />';
  2906. echo '<input type="hidden" id="hid_currency_symbol" value="'.Application::Get('currency_symbol').'" />';
  2907. echo '<input type="hidden" id="hid_currency_format" value="'.$this->currencyFormat.'" />';
  2908. echo '</form><br>';
  2909.  
  2910. if($submition_type == 'apply_coupon'){
  2911. echo "\n".'<script type="text/javascript">'."\n";
  2912. for($i=0; $i<$extras[1]; $i++){
  2913. $extras_id = isset($_POST['extras_'.$extras[0][$i]['id']]) ? $_POST['extras_'.$extras[0][$i]['id']] : 0;
  2914. if($extras_id > 0){
  2915. echo 'appUpdateTotalSum('.$i.','.$extras_id.','.$extras[1].')'.";\n";
  2916. }
  2917. }
  2918. echo '</script>'."\n";
  2919. }
  2920. }else{
  2921. echo '</table>';
  2922. echo '</form>';
  2923. return '';
  2924. }
  2925. }else{
  2926. draw_message(_RESERVATION_CART_IS_EMPTY_ALERT, true, true);
  2927. }
  2928. }
  2929.  
  2930. /**
  2931. * Empty Reservation Cart
  2932. */
  2933. public function EmptyCart()
  2934. {
  2935. $this->arrReservation = array();
  2936. $this->arrReservationInfo = array();
  2937. Session::Set('current_customer_id', '');
  2938. }
  2939.  
  2940. /**
  2941. * Returns amount of items in Reservation Cart
  2942. */
  2943. public function GetCartItems()
  2944. {
  2945. return $this->cartItems;
  2946. }
  2947.  
  2948. /**
  2949. * Returns total number of adults in Reservation Cart
  2950. */
  2951. public function GetAdultsInCart()
  2952. {
  2953. $adults_number = 0;
  2954.  
  2955. if(count($this->arrReservation) > 0){
  2956. foreach($this->arrReservation as $key => $val){
  2957. $adults_number += isset($val['adults']) ? (int)$val['adults'] : 0;
  2958. }
  2959. }
  2960.  
  2961. return $adults_number;
  2962. }
  2963.  
  2964. /**
  2965. * Returns total number of children in Reservation Cart
  2966. */
  2967. public function GetChildrenInCart()
  2968. {
  2969. $children_number = 0;
  2970.  
  2971. if(count($this->arrReservation) > 0){
  2972. foreach($this->arrReservation as $key => $val){
  2973. $children_number += isset($val['children']) ? (int)$val['children'] : 0;
  2974. }
  2975. }
  2976. return $children_number;
  2977. }
  2978.  
  2979. /**
  2980. * Checks if cart is empty
  2981. */
  2982. public function IsCartEmpty()
  2983. {
  2984. return ($this->cartItems > 0) ? false : true;
  2985. }
  2986.  
  2987. /**
  2988. * Draw reservation info
  2989. * @param $payment_type
  2990. * @param $additional_info
  2991. * @param $extras
  2992. * @param $pre_payment_type
  2993. * @param $pre_payment_value
  2994. * @param $draw
  2995. */
  2996. public function DrawReservation($payment_type, $additional_info, $extras = array(), $pre_payment_type = '', $pre_payment_value = '', $draw = true)
  2997. {
  2998. global $objLogin;
  2999.  
  3000. $class_left = Application::Get('defined_left');
  3001. $class_right = Application::Get('defined_right');
  3002. $output = '';
  3003.  
  3004. $cc_type = isset($_POST['cc_type']) ? prepare_input($_POST['cc_type']) : '';
  3005. $cc_holder_name = isset($_POST['cc_holder_name']) ? prepare_input($_POST['cc_holder_name']) : '';
  3006. $cc_number = isset($_POST['cc_number']) ? prepare_input($_POST['cc_number']) : '';
  3007. $cc_expires_month = isset($_POST['cc_expires_month']) ? prepare_input($_POST['cc_expires_month']) : '01';
  3008. $cc_expires_year = isset($_POST['cc_expires_year']) ? prepare_input($_POST['cc_expires_year']) : date('Y');
  3009. $cc_cvv_code = isset($_POST['cc_cvv_code']) ? prepare_input($_POST['cc_cvv_code']) : '';
  3010.  
  3011. $paypal_email = ModulesSettings::Get('booking', 'paypal_email');
  3012. $credit_card_required = ModulesSettings::Get('booking', 'online_credit_card_required');
  3013. $two_checkout_vendor = ModulesSettings::Get('booking', 'two_checkout_vendor');
  3014. $authorize_login_id = ModulesSettings::Get('booking', 'authorize_login_id');
  3015. $authorize_transaction_key = ModulesSettings::Get('booking', 'authorize_transaction_key');
  3016. $bank_transfer_info = ModulesSettings::Get('booking', 'bank_transfer_info');
  3017. $mode = ModulesSettings::Get('booking', 'mode');
  3018.  
  3019. // specify API login and key for separate hotels
  3020. if(ModulesSettings::Get('booking', 'allow_separate_gateways') == 'yes'){
  3021. $hotel_id = $this->GetReservationHotelId();
  3022. $info = HotelPaymentGateways::GetPaymentInfo($hotel_id, $payment_type);
  3023.  
  3024. if($payment_type == 'paypal'){
  3025. $paypal_email = isset($info[0]['api_login']) ? $info[0]['api_login'] : '';
  3026. }else if($payment_type == '2co'){
  3027. $two_checkout_vendor = $info[0]['api_login'];
  3028. }else if($payment_type == 'authorize.net'){
  3029. $authorize_login_id = $info[0]['api_login'];
  3030. $authorize_transaction_key = isset($info[0]['api_key']) ? $info[0]['api_key'] : '';
  3031. }else if($payment_type == 'bank.transfer'){
  3032. $bank_transfer_info = isset($info[0]['payment_info']) ? $info[0]['payment_info'] : '';
  3033. }
  3034. }
  3035.  
  3036. // prepare customers info
  3037. $sql='SELECT * FROM '.TABLE_CUSTOMERS.' WHERE id = '.(int)$this->currentCustomerID;
  3038. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  3039. $customer_info = array();
  3040. $customer_info['first_name'] = isset($result[0]['first_name']) ? $result[0]['first_name'] : '';
  3041. $customer_info['last_name'] = isset($result[0]['last_name']) ? $result[0]['last_name'] : '';
  3042. $customer_info['address1'] = isset($result[0]['b_address']) ? $result[0]['b_address'] : '';
  3043. $customer_info['address2'] = isset($result[0]['b_address2']) ? $result[0]['b_address2'] : '';
  3044. $customer_info['city'] = isset($result[0]['b_city']) ? $result[0]['b_city'] : '';
  3045. $customer_info['state'] = isset($result[0]['b_state']) ? $result[0]['b_state'] : '';
  3046. $customer_info['zip'] = isset($result[0]['b_zipcode']) ? $result[0]['b_zipcode'] : '';
  3047. $customer_info['country'] = isset($result[0]['b_country']) ? $result[0]['b_country'] : '';
  3048. $customer_info['email'] = isset($result[0]['email']) ? $result[0]['email'] : '';
  3049. $customer_info['company'] = isset($result[0]['company']) ? $result[0]['company'] : '';
  3050. $customer_info['phone'] = isset($result[0]['phone']) ? $result[0]['phone'] : '';
  3051. $customer_info['fax'] = isset($result[0]['fax']) ? $result[0]['fax'] : '';
  3052.  
  3053. if($cc_holder_name == ''){
  3054. if($objLogin->IsLoggedIn()){
  3055. $cc_holder_name = $objLogin->GetLoggedFirstName().' '.$objLogin->GetLoggedLastName();
  3056. }else{
  3057. $cc_holder_name = $customer_info['first_name'].' '.$customer_info['last_name'];
  3058. }
  3059. }
  3060.  
  3061. // check if prepared booking exists and replace it
  3062. $sql='SELECT id, booking_number
  3063. FROM '.TABLE_BOOKINGS.'
  3064. WHERE customer_id = '.(int)$this->currentCustomerID.' AND
  3065. status = 0 AND
  3066. is_admin_reservation = '.(($this->selectedUser == 'admin') ? '1' : '0').'
  3067. ORDER BY id DESC';
  3068. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  3069. if($result[1] > 0){
  3070. $booking_number = $result[0]['booking_number'];
  3071. $order_price = $this->cartTotalSum;
  3072.  
  3073. // Calculate total number of adults
  3074. $total_adults = $this->GetAdultsInCart();
  3075.  
  3076. // Calculate total number of children
  3077. $total_children = $this->GetChildrenInCart();
  3078.  
  3079. // prepare extras
  3080. $extras_text = '';
  3081. $extras_param = '';
  3082. $extras_sub_total = 0;
  3083. if(count($extras) > 0){
  3084. $extras_text_header = '<tr><td colspan="3" nowrap height="10px"></td></tr>
  3085. <tr><td colspan="3"><h4>'._EXTRAS.'</h4></td></tr>
  3086. <tr><td colspan="3">';
  3087. $extras_text_middle = '';
  3088. foreach($extras as $key => $val){
  3089. $extr = Extras::GetExtrasInfo($key);
  3090. if($val){
  3091. $extras_sub_total += ($extr['price'] * $this->currencyRate) * $val;
  3092. $extras_text_middle .= '<tr><td nowrap="nowrap">'.$extr['name'].'&nbsp;</td>';
  3093. $extras_text_middle .= '<td> : </td>';
  3094. $extras_text_middle .= '<td> '.Currencies::PriceFormat($extr['price'] * $this->currencyRate, '', '', $this->currencyFormat).' x '.$val;
  3095. $extras_text_middle .= draw_hidden_field('extras_'.$key, $val, false)."\n";
  3096. $extras_param .= draw_hidden_field('extras_'.$key, $val, false)."\n";
  3097. $extras_text_middle .= '</td></tr>';
  3098. }
  3099. }
  3100. $extras_text_footer = '<tr><td>'._EXTRAS_SUBTOTAL.' </td><td> : </td><td> <b>'.Currencies::PriceFormat($extras_sub_total, '', '', $this->currencyFormat).'</b></td></tr>';
  3101. $extras_text_footer .= '</td></tr>';
  3102.  
  3103. if($extras_sub_total >= 0){
  3104. $extras_text = $extras_text_header.$extras_text_middle.$extras_text_footer;
  3105. }
  3106. }
  3107.  
  3108. // calculate discount
  3109. $discount_value = ($order_price * ($this->discountPercent / 100));
  3110. $order_price_after_discount = $order_price - $discount_value;
  3111.  
  3112. // calculate VAT
  3113. $cart_total_wo_vat = round($order_price_after_discount + $extras_sub_total, 2);
  3114. $vat_cost = (($cart_total_wo_vat + $this->bookingInitialFee + ($this->guestTax * $val['nights'] * $val['rooms'])) * ($this->vatPercent / 100));
  3115. $cart_total = round($cart_total_wo_vat, 2) + $this->bookingInitialFee + ($this->guestTax * $val['nights'] * $val['rooms']) + $vat_cost;
  3116.  
  3117. if($pre_payment_type == 'first night'){
  3118. $is_prepayment = true;
  3119. $cart_total = ($this->firstNightSum * (1 + $this->vatPercent / 100));
  3120. $prepayment_text = _FIRST_NIGHT;
  3121. }else if(($pre_payment_type == 'percentage') && (int)$pre_payment_value > 0 && (int)$pre_payment_value < 100){
  3122. $is_prepayment = true;
  3123. $cart_total = ($cart_total * ($pre_payment_value / 100));
  3124. $prepayment_text = $pre_payment_value.'%';
  3125. }else if(($pre_payment_type == 'fixed sum') && (int)$pre_payment_value > 0){
  3126. $is_prepayment = true;
  3127. $cart_total = round($pre_payment_value * $this->currencyRate, 2);
  3128. $prepayment_text = _FIXED_SUM;
  3129. }else{
  3130. $prepayment_text = '';
  3131. $is_prepayment = false;
  3132. }
  3133.  
  3134. $pp_params = array(
  3135. 'api_login' => '',
  3136. 'transaction_key' => '',
  3137. 'payment_info' => $bank_transfer_info,
  3138.  
  3139. 'booking_number' => $booking_number,
  3140.  
  3141. 'address1' => $customer_info['address1'],
  3142. 'address2' => $customer_info['address2'],
  3143. 'city' => $customer_info['city'],
  3144. 'zip' => $customer_info['zip'],
  3145. 'country' => $customer_info['country'],
  3146. 'state' => $customer_info['state'],
  3147. 'first_name' => $customer_info['first_name'],
  3148. 'last_name' => $customer_info['last_name'],
  3149. 'email' => $customer_info['email'],
  3150. 'company' => $customer_info['company'],
  3151. 'phone' => $customer_info['phone'],
  3152. 'fax' => $customer_info['fax'],
  3153.  
  3154. 'notify' => '',
  3155. 'return' => 'index.php?page=booking_return',
  3156. //'cancel_return' => 'index.php?page=booking_cancel',
  3157. 'cancel_return' => 'index.php?page=booking',
  3158.  
  3159. 'paypal_form_type' => '',
  3160. 'paypal_form_fields' => '',
  3161. 'paypal_form_fields_count' => '',
  3162.  
  3163. 'credit_card_required' => '',
  3164. 'cc_type' => '',
  3165. 'cc_holder_name' => '',
  3166. 'cc_number' => '',
  3167. 'cc_cvv_code' => '',
  3168. 'cc_expires_month' => '',
  3169. 'cc_expires_year' => '',
  3170.  
  3171. 'currency_code' => Application::Get('currency_code'),
  3172. 'additional_info' => $additional_info,
  3173. 'discount_value' => $discount_value,
  3174. 'extras_param' => $extras_param,
  3175. 'extras_sub_total' => $extras_sub_total,
  3176. 'vat_cost' => $vat_cost,
  3177. 'cart_total' => number_format((float)$cart_total, (int)Application::Get('currency_decimals'), '.', ''),
  3178. 'is_prepayment' => $is_prepayment,
  3179. 'pre_payment_type' => $pre_payment_type,
  3180. 'pre_payment_value' => $pre_payment_value,
  3181. );
  3182.  
  3183. $fisrt_part = '<table border="0" width="97%" align="center">
  3184. <tr><td width="20%">'._BOOKING_DATE.' </td><td width="2%"> : </td><td> '.format_date(date('Y-m-d H:i:s'), $this->fieldDateFormat, '', true).'</td></tr>
  3185. <tr><td>'._ROOMS.' </td><td> : </td><td> '.(int)$this->roomsCount.'</td></tr>
  3186. <tr><td>'._BOOKING_PRICE.' </td><td width="2%"> : </td><td> '.Currencies::PriceFormat($order_price, '', '', $this->currencyFormat).'</td></tr>';
  3187. if($discount_value != ''){
  3188. $fisrt_part .= '<tr><td>'._DISCOUNT.' </td><td> : </td><td> - '.Currencies::PriceFormat($discount_value, '', '', $this->currencyFormat).' ('.Currencies::PriceFormat($this->discountPercent, '%', 'after', $this->currencyFormat).')</td></tr>';
  3189. $fisrt_part .= '<tr><td>'._BOOKING_SUBTOTAL.' </td><td> : </td><td> <b>'.Currencies::PriceFormat($order_price_after_discount, '', '', $this->currencyFormat).'</b></td></tr>';
  3190. }
  3191.  
  3192. $fisrt_part .= ((count($extras) > 0) ? $extras_text : '').'
  3193. <tr><td colspan="3" nowrap height="10px"></td></tr>
  3194. <tr><td colspan="3"><h4>'._TOTAL.'</h4></td></tr>
  3195. <tr><td>'._SUBTOTAL.' </td><td> : </td><td> '.Currencies::PriceFormat($cart_total_wo_vat, '', '', $this->currencyFormat).'</td></tr>';
  3196. if(!empty($this->bookingInitialFee)){
  3197. $fisrt_part .= '<tr><td>'._INITIAL_FEE.' </td><td> : </td><td> '.Currencies::PriceFormat($this->bookingInitialFee, '', '', $this->currencyFormat).'</td></tr>';
  3198. }
  3199. if(!empty($this->guestTax)){
  3200. $var1 = $val['nights'];
  3201. $var2 = $val['rooms'];
  3202. $fisrt_part .= '<tr><td>'._GUEST_TAX.' </td><td> : </td><td> '.Currencies::PriceFormat(($this->guestTax * $var1 * $var2), '', '', $this->currencyFormat).'</td></tr>';
  3203. }
  3204. if($this->vatIncludedInPrice == 'no'){
  3205. $fisrt_part .= '<tr><td>'._VAT.' ('.Currencies::PriceFormat($this->vatPercent, '%', 'after', $this->currencyFormat, $this->GetVatPercentDecimalPoints($this->vatPercent)).') </td><td> : </td><td> '.Currencies::PriceFormat($vat_cost, '', '', $this->currencyFormat).'</td></tr>';
  3206. }
  3207. if($is_prepayment){
  3208. $fisrt_part .= '<tr><td>'._PAYMENT_SUM.' </td><td> : </td><td> <b>'.Currencies::PriceFormat($order_price_after_discount + $extras_sub_total + $this->bookingInitialFee + ($this->guestTax * $val['nights'] * $val['rooms']) + $vat_cost, '', '', $this->currencyFormat).'</b></td></tr>';
  3209. $fisrt_part .= '<tr><td>'._PRE_PAYMENT.'</td><td> : </td> <td>'.Currencies::PriceFormat($cart_total, '', '', $this->currencyFormat).' ('.$prepayment_text.')</td></tr>';
  3210. }else{
  3211. $fisrt_part .= '<tr><td>'._PAYMENT_SUM.' </td><td> : </td><td> <b>'.Currencies::PriceFormat($order_price_after_discount + $extras_sub_total + $this->bookingInitialFee + ($this->guestTax * $val['nights'] * $val['rooms']) + $vat_cost, '', '', $this->currencyFormat).'</b></td></tr>';
  3212. ///echo '<tr><td>'._PRE_PAYMENT.'</td><td> : </td> <td>'._FULL_PRICE.'</td></tr>';
  3213. }
  3214. if($additional_info != ''){
  3215. $fisrt_part .= '<tr><td colspan="3" nowrap height="10px"></td></tr>';
  3216. $fisrt_part .= '<tr><td colspan="3"><h4>'._ADDITIONAL_INFO.'</h4>'.$additional_info.'</td></tr>';
  3217. }
  3218.  
  3219. $second_part = '</table><br />';
  3220.  
  3221. if($payment_type == 'poa'){
  3222.  
  3223. $output .= $fisrt_part;
  3224. $output .= PaymentIPN::DrawPaymentForm('poa', $pp_params, (($mode == 'TEST MODE') ? 'test' : 'real'), false);
  3225. $output .= $second_part;
  3226.  
  3227. }else if($payment_type == 'online'){
  3228.  
  3229. $output .= $fisrt_part;
  3230. $pp_params['credit_card_required'] = $credit_card_required;
  3231. $pp_params['cc_type'] = $cc_type;
  3232. $pp_params['cc_holder_name'] = $cc_holder_name;
  3233. $pp_params['cc_number'] = $cc_number;
  3234. $pp_params['cc_cvv_code'] = $cc_cvv_code;
  3235. $pp_params['cc_expires_month'] = $cc_expires_month;
  3236. $pp_params['cc_expires_year'] = $cc_expires_year;
  3237. $output .= PaymentIPN::DrawPaymentForm('online', $pp_params, (($mode == 'TEST MODE') ? 'test' : 'real'), false);
  3238. $output .= $second_part;
  3239.  
  3240. }else if($payment_type == 'paypal'){
  3241.  
  3242. $output .= $fisrt_part;
  3243. $pp_params['api_login'] = $paypal_email;
  3244. $pp_params['notify'] = 'index.php?page=booking_notify_paypal';
  3245. $pp_params['paypal_form_type'] = $this->paypal_form_type;
  3246. $pp_params['paypal_form_fields'] = $this->paypal_form_fields;
  3247. $pp_params['paypal_form_fields_count'] = $this->paypal_form_fields_count;
  3248. $output .= PaymentIPN::DrawPaymentForm('paypal', $pp_params, (($mode == 'TEST MODE') ? 'test' : 'real'), false);
  3249. $output .= $second_part;
  3250.  
  3251. }else if($payment_type == '2co'){
  3252.  
  3253. $output .= $fisrt_part;
  3254. $pp_params['api_login'] = $two_checkout_vendor;
  3255. $pp_params['notify'] = 'index.php?page=booking_notify_2co';
  3256. $output .= PaymentIPN::DrawPaymentForm('2co', $pp_params, (($mode == 'TEST MODE') ? 'test' : 'real'), false);
  3257. $output .= $second_part;
  3258.  
  3259. }else if($payment_type == 'authorize.net'){
  3260.  
  3261. $output .= $fisrt_part;
  3262. $pp_params['api_login'] = $authorize_login_id;
  3263. $pp_params['transaction_key'] = $authorize_transaction_key;
  3264. $pp_params['notify'] = 'index.php?page=booking_notify_autorize_net';
  3265. // authorize.net accepts only USD, so we need to convert the sum into USD
  3266. $pp_params['cart_total'] = number_format((($pp_params['cart_total'] * Application::Get('currency_rate'))), '2', '.', ',');
  3267. $output .= PaymentIPN::DrawPaymentForm('authorize.net', $pp_params, (($mode == 'TEST MODE') ? 'test' : 'real'), false);
  3268. $output .= $second_part;
  3269.  
  3270. }else if($payment_type == 'bank.transfer'){
  3271.  
  3272. $output .= $fisrt_part;
  3273. $output .= PaymentIPN::DrawPaymentForm('bank.transfer', $pp_params, (($mode == 'TEST MODE') ? 'test' : 'real'), false);
  3274. $output .= $second_part;
  3275. }
  3276. }else{
  3277. ///echo $sql.database_error();
  3278. $output .= draw_important_message(_ORDER_ERROR, false);
  3279. }
  3280.  
  3281. if($draw) echo $output;
  3282. else return $output;
  3283. }
  3284.  
  3285. /**
  3286. * Place booking
  3287. * @param $additional_info
  3288. * @param $cc_params
  3289. */
  3290. public function PlaceBooking($additional_info = '', $cc_params = array())
  3291. {
  3292. global $objLogin;
  3293. $additional_info = substr_by_word($additional_info, 1024);
  3294.  
  3295. if(SITE_MODE == 'demo'){
  3296. $this->message = draw_important_message(_OPERATION_BLOCKED, false);
  3297. return false;
  3298. }
  3299.  
  3300. // check if prepared booking exists
  3301. $sql = 'SELECT id, booking_number, payment_type
  3302. FROM '.TABLE_BOOKINGS.'
  3303. WHERE customer_id = '.(int)$this->currentCustomerID.' AND
  3304. is_admin_reservation = '.(($this->selectedUser == 'admin') ? '1' : '0').' AND
  3305. status = 0
  3306. ORDER BY id DESC';
  3307.  
  3308. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  3309. if($result[1] > 0){
  3310. $booking_number = $result[0]['booking_number'];
  3311. if($this->selectedUser == 'admin'){
  3312. // For admin always make status - 2 - reserved
  3313. $status = 2;
  3314. }else{
  3315. $status = ($result[0]['payment_type'] == 0) ? 1 : 2;
  3316. }
  3317. $sql = 'UPDATE '.TABLE_BOOKINGS.'
  3318. SET
  3319. status_changed = \''.date('Y-m-d H:i:s').'\',
  3320. additional_info = \''.$additional_info.'\',
  3321. cc_type = \''.$cc_params['cc_type'].'\',
  3322. cc_holder_name = \''.$cc_params['cc_holder_name'].'\',
  3323. cc_number = AES_ENCRYPT(\''.$cc_params['cc_number'].'\', \''.PASSWORDS_ENCRYPT_KEY.'\'),
  3324. cc_expires_month = \''.$cc_params['cc_expires_month'].'\',
  3325. cc_expires_year = \''.$cc_params['cc_expires_year'].'\',
  3326. cc_cvv_code = AES_ENCRYPT(\''.$cc_params['cc_cvv_code'].'\', \''.PASSWORDS_ENCRYPT_KEY.'\'),
  3327. status = \''.$status.'\'
  3328. WHERE booking_number = \''.$booking_number.'\'';
  3329. database_void_query($sql);
  3330.  
  3331. // update customer bookings/rooms amount
  3332. $sql = 'UPDATE '.TABLE_CUSTOMERS.' SET
  3333. orders_count = orders_count + 1,
  3334. rooms_count = rooms_count + '.$this->roomsCount.'
  3335. WHERE id = '.(int)$this->currentCustomerID;
  3336. database_void_query($sql);
  3337. if(!$objLogin->IsLoggedIn()){
  3338. // clear selected user ID for non-registered visitors
  3339. Session::Set('sel_current_customer_id', '');
  3340. }
  3341.  
  3342. $this->message = draw_success_message(str_replace('_BOOKING_NUMBER_', '<b>'.$booking_number.'</b>', _ORDER_PLACED_MSG), false);
  3343. if($this->SendOrderEmail($booking_number, 'placed', $this->currentCustomerID)){
  3344. $this->message .= draw_success_message(_EMAIL_SUCCESSFULLY_SENT, false);
  3345. }else{
  3346. if($objLogin->IsLoggedInAsAdmin()){
  3347. $this->message .= draw_important_message(_EMAIL_SEND_ERROR, false);
  3348. }
  3349. }
  3350. }else{
  3351. $this->message = draw_important_message(_EMAIL_SEND_ERROR, false);
  3352. }
  3353.  
  3354. if(SITE_MODE == 'development' && database_error() != '') $this->message .= '<br>'.$sql.'<br>'.database_error();
  3355.  
  3356. $this->EmptyCart();
  3357. }
  3358.  
  3359. /**
  3360. * Makes reservation
  3361. * @param $payment_type
  3362. * @param $additional_info
  3363. * @param $extras
  3364. * @param $pre_payment_type
  3365. * @param $pre_payment_value
  3366. */
  3367. public function DoReservation($payment_type = '', $additional_info = '', $extras = array(), $pre_payment_type = '', $pre_payment_value = '')
  3368. {
  3369. global $objLogin;
  3370.  
  3371. if(SITE_MODE == 'demo'){
  3372. $this->error = draw_important_message(_OPERATION_BLOCKED, false);
  3373. return false;
  3374. }
  3375.  
  3376. // check the maximum allowed room reservation per customer
  3377. if($this->selectedUser == 'customer'){
  3378. $sql = 'SELECT COUNT(*) as cnt FROM '.TABLE_BOOKINGS.' WHERE customer_id = '.(int)$this->currentCustomerID.' AND status < 3';
  3379. $result = database_query($sql, DATA_ONLY);
  3380. $cnt = isset($result[0]['cnt']) ? (int)$result[0]['cnt'] : 0;
  3381. if($cnt >= $this->maximumAllowedReservations){
  3382. $this->error = draw_important_message(_MAX_RESERVATIONS_ERROR, false);
  3383. return false;
  3384. }
  3385. }
  3386.  
  3387. $booking_placed = false;
  3388. $booking_number = '';
  3389. $additional_info = substr_by_word($additional_info, 1024);
  3390.  
  3391. $order_price = $this->cartTotalSum;
  3392.  
  3393. // calculate extras
  3394. $extras_sub_total = '0';
  3395. $extras_info = array();
  3396. foreach($extras as $key => $val){
  3397. $extr = Extras::GetExtrasInfo($key);
  3398. $extras_sub_total += ($extr['price'] * $this->currencyRate) * $val;
  3399. $extras_info[$key] = $val;
  3400. }
  3401. ///$order_price += $extras_sub_total;
  3402.  
  3403. // calculate discount
  3404. $discount_value = ($order_price * ($this->discountPercent / 100));
  3405. $order_price_after_discount = $order_price - $discount_value;
  3406.  
  3407. // Calculate total number of adults
  3408. $total_adults = $this->GetAdultsInCart();
  3409.  
  3410. // Calculate total number of children
  3411. $total_children = $this->GetChildrenInCart();
  3412.  
  3413. // calculate VAT
  3414. $cart_total_wo_vat = round($order_price_after_discount + $extras_sub_total, 2);
  3415. $vat_cost = (($cart_total_wo_vat + $this->bookingInitialFee + ($this->guestTax * $val['nights'] * $val['rooms'])) * ($this->vatPercent / 100));
  3416. $cart_total = round($cart_total_wo_vat, 2) + $this->bookingInitialFee + ($this->guestTax * $val['nights'] * $val['rooms']) + $vat_cost;
  3417.  
  3418. if($pre_payment_type == 'first night'){
  3419. $cart_total = ($this->firstNightSum * (1 + $this->vatPercent / 100));
  3420. }else if(($pre_payment_type == 'percentage') && (int)$pre_payment_value > 0 && (int)$pre_payment_value < 100){
  3421. $cart_total = ($cart_total * ($pre_payment_value / 100));
  3422. }else if(($pre_payment_type == 'fixed sum') && (int)$pre_payment_value > 0){
  3423. $cart_total = round($pre_payment_value * $this->currencyRate, 2);
  3424. }else{
  3425. // $cart_total
  3426. }
  3427.  
  3428. if($this->cartItems > 0){
  3429. // add order to database
  3430. if(in_array($payment_type, array('poa', 'online', 'paypal', '2co', 'authorize.net', 'bank.transfer'))){
  3431. if($payment_type == 'bank.transfer'){
  3432. $payed_by = '5';
  3433. $status = '0';
  3434. }else if($payment_type == 'authorize.net'){
  3435. $payed_by = '4';
  3436. $status = '0';
  3437. }else if($payment_type == '2co'){
  3438. $payed_by = '3';
  3439. $status = '0';
  3440. }else if($payment_type == 'paypal'){
  3441. $payed_by = '2';
  3442. $status = '0';
  3443. }else if($payment_type == 'online'){
  3444. $payed_by = '1';
  3445. $status = '0';
  3446. }else{
  3447. $payed_by = '0';
  3448. $status = '0';
  3449. }
  3450.  
  3451. // check if prepared booking exists and replace it
  3452. $sql = 'SELECT id, booking_number
  3453. FROM '.TABLE_BOOKINGS.'
  3454. WHERE customer_id = '.(int)$this->currentCustomerID.' AND
  3455. is_admin_reservation = '.(($this->selectedUser == 'admin') ? '1' : '0').' AND
  3456. status = 0
  3457. ORDER BY id DESC';
  3458. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  3459. if($result[1] > 0){
  3460. $booking_number = $result[0]['booking_number'];
  3461. // booking exists - replace it with new
  3462. $sql = 'DELETE FROM '.TABLE_BOOKINGS_ROOMS.' WHERE booking_number = \''.$booking_number.'\'';
  3463. if(!database_void_query($sql)){ /* echo 'error!'; */ }
  3464.  
  3465. $sql = 'UPDATE '.TABLE_BOOKINGS.' SET ';
  3466. $sql_end = ' WHERE booking_number = \''.$booking_number.'\'';
  3467. $is_new_record = false;
  3468. }else{
  3469. $sql = 'INSERT INTO '.TABLE_BOOKINGS.' SET booking_number = \'\',';
  3470. $sql_end = '';
  3471. $is_new_record = true;
  3472. }
  3473.  
  3474. $sql .= 'booking_description = \''._ROOMS_RESERVATION.'\',
  3475. order_price = '.number_format((float)$order_price, (int)Application::Get('currency_decimals'), '.', '').',
  3476. pre_payment_type = \''.$pre_payment_type.'\',
  3477. pre_payment_value = \''.(($pre_payment_type != 'full price') ? $pre_payment_value : '0').'\',
  3478. discount_campaign_id = '.(int)$this->discountCampaignID.',
  3479. discount_percent = '.$this->discountPercent.',
  3480. discount_fee = '.$discount_value.',
  3481. vat_fee = '.$vat_cost.',
  3482. vat_percent = '.$this->vatPercent.',
  3483. initial_fee = '.$this->bookingInitialFee.',
  3484. guest_tax = '.($this->guestTax * $val['nights'] * $val['rooms']).',
  3485. extras = \''.serialize($extras_info).'\',
  3486. extras_fee = \''.$extras_sub_total.'\',
  3487. payment_sum = '.number_format((float)$cart_total, (int)Application::Get('currency_decimals'), '.', '').',
  3488. additional_payment = 0,
  3489. currency = \''.$this->currencyCode.'\',
  3490. rooms_amount = '.(int)$this->roomsCount.',
  3491. customer_id = '.(int)$this->currentCustomerID.',
  3492. is_admin_reservation = '.(($this->selectedUser == 'admin') ? '1' : '0').',
  3493. transaction_number = \'\',
  3494. created_date = \''.date('Y-m-d H:i:s').'\',
  3495. payment_type = '.$payed_by.',
  3496. payment_method = 0,
  3497. coupon_code = \''.$this->discountCoupon.'\',
  3498. additional_info = \''.$additional_info.'\',
  3499. cc_type = \'\',
  3500. cc_holder_name = \'\',
  3501. cc_number = \'\',
  3502. cc_expires_month = \'\',
  3503. cc_expires_year = \'\',
  3504. cc_cvv_code = \'\',
  3505. status = '.(int)$status.',
  3506. status_description = \'\'';
  3507. $sql .= $sql_end;
  3508.  
  3509. // handle booking details
  3510. if(database_void_query($sql)){
  3511. if($is_new_record){
  3512. $insert_id = database_insert_id();
  3513. $booking_number = $this->GenerateBookingNumber($insert_id);
  3514. $sql = 'UPDATE '.TABLE_BOOKINGS.' SET booking_number = \''.$booking_number.'\' WHERE id = '.(int)$insert_id;
  3515. if(!database_void_query($sql)){
  3516. $this->error = draw_important_message(_ORDER_ERROR, false);
  3517. }
  3518. }
  3519.  
  3520. $sql = 'INSERT INTO '.TABLE_BOOKINGS_ROOMS.'
  3521. (id, booking_number, hotel_id, room_id, room_numbers, checkin, checkout, adults, children, rooms, price, extra_beds, extra_beds_charge, meal_plan_id, meal_plan_price)
  3522. VALUES ';
  3523. $items_count = 0;
  3524. foreach($this->arrReservation as $key => $val){
  3525. $sql .= ($items_count++ > 0) ? ',' : '';
  3526. $sql .= '(NULL, \''.$booking_number.'\', '.(int)$val['hotel_id'].', '.(int)$key.', \'\', \''.$val['from_date'].'\', \''.$val['to_date'].'\', \''.$val['adults'].'\', \''.$val['children'].'\', '.(int)$val['rooms'].', '.($val['price'] * $this->currencyRate).', '.(int)$val['extra_beds'].', '.($val['extra_beds_charge'] * $this->currencyRate).', '.(int)$val['meal_plan_id'].', '.($val['meal_plan_price'] * $this->currencyRate).')';
  3527. }
  3528. if(database_void_query($sql)){
  3529. $booking_placed = true;
  3530. }else{
  3531. $this->error = draw_important_message(_ORDER_ERROR, false);
  3532. }
  3533. }else{
  3534. $this->error = draw_important_message(_ORDER_ERROR, false);
  3535. }
  3536. }else{
  3537. $this->error = draw_important_message(_ORDER_ERROR, false);
  3538. }
  3539. }else{
  3540. $this->error = draw_message(_RESERVATION_CART_IS_EMPTY_ALERT, false, true);
  3541. }
  3542.  
  3543. if(SITE_MODE == 'development' && !empty($this->error)) $this->error .= '<br>'.$sql.'<br>'.database_error();
  3544.  
  3545. return $booking_placed;
  3546. }
  3547.  
  3548. /**
  3549. * Sends booking email
  3550. * @param booking_number
  3551. * @param $order_type
  3552. * @param $customer_id
  3553. */
  3554. public function SendOrderEmail($booking_number, $order_type = 'placed', $customer_id = '')
  3555. {
  3556. global $objSettings;
  3557.  
  3558. $lang = Application::Get('lang');
  3559. $return = true;
  3560. $personal_information = '';
  3561. $allow_children = ModulesSettings::Get('rooms', 'allow_children');
  3562. $allow_extra_beds = ModulesSettings::Get('rooms', 'allow_extra_beds');
  3563. $hotels_count = Hotels::HotelsCount();
  3564. $meal_plans_count = MealPlans::MealPlansCount();
  3565.  
  3566. $arr_payment_types = array(
  3567. '0'=>_PAY_ON_ARRIVAL,
  3568. '1'=>_ONLINE_ORDER,
  3569. '2'=>_PAYPAL,
  3570. '3'=>'2CO',
  3571. '4'=>'Authorize.Net',
  3572. '5'=>_BANK_TRANSFER
  3573. );
  3574.  
  3575. $arr_statuses = array(
  3576. '0'=>_PREBOOKING,
  3577. '1'=>_PENDING,
  3578. '2'=>_RESERVED,
  3579. '3'=>_COMPLETED,
  3580. '4'=>_REFUNDED,
  3581. '5'=>_PAYMENT_ERROR,
  3582. '6'=>_CANCELED,
  3583. '-1'=>_UNKNOWN
  3584. );
  3585.  
  3586. // send email to customer
  3587. $sql = 'SELECT
  3588. '.TABLE_BOOKINGS.'.id,
  3589. '.TABLE_BOOKINGS.'.booking_number,
  3590. '.TABLE_BOOKINGS.'.booking_description,
  3591. '.TABLE_BOOKINGS.'.order_price,
  3592. '.TABLE_BOOKINGS.'.discount_fee,
  3593. '.TABLE_BOOKINGS.'.discount_percent,
  3594. '.TABLE_BOOKINGS.'.coupon_code,
  3595. '.TABLE_BOOKINGS.'.vat_fee,
  3596. '.TABLE_BOOKINGS.'.vat_percent,
  3597. '.TABLE_BOOKINGS.'.initial_fee,
  3598. '.TABLE_BOOKINGS.'.guest_tax,
  3599. '.TABLE_BOOKINGS.'.extras,
  3600. '.TABLE_BOOKINGS.'.extras_fee,
  3601. '.TABLE_BOOKINGS.'.payment_sum,
  3602. '.TABLE_BOOKINGS.'.currency,
  3603. '.TABLE_BOOKINGS.'.rooms_amount,
  3604. '.TABLE_BOOKINGS.'.customer_id,
  3605. '.TABLE_BOOKINGS.'.transaction_number,
  3606. '.TABLE_BOOKINGS.'.created_date,
  3607. '.TABLE_BOOKINGS.'.payment_date,
  3608. '.TABLE_BOOKINGS.'.payment_type,
  3609. '.TABLE_BOOKINGS.'.payment_method,
  3610. '.TABLE_BOOKINGS.'.status,
  3611. '.TABLE_BOOKINGS.'.status_description,
  3612. '.TABLE_BOOKINGS.'.email_sent,
  3613. '.TABLE_BOOKINGS.'.additional_info,
  3614. '.TABLE_BOOKINGS.'.is_admin_reservation,
  3615. CASE
  3616. WHEN '.TABLE_BOOKINGS.'.payment_method = 0 THEN \''._PAYMENT_COMPANY_ACCOUNT.'\'
  3617. WHEN '.TABLE_BOOKINGS.'.payment_method = 1 THEN \''._CREDIT_CARD.'\'
  3618. WHEN '.TABLE_BOOKINGS.'.payment_method = 2 THEN \''._ECHECK.'\'
  3619. ELSE \''._UNKNOWN.'\'
  3620. END as mod_payment_method,
  3621. IF((('.TABLE_BOOKINGS.'.order_price - '.TABLE_BOOKINGS.'.discount_fee) + '.TABLE_BOOKINGS.'.initial_fee + '.TABLE_BOOKINGS.'.extras_fee + '.TABLE_BOOKINGS.'.vat_fee - ('.TABLE_BOOKINGS.'.payment_sum + '.TABLE_BOOKINGS.'.additional_payment) > 0),
  3622. (('.TABLE_BOOKINGS.'.order_price - '.TABLE_BOOKINGS.'.discount_fee) + '.TABLE_BOOKINGS.'.initial_fee + '.TABLE_BOOKINGS.'.extras_fee + '.TABLE_BOOKINGS.'.vat_fee - ('.TABLE_BOOKINGS.'.payment_sum + '.TABLE_BOOKINGS.'.additional_payment)),
  3623. 0
  3624. ) as mod_have_to_pay,
  3625. '.TABLE_CUSTOMERS.'.first_name,
  3626. '.TABLE_CUSTOMERS.'.last_name,
  3627. '.TABLE_CUSTOMERS.'.user_name as customer_name,
  3628. '.TABLE_CUSTOMERS.'.email,
  3629. '.TABLE_CUSTOMERS.'.preferred_language,
  3630. '.TABLE_CUSTOMERS.'.b_address,
  3631. '.TABLE_CUSTOMERS.'.b_address_2,
  3632. '.TABLE_CUSTOMERS.'.b_city,
  3633. '.TABLE_CUSTOMERS.'.b_zipcode,
  3634. '.TABLE_CUSTOMERS.'.phone,
  3635. '.TABLE_CUSTOMERS.'.fax,
  3636. '.TABLE_CURRENCIES.'.symbol,
  3637. '.TABLE_CURRENCIES.'.symbol_placement,
  3638. '.TABLE_CAMPAIGNS.'.campaign_name,
  3639. '.TABLE_COUNTRIES.'.name as b_country,
  3640. IF('.TABLE_STATES.'.name IS NOT NULL, '.TABLE_STATES.'.name, '.TABLE_CUSTOMERS.'.b_state) as b_state
  3641. FROM '.TABLE_BOOKINGS.'
  3642. INNER JOIN '.TABLE_CURRENCIES.' ON '.TABLE_BOOKINGS.'.currency = '.TABLE_CURRENCIES.'.code
  3643. LEFT OUTER JOIN '.TABLE_CAMPAIGNS.' ON '.TABLE_BOOKINGS.'.discount_campaign_id = '.TABLE_CAMPAIGNS.'.id
  3644. LEFT OUTER JOIN '.TABLE_CUSTOMERS.' ON '.TABLE_BOOKINGS.'.customer_id = '.TABLE_CUSTOMERS.'.id
  3645. LEFT OUTER JOIN '.TABLE_COUNTRIES.' ON '.TABLE_CUSTOMERS.'.b_country = '.TABLE_COUNTRIES.'.abbrv AND '.TABLE_COUNTRIES.'.is_active = 1
  3646. LEFT OUTER JOIN '.TABLE_STATES.' ON '.TABLE_CUSTOMERS.'.b_state = '.TABLE_STATES.'.abbrv AND '.TABLE_STATES.'.country_id = '.TABLE_COUNTRIES.'.id AND '.TABLE_STATES.'.is_active = 1
  3647. WHERE
  3648. '.TABLE_BOOKINGS.'.customer_id = '.$customer_id.' AND
  3649. '.TABLE_BOOKINGS.'.booking_number = \''.$booking_number.'\'';
  3650.  
  3651. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  3652. if($result[1] > 0){
  3653. $recipient = $result[0]['email'];
  3654. $first_name = $result[0]['first_name'];
  3655. $last_name = $result[0]['last_name'];
  3656. $email_sent = $result[0]['email_sent'];
  3657. $status = $result[0]['status'];
  3658. $status_description = $result[0]['status_description'];
  3659. $preferred_language = $result[0]['preferred_language'];
  3660. $is_admin_reservation = $result[0]['is_admin_reservation'];
  3661. $payment_type = (int)$result[0]['payment_type'];
  3662.  
  3663. if(ModulesSettings::Get('booking', 'mode') == 'TEST MODE'){
  3664. $personal_information .= '<div style="text-align:center;padding:10px;color:#a60000;border:1px dashed #a60000;width:100px">TEST MODE!</div><br />';
  3665. }
  3666.  
  3667. $personal_information .= '<b>'._PERSONAL_INFORMATION.':</b>';
  3668. $personal_information .= '<br />-----------------------------<br />';
  3669. $personal_information .= _FIRST_NAME.' : '.$result[0]['first_name'].'<br />';
  3670. $personal_information .= _LAST_NAME.' : '.$result[0]['last_name'].'<br />';
  3671. $personal_information .= _EMAIL_ADDRESS.' : '.$result[0]['email'].'<br />';
  3672.  
  3673. $billing_information = '<b>'._BILLING_DETAILS.':</b>';
  3674. $billing_information .= '<br />-----------------------------<br />';
  3675. $billing_information .= _ADDRESS.' : '.$result[0]['b_address'].' '.$result[0]['b_address_2'].'<br />';
  3676. $billing_information .= _CITY.' : '.$result[0]['b_city'].'<br />';
  3677. $billing_information .= _STATE.' : '.$result[0]['b_state'].'<br />';
  3678. $billing_information .= _COUNTRY.' : '.$result[0]['b_country'].'<br />';
  3679. $billing_information .= _ZIP_CODE.' : '.$result[0]['b_zipcode'].'<br />';
  3680. if(!empty($result[0]['phone'])) $billing_information .= _PHONE.' : '.$result[0]['phone'].'<br />';
  3681. if(!empty($result[0]['fax'])) $billing_information .= _FAX.' : '.$result[0]['fax'].'<br />';
  3682.  
  3683. $booking_details = _BOOKING_DESCRIPTION.': '.$result[0]['booking_description'].'<br />';
  3684. $booking_details .= _CREATED_DATE.': '.format_datetime($result[0]['created_date'], $this->fieldDateFormat.' H:i:s', '', true).'<br />';
  3685. $payment_date = format_datetime($result[0]['payment_date'], $this->fieldDateFormat.' H:i:s', '', true);
  3686. if(empty($payment_date)) $payment_date = _NOT_PAID_YET;
  3687. $booking_details .= _PAYMENT_DATE.': '.$payment_date.'<br />';
  3688. $booking_details .= _PAYMENT_TYPE.': '.((isset($arr_payment_types[$payment_type])) ? $arr_payment_types[$payment_type] : '').'<br />';
  3689. $booking_details .= _PAYMENT_METHOD.': '.$result[0]['mod_payment_method'].'<br />';
  3690. $booking_details .= _CURRENCY.': '.$result[0]['currency'].'<br />';
  3691. $booking_details .= _ROOMS.': '.$result[0]['rooms_amount'].'<br />';
  3692. $booking_details .= _BOOKING_PRICE.': '.Currencies::PriceFormat($result[0]['order_price'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  3693. $booking_details .= (($result[0]['campaign_name'] != '') ? _DISCOUNT.': - '.Currencies::PriceFormat($result[0]['discount_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).' ('.Currencies::PriceFormat($result[0]['discount_percent'], '%', 'after', $this->currencyFormat).' - '.$result[0]['campaign_name'].')<br />' : '');
  3694. $booking_details .= (($result[0]['coupon_code'] != '') ? _DISCOUNT.': - '.Currencies::PriceFormat($result[0]['discount_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).' ('.Currencies::PriceFormat($result[0]['discount_percent'], '%', 'after', $this->currencyFormat).' - '._COUPON_CODE.': '.$result[0]['coupon_code'].')<br />' : '');
  3695. $booking_details .= _BOOKING_SUBTOTAL.(($result[0]['campaign_name'] != '') ? ' ('._AFTER_DISCOUNT.')' : '').': '.Currencies::PriceFormat($result[0]['order_price'] - $result[0]['discount_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  3696.  
  3697. if(!empty($result[0]['extras'])) $booking_details .= _EXTRAS_SUBTOTAL.': '.Currencies::PriceFormat($result[0]['extras_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  3698.  
  3699. if(!empty($this->bookingInitialFee)) $booking_details .= _INITIAL_FEE.': '.Currencies::PriceFormat($result[0]['initial_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  3700. if(!empty($this->guestTax)) $booking_details .= _GUEST_TAX.': '.Currencies::PriceFormat($result[0]['guest_tax'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  3701. if($this->vatIncludedInPrice == 'no'){
  3702. $booking_details .= _VAT.': '.Currencies::PriceFormat($result[0]['vat_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).' ('.Currencies::PriceFormat($result[0]['vat_percent'], '%', 'after', $this->currencyFormat, $this->GetVatPercentDecimalPoints($result[0]['vat_percent'])).')<br />';
  3703. }
  3704. $booking_details .= _PAYMENT_SUM.': '.Currencies::PriceFormat($result[0]['payment_sum'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  3705. $booking_details .= _PAYMENT_REQUIRED.': '.Currencies::PriceFormat($result[0]['mod_have_to_pay'], $result[0]['symbol'], $result[0]['symbol_placement'], $this->currencyFormat).'<br />';
  3706. if($result[0]['additional_info'] != '') $booking_details .= _ADDITIONAL_INFO.': '.nl2br($result[0]['additional_info']).'<br />';
  3707. $booking_details .= '<br />';
  3708.  
  3709. // display list of extras in order
  3710. // -----------------------------------------------------------------------------
  3711. $booking_details .= Extras::GetExtrasList(unserialize($result[0]['extras']), $result[0]['currency'], 'email');
  3712.  
  3713. // display list of rooms in order
  3714. // -----------------------------------------------------------------------------
  3715. $booking_details .= '<b>'._RESERVATION_DETAILS.':</b>';
  3716. $booking_details .= '<br />-----------------------------<br />';
  3717. $sql = 'SELECT
  3718. '.TABLE_BOOKINGS_ROOMS.'.booking_number,
  3719. '.TABLE_BOOKINGS_ROOMS.'.rooms,
  3720. '.TABLE_BOOKINGS_ROOMS.'.adults,
  3721. '.TABLE_BOOKINGS_ROOMS.'.children,
  3722. '.TABLE_BOOKINGS_ROOMS.'.extra_beds,
  3723. '.TABLE_BOOKINGS_ROOMS.'.checkin,
  3724. '.TABLE_BOOKINGS_ROOMS.'.checkout,
  3725. '.TABLE_BOOKINGS_ROOMS.'.price,
  3726. '.TABLE_BOOKINGS_ROOMS.'.meal_plan_price,
  3727. '.TABLE_BOOKINGS_ROOMS.'.extra_beds_charge,
  3728. '.TABLE_BOOKINGS.'.currency,
  3729. '.TABLE_CURRENCIES.'.symbol,
  3730. '.TABLE_ROOMS_DESCRIPTION.'.room_type,
  3731. '.TABLE_HOTELS.'.email as hotel_email,
  3732. '.TABLE_HOTELS_DESCRIPTION.'.name as hotel_name,
  3733. '.TABLE_MEAL_PLANS_DESCRIPTION.'.name as meal_plan_name,
  3734. '.TABLE_HOTELS_DESCRIPTION.'.name as hotel_name
  3735. FROM '.TABLE_BOOKINGS.'
  3736. INNER JOIN '.TABLE_BOOKINGS_ROOMS.' ON '.TABLE_BOOKINGS.'.booking_number = '.TABLE_BOOKINGS_ROOMS.'.booking_number
  3737. INNER JOIN '.TABLE_ROOMS.' ON '.TABLE_BOOKINGS_ROOMS.'.room_id = '.TABLE_ROOMS.'.id
  3738. INNER JOIN '.TABLE_ROOMS_DESCRIPTION.' ON '.TABLE_ROOMS.'.id = '.TABLE_ROOMS_DESCRIPTION.'.room_id AND '.TABLE_ROOMS_DESCRIPTION.'.language_id = \''.$this->lang.'\'
  3739. LEFT OUTER JOIN '.TABLE_CURRENCIES.' ON '.TABLE_BOOKINGS.'.currency = '.TABLE_CURRENCIES.'.code
  3740. LEFT OUTER JOIN '.TABLE_CUSTOMERS.' ON '.TABLE_BOOKINGS.'.customer_id = '.TABLE_CUSTOMERS.'.id
  3741. LEFT OUTER JOIN '.TABLE_HOTELS.' ON '.TABLE_BOOKINGS_ROOMS.'.hotel_id = '.TABLE_HOTELS.'.id
  3742. LEFT OUTER JOIN '.TABLE_HOTELS_DESCRIPTION.' ON '.TABLE_BOOKINGS_ROOMS.'.hotel_id = '.TABLE_HOTELS_DESCRIPTION.'.hotel_id AND '.TABLE_HOTELS_DESCRIPTION.'.language_id = \''.$this->lang.'\'
  3743. LEFT OUTER JOIN '.TABLE_MEAL_PLANS_DESCRIPTION.' ON '.TABLE_BOOKINGS_ROOMS.'.meal_plan_id = '.TABLE_MEAL_PLANS_DESCRIPTION.'.meal_plan_id AND '.TABLE_MEAL_PLANS_DESCRIPTION.'.language_id = \''.$this->lang.'\'
  3744. WHERE
  3745. '.TABLE_BOOKINGS.'.booking_number = \''.$result[0]['booking_number'].'\' ';
  3746.  
  3747. $result = database_query($sql, DATA_AND_ROWS, ALL_ROWS);
  3748. ///echo $sql.'----------'.database_error();
  3749. $hotelowner_emails = array();
  3750. if($result[1] > 0){
  3751. $booking_details .= '<table style="border:1px" cellspacing="2">';
  3752. $booking_details .= '<tr align="center">';
  3753. $booking_details .= '<th>#</th>';
  3754. $booking_details .= '<th align="left">'._ROOM_TYPE.'</th>';
  3755. if($hotels_count > 1) $booking_details .= '<th align="left">'._HOTEL.'</th>';
  3756. $booking_details .= '<th>'._CHECK_IN.'</th>';
  3757. $booking_details .= '<th>'._CHECK_OUT.'</th>';
  3758. $booking_details .= '<th>'._NIGHTS.'</th>';
  3759. $booking_details .= '<th>'._ROOMS.'</th>';
  3760. $booking_details .= '<th>'._ADULT.'</th>';
  3761. $booking_details .= (($allow_children == 'yes') ? '<th>'._CHILD.'</th>' : '');
  3762. $booking_details .= (($allow_extra_beds == 'yes') ? '<th>'._EXTRA_BEDS.'</th>' : '');
  3763. $booking_details .= (($meal_plans_count) ? '<th>'._MEAL_PLANS.'</th>' : '');
  3764. $booking_details .= '<th align="right">'._PER_NIGHT.'</th>';
  3765. $booking_details .= '<th align="right">'._PRICE.'</th>';
  3766. $booking_details .= '</tr>';
  3767. for($i=0; $i < $result[1]; $i++){
  3768. $nights = nights_diff($result[0][$i]['checkin'], $result[0][$i]['checkout']);
  3769. $booking_details .= '<tr align="center">';
  3770. $booking_details .= '<td width="30px">'.($i+1).'.</td>';
  3771. $booking_details .= '<td align="left">'.$result[0][$i]['room_type'].'</td>';
  3772. if($hotels_count > 1) $booking_details .= '<td align="left">'.$result[0][$i]['hotel_name'].'</td>';
  3773. if(!empty($result[0][$i]['hotel_email'])) $hotelowner_emails[] = $result[0][$i]['hotel_email'];
  3774. $booking_details .= '<td>'.format_datetime($result[0][$i]['checkin'], $this->fieldDateFormat, '', false).'</td>';
  3775. $booking_details .= '<td>'.format_datetime($result[0][$i]['checkout'], $this->fieldDateFormat, '', false).'</td>';
  3776. $booking_details .= '<td>'.$nights.'</td>';
  3777. $booking_details .= '<td>'.$result[0][$i]['rooms'].'</td>';
  3778. $booking_details .= '<td>'.$result[0][$i]['adults'].'</td>';
  3779. $booking_details .= (($allow_children == 'yes') ? '<td>'.$result[0][$i]['children'].'</td>' : '');
  3780. $booking_details .= (($allow_extra_beds == 'yes' && !empty($result[0][$i]['extra_beds'])) ? '<td>'.$result[0][$i]['extra_beds'].' ('.Currencies::PriceFormat($result[0][$i]['extra_beds_charge'], $result[0][$i]['symbol'], '', $this->currencyFormat).')</td>' : '<td>0</td>');
  3781. $booking_details .= (($meal_plans_count) ? '<td>'.(!empty($result[0][$i]['meal_plan_name']) ? $result[0][$i]['meal_plan_name'].' (' : '').Currencies::PriceFormat($result[0][$i]['meal_plan_price'], $result[0][$i]['symbol'], '', $this->currencyFormat).')</td>' : '');
  3782. $booking_details .= '<td align="right">'.Currencies::PriceFormat(($result[0][$i]['price'] / $nights), $result[0][$i]['symbol'], '', $this->currencyFormat).'</td>';
  3783. $booking_details .= '<td align="right">'.Currencies::PriceFormat(($result[0][$i]['price'] + $result[0][$i]['meal_plan_price'] + $result[0][$i]['extra_beds_charge']), $result[0][$i]['symbol'], '', $this->currencyFormat).'</td>';
  3784. $booking_details .= '</tr>';
  3785. }
  3786. $booking_details .= '</table>';
  3787. }
  3788.  
  3789. // add info for bank transfer payments
  3790. if($payment_type == 5){
  3791. $booking_details .= '<br />';
  3792. $booking_details .= '<b>'._BANK_PAYMENT_INFO.':</b>';
  3793. $booking_details .= '<br />-----------------------------<br />';
  3794. $booking_details .= ModulesSettings::Get('booking', 'bank_transfer_info');
  3795. }
  3796.  
  3797. $send_order_copy_to_admin = ModulesSettings::Get('booking', 'send_order_copy_to_admin');
  3798. ////////////////////////////////////////////////////////////
  3799. $sender = $objSettings->GetParameter('admin_email');
  3800. ///$recipient = $result[0]['email'];
  3801.  
  3802. if($order_type == 'reserved'){
  3803. // exit if email already sent
  3804. if($email_sent == '1') return true;
  3805. $email_template = 'order_status_changed';
  3806. $admin_copy_subject = 'Customer order status has been changed (admin copy)';
  3807. $status_description = isset($arr_statuses[$status]) ? '<b>'.$arr_statuses[$status].'</b>' : _UNKNOWN;
  3808. }else if($order_type == 'completed'){
  3809. // exit if email already sent
  3810. if($email_sent == '1') return true;
  3811. $email_template = 'order_paid';
  3812. $admin_copy_subject = 'Customer order has been paid (admin copy)';
  3813. }else if($order_type == 'canceled'){
  3814. $email_template = 'order_canceled';
  3815. $admin_copy_subject = 'Customer has canceled order (admin copy)';
  3816. }else if($order_type == 'payment_error'){
  3817. $email_template = 'payment_error';
  3818. $admin_copy_subject = 'Customer order payment error (admin copy)';
  3819. }else if($order_type == 'refunded'){
  3820. $email_template = 'order_refunded';
  3821. $admin_copy_subject = 'Customer order has been refunded (admin copy)';
  3822. }else{
  3823. $email_template = 'order_placed_online';
  3824. $order_type = isset($arr_payment_types[$payment_type]) ? $arr_payment_types[$payment_type] : '';
  3825. $admin_copy_subject = 'Customer has placed "'.$order_type.'" order (admin copy)';
  3826. if(isset($arr_statuses[$status])) $status_description = _STATUS.': '.$arr_statuses[$status];
  3827. }
  3828.  
  3829. ////////////////////////////////////////////////////////////
  3830. if(!$is_admin_reservation){
  3831.  
  3832. $hotel_description = '';
  3833. if(Hotels::HotelsCount() == 1){
  3834. $hotel_info = Hotels::GetHotelFullInfo(0, $preferred_language);
  3835. $hotel_description .= $hotel_info['name'].'<br>';
  3836. $hotel_description .= $hotel_info['address'].'<br>';
  3837. $hotel_description .= _PHONE.':'.$hotel_info['phone'];
  3838. if($hotel_info['fax'] != '') $hotel_description .= ', '._FAX.':'.$hotel_info['fax'];
  3839. }
  3840.  
  3841. $arr_send_email = array('customer');
  3842. if($send_order_copy_to_admin == 'yes'){
  3843. $arr_send_email[] = 'admin_copy';
  3844. $arr_send_email[] = 'hotelowner_copy';
  3845. }
  3846.  
  3847. $copy_subject = '';
  3848. $default_lang = Languages::GetDefaultLang();
  3849. foreach($arr_send_email as $key){
  3850. if($key == 'admin_copy'){
  3851. $email_language = $default_lang;
  3852. $recipient = $sender;
  3853. $copy_subject = $admin_copy_subject;
  3854. }else if($key == 'hotelowner_copy'){
  3855. $email_language = $default_lang;
  3856. $recipient = implode(',', array_unique($hotelowner_emails));
  3857. $copy_subject = $admin_copy_subject;
  3858. }else{
  3859. $email_language = $preferred_language;
  3860. }
  3861.  
  3862. send_email(
  3863. $recipient,
  3864. $sender,
  3865. $email_template,
  3866. array(
  3867. '{FIRST NAME}' => $first_name,
  3868. '{LAST NAME}' => $last_name,
  3869. '{BOOKING NUMBER}' => $booking_number,
  3870. '{BOOKING DETAILS}' => $booking_details,
  3871. '{STATUS DESCRIPTION}' => $status_description,
  3872. '{PERSONAL INFORMATION}' => $personal_information,
  3873. '{BILLING INFORMATION}' => $billing_information,
  3874. '{BASE URL}' => APPHP_BASE,
  3875. '{HOTEL INFO}' => ((!empty($hotel_description)) ? '<br>-----<br>'.$hotel_description : ''),
  3876. ),
  3877. $email_language,
  3878. '',
  3879. $copy_subject
  3880. );
  3881. }
  3882. }
  3883. ////////////////////////////////////////////////////////////
  3884.  
  3885. if(in_array($order_type, array('completed', 'reserved')) && !$email_sent){
  3886. // exit if email already sent
  3887. $sql = 'UPDATE '.TABLE_BOOKINGS.' SET email_sent = 1 WHERE booking_number = \''.$booking_number.'\'';
  3888. database_void_query($sql);
  3889. }
  3890.  
  3891. ////////////////////////////////////////////////////////////
  3892. return $return;
  3893. }
  3894. return false;
  3895. }
  3896.  
  3897. /**
  3898. * Send cancel booking email
  3899. * @param $rid
  3900. */
  3901. public function SendCancelOrderEmail($rid)
  3902. {
  3903. $sql = 'SELECT booking_number, customer_id, is_admin_reservation FROM '.TABLE_BOOKINGS.' WHERE id = '.(int)$rid;
  3904. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  3905. if($result[1] > 0){
  3906. $booking_number = $result[0]['booking_number'];
  3907. $customer_id = $result[0]['customer_id'];
  3908. $is_admin_reservation = $result[0]['is_admin_reservation'];
  3909.  
  3910. if($is_admin_reservation){
  3911. $this->error = ''; // show empty error on email sending operation
  3912. return false;
  3913. }else if($this->SendOrderEmail($booking_number, 'canceled', $customer_id)){
  3914. return true;
  3915. }
  3916. }
  3917. $this->error = _EMAIL_SEND_ERROR;
  3918. return false;
  3919. }
  3920.  
  3921. /**
  3922. * Returns VAT percent
  3923. */
  3924. private function GetVatPercent()
  3925. {
  3926. if($this->vatIncludedInPrice == 'no'){
  3927. $sql='SELECT
  3928. cl.*,
  3929. count.name as country_name,
  3930. count.vat_value
  3931. FROM '.TABLE_CUSTOMERS.' cl
  3932. LEFT OUTER JOIN '.TABLE_COUNTRIES.' count ON cl.b_country = count.abbrv AND count.is_active = 1
  3933. WHERE cl.id = '.(int)$this->currentCustomerID;
  3934. $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
  3935. if($result[1] > 0){
  3936. $vat_percent = isset($result[0]['vat_value']) ? $result[0]['vat_value'] : '0';
  3937. }else{
  3938. $vat_percent = ModulesSettings::Get('booking', 'vat_value');
  3939. }
  3940. }else{
  3941. $vat_percent = '0';
  3942. }
  3943. return $vat_percent;
  3944. }
  3945.  
  3946. /**
  3947. * Generate booking number
  3948. * @param $booking_id
  3949. */
  3950. private function GenerateBookingNumber($booking_id = '0')
  3951. {
  3952. $booking_number_type = ModulesSettings::Get('booking', 'booking_number_type');
  3953. if($booking_number_type == 'sequential'){
  3954. return str_pad($booking_id, 10, '0', STR_PAD_LEFT);
  3955. }else{
  3956. return strtoupper(get_random_string(10));
  3957. }
  3958. }
  3959.  
  3960. /**
  3961. * Get VAT Percent decimal points
  3962. * @param $vat_percent
  3963. */
  3964. private function GetVatPercentDecimalPoints($vat_percent = '0')
  3965. {
  3966. return (substr($vat_percent, -1) == '0') ? 2 : 3;
  3967. }
  3968.  
  3969. /**
  3970. * Checks if the given hotel id already exists in reservation cart
  3971. * @param $hotel_id
  3972. */
  3973. public function CheckHotelIdExists($hotel_id = 0)
  3974. {
  3975. foreach($this->arrReservation as $key => $val){
  3976. if($val['hotel_id'] == $hotel_id){
  3977. return true;
  3978. }
  3979. }
  3980. return false;
  3981. }
  3982.  
  3983. /**
  3984. * Returns reservation hotel ID
  3985. * @param $hotel_id
  3986. */
  3987. public function GetReservationHotelId()
  3988. {
  3989. foreach($this->arrReservation as $key => $val){
  3990. if(isset($val['hotel_id'])){
  3991. return $val['hotel_id'];
  3992. }
  3993. }
  3994. return 0;
  3995. }
  3996.  
  3997. /**
  3998. * Load discount info
  3999. */
  4000. public function LoadDiscountInfo($from_date = '', $to_date = '')
  4001. {
  4002. $this->discountCoupon = '';
  4003. $this->discountCampaignID = '';
  4004. $this->discountPercent = '0';
  4005.  
  4006. // prepare discount info
  4007. if(isset($this->arrReservationInfo['coupon_code']) && $this->arrReservationInfo['coupon_code'] != ''){
  4008. $this->discountCampaignID = '';
  4009. $this->discountCoupon = $this->arrReservationInfo['coupon_code'];
  4010. $this->discountPercent = $this->arrReservationInfo['discount_percent'];
  4011. }else{
  4012. $campaign_info = Campaigns::GetCampaignInfo('', $from_date, $to_date, 'global');
  4013. if(!empty($campaign_info['id'])){
  4014. $allow_discount = true;
  4015. if(!empty($campaign_info['hotel_id']) && is_array($this->arrReservation)){
  4016. foreach($this->arrReservation as $key => $val){
  4017. if($val['hotel_id'] != $campaign_info['hotel_id']){
  4018. $allow_discount = false;
  4019. break;
  4020. }
  4021. }
  4022. }
  4023.  
  4024. if($allow_discount){
  4025. $this->discountCoupon = '';
  4026. $this->discountCampaignID = $campaign_info['id'];
  4027. $this->discountPercent = $campaign_info['discount_percent'];
  4028. $this->arrReservationInfo = array(
  4029. 'coupon_code' => '',
  4030. 'discount_percent' => ''
  4031. );
  4032. }else{
  4033. //echo draw_important_message('Discount can be applied only for single hotel', false);
  4034. }
  4035. }
  4036. }
  4037. }
  4038.  
  4039. /**
  4040. * Applies discount coupon number
  4041. */
  4042. public function ApplyDiscountCoupon($coupon_code = '')
  4043. {
  4044. $result = Coupons::GetCouponInfo($coupon_code);
  4045. if(count($result) > 0){
  4046.  
  4047. $allow_discount = true;
  4048. if(!empty($result['hotel_id'])){
  4049. foreach($this->arrReservation as $key => $val){
  4050. if($val['hotel_id'] != $result['hotel_id']){
  4051. $allow_discount = false;
  4052. break;
  4053. }
  4054. }
  4055. }
  4056.  
  4057. if($allow_discount){
  4058. $this->discountCampaignID = '';
  4059. $this->discountPercent = $result['discount_percent'];
  4060. $this->discountCoupon = $coupon_code;
  4061. $this->arrReservationInfo = array(
  4062. 'coupon_code' => $coupon_code,
  4063. 'discount_percent'=> $result['discount_percent']
  4064. );
  4065. return true;
  4066. }else{
  4067. $this->error = 'This discount coupon can be applied only for single hotel';
  4068. return false;
  4069. }
  4070. }else{
  4071. $this->discountCoupon = '';
  4072. $this->arrReservationInfo = array(
  4073. 'coupon_code' => '',
  4074. 'discount_percent'=> ''
  4075. );
  4076.  
  4077. $this->LoadDiscountInfo();
  4078. $this->error = _WRONG_COUPON_CODE;
  4079. return false;
  4080. }
  4081. }
  4082.  
  4083. /**
  4084. * Removes discount coupon number
  4085. */
  4086. public function RemoveDiscountCoupon($coupon_code = '')
  4087. {
  4088. if(empty($coupon_code)){
  4089. return false;
  4090. }else{
  4091. $this->discountCoupon = '';
  4092. $this->arrReservationInfo = array();
  4093. $this->LoadDiscountInfo();
  4094.  
  4095. return true;
  4096. }
  4097. }
  4098. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement