diff --git a/admin/themes/default/template/controllers/orders/form.tpl b/admin/themes/default/template/controllers/orders/form.tpl index 933d0a6cc..66ab9c223 100644 --- a/admin/themes/default/template/controllers/orders/form.tpl +++ b/admin/themes/default/template/controllers/orders/form.tpl @@ -139,6 +139,7 @@ $('body').on('click', '.delete_hotel_cart_data', function(){ if (confirm("{l s='Are you sure?'}")) { + var idCart = $(this).data('id_cart'); $.ajax({ type:"POST", url: "{$link->getAdminLink('AdminOrders')|addslashes}", @@ -147,7 +148,7 @@ action: "deleteRoomProcess", del_id: $(this).data('id'), id_product: $(this).data('id_product'), - id_cart: $(this).data('id_cart'), + id_cart: idCart, id_room: $(this).data('id_room'), date_from: $(this).data('date_from'), date_to: $(this).data('date_to'), @@ -159,7 +160,7 @@ { showSuccessMessage("{l s='Remove successful'}"); if (data.cart_rooms) - location.reload(); + window.location.href = "{$link->getAdminLink('AdminOrders',true)}" + '&addorder&cart_id=' + idCart; else window.location.href = "{$link->getAdminLink('AdminHotelRoomsBooking',true)}"; } @@ -1731,539 +1732,540 @@
{block name="leadin"}{/block}
{include file='controllers/orders/_current_cart_details_data.tpl'} -
-
- - {l s='Customer'} -
-
- -
-
-
-
- - - - -
-
- -
-
-
-
-
-
- {*
- + {* If cart has errors the do not allow to proceed with this cart *} +
+
+ + {l s='Customer'} +
+
+ +
+
+
+
+ + + + +
+
+ +
+
+
+
+
+
+ {*
+ - -
-
- - - - - - - - - - - -
{l s='ID'}{l s='Date'}{l s='Total'}
-
-
- - - - - - - - - - - - - - -
{l s='ID'}{l s='Date'}{l s='Products'}{l s='Total paid'}{l s='Payment'}{l s='Status'}
-
-
-
-->*} -
+ +
+
+ + + + + + + + + + + +
{l s='ID'}{l s='Date'}{l s='Total'}
+
+
+ + + + + + + + + + + + + + +
{l s='ID'}{l s='Date'}{l s='Products'}{l s='Total paid'}{l s='Payment'}{l s='Status'}
+
+
+
-->*} +
- + {strip} {addJsDef max_child_age=$max_child_age} {addJsDef max_child_in_room=$max_child_in_room} diff --git a/admin/themes/default/template/helpers/list/list_header.tpl b/admin/themes/default/template/helpers/list/list_header.tpl index bf7678e4f..d8e313a11 100644 --- a/admin/themes/default/template/helpers/list/list_header.tpl +++ b/admin/themes/default/template/helpers/list/list_header.tpl @@ -553,10 +553,11 @@ diff --git a/classes/Cart.php b/classes/Cart.php index 7500dd21e..6bd68b361 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -374,7 +374,7 @@ class CartCore extends ObjectModel if ($cart_vat_amount == 0 || $cart_amount_te == 0) { return 0; } else { - return Tools::ps_round($cart_vat_amount / $cart_amount_te, 3); + return Tools::ps_round($cart_vat_amount / $cart_amount_te, 6); } } diff --git a/classes/order/Order.php b/classes/order/Order.php index a4e7a5e6b..53aa3fff1 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -797,8 +797,9 @@ class OrderCore extends ObjectModel public function getTaxesAverageUsed() { - // @todo should use order table to get tax average - return Cart::getTaxesAverageUsed((int)$this->id_cart); + $cart = new Cart((int) $this->id_cart); + + return $cart->getAverageProductsTaxRate() * 100; } /** diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 108b51a75..3f3798675 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -42,11 +42,11 @@ class AdminCartsControllerCore extends AdminController $this->allow_export = true; $this->_orderWay = 'DESC'; $this->context = Context::getContext(); - $this->_select = 'CONCAT(c.`firstname`, \' \', c.`lastname`) `customer`, a.id_cart total, TIME_TO_SEC(TIMEDIFF(\''.pSQL(date('Y-m-d H:i:00', time())).'\', a.`date_add`)) AS `time_diff`, + IFNULL(GROUP_CONCAT(DISTINCT o.`id_order`), 0) AS `ids_order`, - IF (IFNULL(o.id_order, \''.$this->l('Non ordered cart').'\') = \''.$this->l('Non ordered cart').'\', IF(TIME_TO_SEC(TIMEDIFF(\''.pSQL(date('Y-m-d H:i:00', time())).'\', a.`date_add`)) > 86400, \''.$this->l('Abandoned cart').'\', \''.$this->l('Non ordered cart').'\'), GROUP_CONCAT(DISTINCT o.`id_order`)) AS filter_ids_order, + IF (IFNULL(o.id_order, \''.$this->l('Non ordered cart').'\') = \''.$this->l('Non ordered cart').'\', IF(TIME_TO_SEC(TIMEDIFF(\''.pSQL(date('Y-m-d H:i:00', time())).'\', a.`date_add`)) > '._TIME_1_DAY_.', \''.$this->l('Abandoned cart').'\', \''.$this->l('Non ordered cart').'\'), GROUP_CONCAT(DISTINCT o.`id_order`)) AS filter_ids_order, IF(o.id_order, 1, 0) badge_success, IF(o.id_order, 0, 1) badge_danger, IF(co.id_guest, 1, 0) id_guest'; $this->_join = 'LEFT JOIN '._DB_PREFIX_.'customer c ON (c.id_customer = a.id_customer) LEFT JOIN '._DB_PREFIX_.'currency cu ON (cu.id_currency = a.id_currency) @@ -54,10 +54,6 @@ class AdminCartsControllerCore extends AdminController LEFT JOIN `'._DB_PREFIX_.'connections` co ON (a.id_guest = co.id_guest AND TIME_TO_SEC(TIMEDIFF(\''.pSQL(date('Y-m-d H:i:00', time())).'\', co.`date_add`)) < 1800)'; $this->_group = ' GROUP BY a.`id_cart`'; - if (Tools::getValue('action') == 'filterOnlyAbandonedCarts') { - $this->_filterHaving = ' AND `ids_order` = 0 AND `time_diff` > 86400'; - } - $this->fields_list = array( 'id_cart' => array( 'title' => $this->l('ID'), @@ -96,7 +92,7 @@ class AdminCartsControllerCore extends AdminController 'type' => 'bool', 'havingFilter' => true, 'class' => 'fixed-width-xs', - 'icon' => array(0 => 'icon-', 1 => 'icon-user') + 'callback' => 'getOnlineStatus', ) ); $this->shopLinkType = 'shop'; @@ -117,10 +113,32 @@ class AdminCartsControllerCore extends AdminController } parent::__construct(); - $this->list_no_link = true; } + public function postProcess() + { + if (Tools::getValue('action') == 'filterOnlyAbandonedCarts') { + $this->processResetFilters(); + $this->context->cookie->{'submitFilter'.$this->table} = true; + $prefix = $this->getCookieFilterPrefix(); + $this->context->cookie->{$prefix.$this->table.'Filter_filter_ids_order'} = $this->l('Abandoned cart'); + if (($dateFrom = Tools::getValue('date_from')) + && ($dateTo = Tools::getValue('date_to')) + && strtotime($dateTo) >= strtotime($dateFrom) + ) { + //Updating the date format of the filter dates to the required format. + $dateFrom = date('Y-m-d', strtotime($dateFrom)); + $dateTo = date('Y-m-d', strtotime($dateTo)); + $this->context->cookie->{$prefix.$this->table.'Filter_'.$this->fields_list['date_add']['filter_key']} = json_encode(array($dateFrom, $dateTo)); + } + + $this->redirect_after = $this->context->link->getAdminLink('AdminCarts'); + } + + parent::postProcess(); + } + public function getOrderColumn($idsOrder, $tr) { $smartyVars = array(); @@ -129,7 +147,7 @@ class AdminCartsControllerCore extends AdminController $smartyVars['type'] = 'orders'; $smartyVars['ids_order'] = $idsOrder; } else { - if ($tr['time_diff'] > 86400) { + if ($tr['time_diff'] > _TIME_1_DAY_) { $smartyVars['type'] = 'abandoned'; } else { $smartyVars['type'] = 'non_orderd'; @@ -143,6 +161,11 @@ class AdminCartsControllerCore extends AdminController return $tpl->fetch(); } + public function getOnlineStatus($status) + { + return $status ? $this->l('Yes') : $this->l('No'); + } + public function initPageHeaderToolbar() { if (empty($this->display)) { @@ -184,7 +207,7 @@ class AdminCartsControllerCore extends AdminController $date_from = date(Context::getContext()->language->date_format_lite, strtotime('-2 day')); $date_to = date(Context::getContext()->language->date_format_lite, strtotime('-1 day')); $helper->subtitle = sprintf($this->l('From %s to %s', null, null, false), $date_from, $date_to); - $helper->href = $this->context->link->getAdminLink('AdminCarts').'&action=filterOnlyAbandonedCarts'; + $helper->href = $this->context->link->getAdminLink('AdminCarts').'&action=filterOnlyAbandonedCarts&date_from='.$date_from.'&date_to='.$date_to; $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=abandoned_cart'; $kpis[] = $helper; diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index c08b5f111..3cfdfdf15 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -374,36 +374,17 @@ class AdminOrdersControllerCore extends AdminController $this->errors[] = $this->l('You have to select a shop before creating new orders.'); } - $id_cart = (int)Tools::getValue('id_cart'); - $cart = new Cart((int)$id_cart); - if ($id_cart && !Validate::isLoadedObject($cart)) { - $this->errors[] = $this->l('This cart does not exists'); - } - if ($id_cart && Validate::isLoadedObject($cart) && !$cart->id_customer) { - $this->errors[] = $this->l('The cart must have a customer'); - } - if (count($this->errors) && !Tools::getValue('submitAddorder')) { - return false; - } - - // check page is whether ad new order page or order detail page - if ((Tools::isSubmit('addorder') && ($id_cart = Tools::getValue('cart_id'))) - || (Tools::isSubmit('submitAddOrder') && ($id_cart = Tools::getValue('id_cart'))) - ) { + // check page is new order creation page and cart id is set + if (Tools::isSubmit('addorder') && ($id_cart = Tools::getValue('cart_id'))) { // set smarty variables if new order creation process has errors $cart = new Cart($id_cart); $cart_order_exists = $cart->orderExists(); if (!$cart_order_exists) { $this->context->cart = $cart; - if ($this->context->employee->isSuperAdmin()) { - $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; - } else { - $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; - } - if (!Configuration::get($backOrderConfigKey)) { - $objHotelCartBookingData = new HotelCartBookingData(); - $objHotelCartBookingData->removeBackdateRoomsFromCart($this->context->cart->id); - } + + // validate cart for removing invalid data from cart before new order creation + $this->errors = array_merge($this->errors, HotelCartBookingData::validateCartBookings()); + $this->context->currency = new Currency((int)$cart->id_currency); $cart_detail_data = array(); $cart_detail_data_obj = new HotelCartBookingData(); @@ -420,61 +401,68 @@ class AdminOrdersControllerCore extends AdminController $this->context->smarty->assign('cart_normal_data', $normalCartProduct); } + if (empty($cart_detail_data) && empty($normalCartProduct)) { + // if no rooms added in the cart and user visits add order page then redirect to BOOK NOW page + Tools::redirectAdmin($this->context->link->getAdminLink('AdminHotelRoomsBooking')); + } + + $payment_modules = array(); + foreach (PaymentModule::getInstalledPaymentModules() as $p_module) { + $payment_modules[] = Module::getInstanceById((int)$p_module['id_module']); + } + + $paymentTypes = array(); + foreach ($this->getPaymentsTypes() as $paymentType) { + if ($paymentType['value'] != OrderPayment::PAYMENT_TYPE_REMOTE_PAYMENT) { + $paymentTypes[] = $paymentType; + } + } + + $occupancyRequiredForBooking = false; + if (Configuration::get('PS_BACKOFFICE_ROOM_BOOKING_TYPE') == HotelBookingDetail::PS_ROOM_UNIT_SELECTION_TYPE_OCCUPANCY) { + $occupancyRequiredForBooking = true; + } + $objHotelAdvancedPayment = new HotelAdvancedPayment(); $this->context->smarty->assign(array( 'order_total' => $cart->getOrderTotal(true), 'is_advance_payment_active' => $objHotelAdvancedPayment->isAdvancePaymentAvailableForCurrentCart(), 'advance_payment_amount_without_tax' => $cart->getOrderTotal(false, Cart::ADVANCE_PAYMENT), 'advance_payment_amount_with_tax' => $cart->getOrderTotal(true, Cart::ADVANCE_PAYMENT), + 'cart' => $cart, + 'currencies' => Currency::getCurrenciesByIdShop(Context::getContext()->shop->id), + 'langs' => Language::getLanguages(true, Context::getContext()->shop->id), + 'payment_modules' => $payment_modules, + 'payment_types' => $paymentTypes, + 'currency' => new Currency((int)$cart->id_currency), + 'max_child_in_room' => Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM'), + 'max_child_age' => Configuration::get('WK_GLOBAL_CHILD_MAX_AGE'), + 'occupancy_required_for_booking' => $occupancyRequiredForBooking, )); - if (empty($cart_detail_data) && empty($normalCartProduct)) { - // if no rooms added in the cart and user visits add order page then redirect to BOOK NOW page - Tools::redirectAdmin($this->context->link->getAdminLink('AdminHotelRoomsBooking')); - } + } else { + Tools::redirectAdmin($this->context->link->getAdminLink('AdminHotelRoomsBooking')); } $this->context->smarty->assign('is_order_created', $cart_order_exists); + } else { + Tools::redirectAdmin($this->context->link->getAdminLink('AdminHotelRoomsBooking')); } + //end parent::renderForm(); unset($this->toolbar_btn['save']); $this->addJqueryPlugin(array('autocomplete', 'fancybox', 'typewatch')); - $payment_modules = array(); - foreach (PaymentModule::getInstalledPaymentModules() as $p_module) { - $payment_modules[] = Module::getInstanceById((int)$p_module['id_module']); - } - - $paymentTypes = array(); - foreach ($this->getPaymentsTypes() as $paymentType) { - if ($paymentType['value'] != OrderPayment::PAYMENT_TYPE_REMOTE_PAYMENT) { - $paymentTypes[] = $paymentType; - } - } - - $occupancyRequiredForBooking = false; - if (Configuration::get('PS_BACKOFFICE_ROOM_BOOKING_TYPE') == HotelBookingDetail::PS_ROOM_UNIT_SELECTION_TYPE_OCCUPANCY) { - $occupancyRequiredForBooking = true; - } - $this->context->smarty->assign(array( 'recyclable_pack' => (int)Configuration::get('PS_RECYCLABLE_PACK'), 'gift_wrapping' => (int)Configuration::get('PS_GIFT_WRAPPING'), - 'cart' => $cart, - 'currencies' => Currency::getCurrenciesByIdShop(Context::getContext()->shop->id), - 'langs' => Language::getLanguages(true, Context::getContext()->shop->id), - 'payment_modules' => $payment_modules, - 'payment_types' => $paymentTypes, 'show_toolbar' => $this->show_toolbar, 'toolbar_btn' => $this->toolbar_btn, 'toolbar_scroll' => $this->toolbar_scroll, 'PS_CATALOG_MODE' => Configuration::get('PS_CATALOG_MODE'), 'title' => array($this->l('Orders'), $this->l('Create order')), - 'currency' => new Currency((int)$cart->id_currency), - 'max_child_in_room' => Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM'), - 'max_child_age' => Configuration::get('WK_GLOBAL_CHILD_MAX_AGE'), - 'occupancy_required_for_booking' => $occupancyRequiredForBooking, )); + $this->content .= $this->createTemplate('form.tpl')->fetch(); } @@ -1624,9 +1612,21 @@ class AdminOrdersControllerCore extends AdminController } elseif (!Validate::isUnsignedInt($payment_type)) { $this->errors[] = Tools::displayError('Payment source is invalid'); // Amount cannot be less than paid amount by guest in negative price - } elseif ($amount < 0 && ($order->total_paid_real + $amount) < 0) { - $this->errors[] = sprintf(Tools::displayError('Amount cannot be less than -%s'), Tools::displayPrice($order->total_paid_real, new Currency($order->id_currency))); - } else { + } elseif ($amount < 0) { + if ($currency->id == $order->id_currency) { + if (($order->total_paid_real + $amount) < 0) { + $this->errors[] = sprintf(Tools::displayError('Amount cannot be less than -%s'), Tools::displayPrice($order->total_paid_real, new Currency($order->id_currency))); + } + } else { + $convertedAmount = Tools::ps_round(Tools::convertPriceFull($amount, $currency, new Currency($order->id_currency)), 6); + $convertedPaidAmount = Tools::ps_round(Tools::convertPriceFull($order->total_paid_real, new Currency($order->id_currency), $currency), 6); + if (($order->total_paid_real + $convertedAmount) < 0) { + $this->errors[] = sprintf(Tools::displayError('Amount cannot be less than -%s (-%s)'), Tools::displayPrice($convertedPaidAmount, $currency), Tools::displayPrice($order->total_paid_real, new Currency($order->id_currency))); + } + } + } + + if (!count($this->errors)) { if (!$order->addOrderPayment( $amount, Tools::getValue('payment_method'), @@ -1673,6 +1673,9 @@ class AdminOrdersControllerCore extends AdminController if ($this->tabAccess['edit'] === '1') { $objCart = new Cart($id_cart); if (Validate::isLoadedObject($objCart)) { + $this->context->cart = $objCart; + + $this->errors = HotelCartBookingData::validateCartBookings(); $orderTotal = $objCart->getOrderTotal(true, Cart::BOTH); if ($objCart->is_advance_payment) { $advancePaymentAmount = $objCart->getOrderTotal(true, Cart::ADVANCE_PAYMENT); @@ -1690,7 +1693,7 @@ class AdminOrdersControllerCore extends AdminController if ($paymentAmount == '') { $this->errors[] = Tools::displayError('Please enter valid Payment amount of the order.'); } elseif ($paymentAmount && !Validate::isPrice($paymentAmount)) { - $this->errors[] = Tools::displayError('Payment amount is invalid. Please enter correct amount.'); + $this->errors[] = Tools::displayError('Payment amount is invalid. Please enter valid amount.'); } else { $paymentAmount = (float) $paymentAmount; } @@ -1717,23 +1720,6 @@ class AdminOrdersControllerCore extends AdminController } } - // Validate if booking dates are allowed - if ($this->context->employee->isSuperAdmin()) { - $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; - } else { - $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; - } - if (!Configuration::get($backOrderConfigKey)) { - $objCartBookingData = new HotelCartBookingData(); - if ($cartBookingData = $objCartBookingData->getCartCurrentDataByCartId($cart->id)) { - foreach ($cartBookingData as $cartRoom) { - if (strtotime($cartRoom['date_from']) < strtotime(date('Y-m-d'))) { - $this->errors[] = Tools::displayError('You cannot book rooms before today date.'); - } - } - } - } - if (!count($this->errors)) { $this->context->currency = new Currency((int) $objCart->id_currency); $this->context->customer = new Customer((int) $objCart->id_customer); @@ -1811,10 +1797,6 @@ class AdminOrdersControllerCore extends AdminController if ($objPaymentModule->currentOrder) { Tools::redirectAdmin(self::$currentIndex.'&id_order='.$objPaymentModule->currentOrder.'&vieworder'.'&token='.$this->token.'&conf=3'); } - } else { - // if errors render add order form - $_GET['addorder'] = '1'; - $_GET['cart_id'] = $id_cart; } } else { $this->errors[] = Tools::displayError('Cart can not be loaded.'); @@ -2217,60 +2199,62 @@ class AdminOrdersControllerCore extends AdminController $this->errors[] = Tools::displayError('The discount type is invalid.'); } - $res = true; - foreach ($cart_rules as &$cart_rule) { - $cartRuleObj = new CartRule(); - $cartRuleObj->date_from = date('Y-m-d H:i:s', strtotime('-1 hour', strtotime($order->date_add))); - $cartRuleObj->date_to = date('Y-m-d H:i:s', strtotime('+1 hour')); - $cartRuleObj->name[Configuration::get('PS_LANG_DEFAULT')] = Tools::getValue('discount_name'); - $cartRuleObj->quantity = 0; - $cartRuleObj->quantity_per_user = 1; - if (Tools::getValue('discount_type') == 1) { - $cartRuleObj->reduction_percent = $discount_value; - } elseif (Tools::getValue('discount_type') == 2) { - $cartRuleObj->reduction_amount = $cart_rule['value_tax_excl']; - } elseif (Tools::getValue('discount_type') == 3) { - $cartRuleObj->free_shipping = 1; + if (!count($this->errors)) { + $res = true; + foreach ($cart_rules as &$cart_rule) { + $cartRuleObj = new CartRule(); + $cartRuleObj->date_from = date('Y-m-d H:i:s', strtotime('-1 hour', strtotime($order->date_add))); + $cartRuleObj->date_to = date('Y-m-d H:i:s', strtotime('+1 hour')); + $cartRuleObj->name[Configuration::get('PS_LANG_DEFAULT')] = Tools::getValue('discount_name'); + $cartRuleObj->quantity = 0; + $cartRuleObj->quantity_per_user = 1; + if (Tools::getValue('discount_type') == 1) { + $cartRuleObj->reduction_percent = $discount_value; + } elseif (Tools::getValue('discount_type') == 2) { + $cartRuleObj->reduction_amount = $cart_rule['value_tax_excl']; + } elseif (Tools::getValue('discount_type') == 3) { + $cartRuleObj->free_shipping = 1; + } + $cartRuleObj->active = 0; + if ($res = $cartRuleObj->add()) { + $cart_rule['id'] = $cartRuleObj->id; + $cart_rule['free_shipping'] = $cartRuleObj->free_shipping; + } else { + break; + } } - $cartRuleObj->active = 0; - if ($res = $cartRuleObj->add()) { - $cart_rule['id'] = $cartRuleObj->id; - $cart_rule['free_shipping'] = $cartRuleObj->free_shipping; + + if ($res) { + foreach ($cart_rules as $id_order_invoice => $cart_rule) { + // Create OrderCartRule + $order_cart_rule = new OrderCartRule(); + $order_cart_rule->id_order = $order->id; + $order_cart_rule->id_cart_rule = $cart_rule['id']; + $order_cart_rule->id_order_invoice = $id_order_invoice; + $order_cart_rule->name = Tools::getValue('discount_name'); + $order_cart_rule->value = $cart_rule['value_tax_incl']; + $order_cart_rule->value_tax_excl = $cart_rule['value_tax_excl']; + $order_cart_rule->free_shipping = $cart_rule['free_shipping']; + $res &= $order_cart_rule->add(); + + $order->total_discounts = Tools::ps_round($order->total_discounts + $order_cart_rule->value, 6); + $order->total_discounts_tax_incl = Tools::ps_round($order->total_discounts_tax_incl + $order_cart_rule->value, 6); + $order->total_discounts_tax_excl = Tools::ps_round($order->total_discounts_tax_excl + $order_cart_rule->value_tax_excl, 6); + $order->total_paid = Tools::ps_round($order->total_paid - $order_cart_rule->value, 6); + $order->total_paid_tax_incl = Tools::ps_round($order->total_paid_tax_incl - $order_cart_rule->value, 6); + $order->total_paid_tax_excl = Tools::ps_round($order->total_paid_tax_excl - $order_cart_rule->value_tax_excl, 6); + } + + // Update Order + $res &= $order->update(); + } + + if ($res) { + Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token); } else { - break; + $this->errors[] = Tools::displayError('An error occurred during the OrderCartRule creation'); } } - - if ($res) { - foreach ($cart_rules as $id_order_invoice => $cart_rule) { - // Create OrderCartRule - $order_cart_rule = new OrderCartRule(); - $order_cart_rule->id_order = $order->id; - $order_cart_rule->id_cart_rule = $cart_rule['id']; - $order_cart_rule->id_order_invoice = $id_order_invoice; - $order_cart_rule->name = Tools::getValue('discount_name'); - $order_cart_rule->value = $cart_rule['value_tax_incl']; - $order_cart_rule->value_tax_excl = $cart_rule['value_tax_excl']; - $order_cart_rule->free_shipping = $cart_rule['free_shipping']; - $res &= $order_cart_rule->add(); - - $order->total_discounts += $order_cart_rule->value; - $order->total_discounts_tax_incl += $order_cart_rule->value; - $order->total_discounts_tax_excl += $order_cart_rule->value_tax_excl; - $order->total_paid -= $order_cart_rule->value; - $order->total_paid_tax_incl -= $order_cart_rule->value; - $order->total_paid_tax_excl -= $order_cart_rule->value_tax_excl; - } - - // Update Order - $res &= $order->update(); - } - - if ($res) { - Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token); - } else { - $this->errors[] = Tools::displayError('An error occurred during the OrderCartRule creation'); - } } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); @@ -2429,7 +2413,7 @@ class AdminOrdersControllerCore extends AdminController $dateFrom = date(Context::getContext()->language->date_format_lite, strtotime('-2 day')); $dateTo = date(Context::getContext()->language->date_format_lite, strtotime('-1 day')); $helper->subtitle = sprintf($this->l('From %s to %s', null, null, false), $dateFrom, $dateTo); - $helper->href = $this->context->link->getAdminLink('AdminCarts').'&action=filterOnlyAbandonedCarts'; + $helper->href = $this->context->link->getAdminLink('AdminCarts').'&action=filterOnlyAbandonedCarts&date_from='.$dateFrom.'&date_to='.$dateTo; $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=abandoned_cart'; $helper->tooltip = $this->l('Total number of abandoned carts in given period of time.', null, null, false); $kpis[] = $helper; diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index 2de11a362..782f989f8 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -78,13 +78,15 @@ class AdminStatsControllerCore extends AdminStatsTabController return $visits; } - public static function getAbandonedCarts($date_from, $date_to) + + public static function getAbandonedCarts($date_from, $date_to, $timeDiff = false) { return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT COUNT(DISTINCT id_guest) - FROM `'._DB_PREFIX_.'cart` - WHERE `date_add` BETWEEN "'.pSQL($date_from).'" AND "'.pSQL($date_to).'" - AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'orders` WHERE `'._DB_PREFIX_.'orders`.id_cart = `'._DB_PREFIX_.'cart`.id_cart) + SELECT COUNT(`id_cart`) + FROM `'._DB_PREFIX_.'cart` c + WHERE `date_add` BETWEEN "'.pSQL($date_from).'" AND "'.pSQL($date_to).'"'. + (($timeDiff) ? 'AND TIME_TO_SEC(TIMEDIFF(\''.pSQL(date('Y-m-d H:i:00', time())).'\', `date_add`)) > '.$timeDiff : ' ').' + AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'orders` o WHERE o.`id_cart` = c.`id_cart`) '.Shop::addSqlRestriction()); } @@ -638,7 +640,11 @@ class AdminStatsControllerCore extends AdminStatsTabController break; case 'abandoned_cart': - $value = AdminStatsController::getAbandonedCarts(date('Y-m-d H:i:s', strtotime('-2 day')), date('Y-m-d H:i:s', strtotime('-1 day'))); + $value = AdminStatsController::getAbandonedCarts( + date('Y-m-d', strtotime('-2 day')).' 0:0:0', + date('Y-m-d', strtotime('-1 day')).' 23:59:59', + _TIME_1_DAY_ + ); break; case 'installed_modules': diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 2cd2a223c..95a0adceb 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -426,7 +426,7 @@ class OrderOpcControllerCore extends ParentOrderController public function initContent() { // validate room types before payment by customer - $orderRestrictErr = HotelCartBookingData::validateCartBookings(); + $this->errors = HotelCartBookingData::validateCartBookings(); parent::initContent(); @@ -494,7 +494,7 @@ class OrderOpcControllerCore extends ParentOrderController // $objCurrency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $this->context->smarty->assign( array( - 'orderRestrictErr' => $orderRestrictErr, + 'orderRestrictErr' => count($this->errors) ? 1 : 0, // 'allDemands' => $allDemands, // 'defaultcurrencySign' => $objCurrency->sign, 'THEME_DIR' => _THEME_DIR_, diff --git a/install/theme/view.css b/install/theme/view.css index 1d135b54d..95593aa66 100644 --- a/install/theme/view.css +++ b/install/theme/view.css @@ -90,10 +90,10 @@ div#leftpannel{ } div#buttons{ - clear:both; - margin:0 0 0 295px; - height:60px; + margin-top: 20px; + margin-bottom: 20px; width:650px; + padding:0 14px; } * html div#buttons { margin-bottom:60px; diff --git a/install/theme/views/footer.phtml b/install/theme/views/footer.phtml index 44dc055c7..9ae867a65 100644 --- a/install/theme/views/footer.phtml +++ b/install/theme/views/footer.phtml @@ -1,20 +1,20 @@ - - -
- isLastStep()): ?> - next_button): ?> - - - +
+ isLastStep()): ?> + next_button): ?> + + + + - - isFirstStep() && $this->previous_button): ?> - - -
+ isFirstStep() && $this->previous_button): ?> + + +
+ +
l('If you need some assistance, you can get tailored help from our support team. The official documentation is also here to guide you.'), $this->getTailoredHelp(), $this->getDocumentationLink()) ?>
diff --git a/install/theme/views/header.phtml b/install/theme/views/header.phtml index 6a04e0ea9..db3b9bfc6 100644 --- a/install/theme/views/header.phtml +++ b/install/theme/views/header.phtml @@ -119,7 +119,7 @@ -
+
diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index dc32346d2..df5c6c616 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -248,7 +248,7 @@ class HotelCartBookingData extends ObjectModel */ public function getCartCurrentDataByCartId($cart_id) { - $result = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'htl_cart_booking_data` WHERE `id_cart`='.$cart_id); + $result = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'htl_cart_booking_data` WHERE `id_cart`='.(int)$cart_id); if ($result) { return $result; } else { @@ -925,23 +925,34 @@ class HotelCartBookingData extends ObjectModel return true; } + // validate cart data if not available then remove from cart public static function validateCartBookings() { $context = Context::getContext(); - $errors = array(); + $objModule = Module::getInstanceByName('hotelreservationsystem'); + + // For admin cart validations use this variable + $forAdminCart = 0; + if (isset($context->employee->id)) { + $forAdminCart = 1; + } // validate room types if bookable from front office if ($cartProducts = $context->cart->getProducts()) { - $objHotelCartBookingData = new HotelCartBookingData(); - foreach ($cartProducts as $product) { - if ($product['booking_product'] && !$product['show_at_front']) { - $objHotelCartBookingData->deleteCartBookingData($context->cart->id, $product['id_product']); + if (!$forAdminCart) { + $objHotelCartBookingData = new HotelCartBookingData(); + foreach ($cartProducts as $product) { + if ($product['booking_product'] && !$product['show_at_front']) { + $objHotelCartBookingData->deleteCartBookingData($context->cart->id, $product['id_product']); + } } } + } else { + $errors[] = $objModule->l('No booking found in the cart.', 'HotelOrderRestrictDate'); } - // validate service products + // validate service products if not active not then remove from cart if ($cartProducts = $context->cart->getProducts()) { $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail(); foreach ($cartProducts as $product) { @@ -954,8 +965,20 @@ class HotelCartBookingData extends ObjectModel } } + // for admin/employee remove bookings of the back dates from cart if not allowed + if ($forAdminCart) { + if ($context->employee->isSuperAdmin()) { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; + } else { + $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; + } + if (!Configuration::get($backOrderConfigKey)) { + $objHotelCartBookingData = new HotelCartBookingData(); + $objHotelCartBookingData->removeBackdateRoomsFromCart($context->cart->id); + } + } + // validate room types for restriction date - $objModule = Module::getInstanceByName('hotelreservationsystem'); if ($cartProducts = $context->cart->getProducts()) { $objHotelCartBookingData = new HotelCartBookingData(); $objHotelBookingDetail = new HotelBookingDetail(); @@ -977,43 +1000,43 @@ class HotelCartBookingData extends ObjectModel } foreach ($cartData as $roomData) { - if ($maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($roomData['id_hotel'])) { - if (strtotime('-1 day', strtotime($maxOrderDate)) < strtotime($roomData['date_from']) - || strtotime($maxOrderDate) < strtotime($roomData['date_to']) - ) { - $objHotelBranchInformation = new HotelBranchInformation( - $roomData['id_hotel'], - $context->language->id - ); - $errors[] = sprintf( - 'You can not book rooms for hotel \'%s\' after date %s. Please remove rooms from %s - %s to proceed.', - $objHotelBranchInformation->hotel_name, - Tools::displayDate($maxOrderDate), - Tools::displayDate($roomData['date_from']), - Tools::displayDate($roomData['date_to']) - ); - $error = true; + if (!$forAdminCart) { + if ($maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($roomData['id_hotel'])) { + if (strtotime('-1 day', strtotime($maxOrderDate)) < strtotime($roomData['date_from']) + || strtotime($maxOrderDate) < strtotime($roomData['date_to']) + ) { + $objHotelBranchInformation = new HotelBranchInformation( + $roomData['id_hotel'], + $context->language->id + ); + $errors[] = sprintf( + 'You can not book rooms for hotel \'%s\' after date %s. Please remove rooms from %s - %s to proceed.', + $objHotelBranchInformation->hotel_name, + Tools::displayDate($maxOrderDate), + Tools::displayDate($roomData['date_from']), + Tools::displayDate($roomData['date_to']) + ); + } } - } - $preparationTime = HotelOrderRestrictDate::getPreparationTime($roomData['id_hotel']); - if ($preparationTime !== false) { - $minOrderDate = date('Y-m-d', strtotime('+'. ($preparationTime) .' days')); - if (strtotime($minOrderDate) > strtotime($roomData['date_from']) - || strtotime($minOrderDate . ' +1 day')> strtotime($roomData['date_to']) - ) { - $objHotelBranchInformation = new HotelBranchInformation( - $roomData['id_hotel'], - $context->language->id - ); - $errors[] = sprintf( - 'You can not book rooms for hotel \'%s\' before date %s. Please remove rooms from %s - %s to proceed.', - $objHotelBranchInformation->hotel_name, - Tools::displayDate($minOrderDate), - Tools::displayDate($roomData['date_from']), - Tools::displayDate($roomData['date_to']) - ); - $error = true; + $preparationTime = HotelOrderRestrictDate::getPreparationTime($roomData['id_hotel']); + if ($preparationTime !== false) { + $minOrderDate = date('Y-m-d', strtotime('+'. ($preparationTime) .' days')); + if (strtotime($minOrderDate) > strtotime($roomData['date_from']) + || strtotime($minOrderDate . ' +1 day')> strtotime($roomData['date_to']) + ) { + $objHotelBranchInformation = new HotelBranchInformation( + $roomData['id_hotel'], + $context->language->id + ); + $errors[] = sprintf( + 'You can not book rooms for hotel \'%s\' before date %s. Please remove rooms from %s - %s to proceed.', + $objHotelBranchInformation->hotel_name, + Tools::displayDate($minOrderDate), + Tools::displayDate($roomData['date_from']), + Tools::displayDate($roomData['date_to']) + ); + } } } @@ -1025,32 +1048,27 @@ class HotelCartBookingData extends ObjectModel 'only_search_data' => 1, ); $bookingSearchData = $objHotelBookingDetail->dataForFrontSearch($bookingParams); - $isRmBooked = 0; + $isRoomBooked = 0; if (count($bookingSearchData['rm_data'][$product['id_product']]['data']['available']) < count($roomData['id_rms'])) { foreach ($roomData['id_rms'] as $searchRoomData) { - if($isRmBooked = $objHotelBookingDetail->chechRoomBooked($searchRoomData, $roomData['date_from'], $roomData['date_to'])){ + if($isRoomBooked = $objHotelBookingDetail->chechRoomBooked($searchRoomData, $roomData['date_from'], $roomData['date_to'])){ break; } } - if ($isRmBooked) { + if ($isRoomBooked) { $errors[] = sprintf($objModule->l('The Room \'%s\' has been booked by another customer from \'%s\' to \'%s\' Please remove rooms from cart to proceed', 'HotelOrderRestrictDate'), $product['name'], date('d-m-Y', strtotime($roomData['date_from'])), date('d-m-Y', strtotime($roomData['date_to']))); - $error = true; } else { $errors[] = sprintf($objModule->l('The Room \'%s\' is no longer avalable from \'%s\' to \'%s\' Please remove rooms from cart to proceed', 'HotelOrderRestrictDate'), $product['name'], date('d-m-Y', strtotime($roomData['date_from'])), date('d-m-Y', strtotime($roomData['date_to']))); - $error = true; } } } } } else { - $error = true; $errors[] = $objModule->l('You can not book rooms from "', 'HotelOrderRestrictDate'). $product['name'] .$objModule->l('". Please remove rooms from "', 'HotelOrderRestrictDate'). $product['name'] . $objModule->l('" from cart to proceed.', 'HotelOrderRestrictDate'); } } } - $context->controller->errors = array_merge($context->controller->errors, $errors); - return $errors; } diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php index 5fad5a10b..e40082572 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -94,7 +94,7 @@ class RoomTypeServiceProductCartDetail extends ObjectModel )) { $updateQty = $product['quantity']; if (Product::getProductPriceCalculation($product['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) { - $objHotelCartBookingData = new HotelCartBookingData($idHtlCartData); + $objHotelCartBookingData = new HotelCartBookingData($htlCartBookingId); $numdays = HotelHelper::getNumberOfDays($objHotelCartBookingData->date_from, $objHotelCartBookingData->date_to); $updateQty *= $numdays; } diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php index 0edf2d641..5113d2ee1 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php @@ -42,6 +42,9 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $objCart = new Cart($this->context->cookie->id_cart); if (Validate::isLoadedObject($objCart) && !$objCart->orderExists()) { $this->context->cart = $objCart; + + // validate cart for removing invalid data from cart + HotelCartBookingData::validateCartBookings(); } else { $this->context->cookie->id_cart = 0; // remove invalid id_cart $this->context->cart = new Cart(); @@ -63,15 +66,6 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $objCustomer->id_guest = (int) $this->context->cookie->id_guest; $this->context->customer = $objCustomer; - if ($this->context->employee->isSuperAdmin()) { - $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; - } else { - $backOrderConfigKey = 'PS_BACKDATE_ORDER_EMPLOYEES'; - } - if (!Configuration::get($backOrderConfigKey)) { - $htlCart = new HotelCartBookingData(); - $htlCart->removeBackdateRoomsFromCart($this->context->cart->id); - } } protected function createNewCart() diff --git a/modules/qlohotelreview/qlohotelreview.php b/modules/qlohotelreview/qlohotelreview.php index e040fa903..9bd269f98 100644 --- a/modules/qlohotelreview/qlohotelreview.php +++ b/modules/qlohotelreview/qlohotelreview.php @@ -187,13 +187,14 @@ class QloHotelReview extends Module if (QhrHotelReviewHelper::getIsReviewable($idOrder) && !QhrHotelReview::getByIdOrder($idOrder) ) { - $hotel = QhrHotelReviewHelper::getHotelByOrder($idOrder); - $this->smarty->assign(array( - 'id_order' => (int) $idOrder, - 'id_hotel' => $hotel['id_hotel'], - 'hotel_name' => $hotel['hotel_name'], - )); - return $this->display(__FILE__, 'booking-action.tpl'); + if ($hotel = QhrHotelReviewHelper::getHotelByOrder($idOrder)) { + $this->smarty->assign(array( + 'id_order' => (int) $idOrder, + 'id_hotel' => $hotel['id_hotel'], + 'hotel_name' => $hotel['hotel_name'], + )); + return $this->display(__FILE__, 'booking-action.tpl'); + } } } diff --git a/themes/hotel-reservation-theme/css/order-detail.css b/themes/hotel-reservation-theme/css/order-detail.css index c128914d9..c84de4477 100644 --- a/themes/hotel-reservation-theme/css/order-detail.css +++ b/themes/hotel-reservation-theme/css/order-detail.css @@ -86,10 +86,6 @@ line-height: 27px; } -.card.card-toolbar .card-header { - padding: 8px 18px; -} - .card .card-subheader { margin-bottom: 0; font-size: 14px; @@ -211,6 +207,10 @@ line-height: 16px; } +.payment-details .detail-row .status .processing { + font-size: 16px; +} + .hotel-location p.hotel-address { font-size: 16px; line-height: 24px; @@ -251,6 +251,10 @@ align-items: center; } +.room-details .card-header .booking-actions-wrap { + margin: -6px 0; +} + .room-details .card-header .booking-actions-wrap .col-xs-12 { display: flex; flex-wrap: wrap; diff --git a/themes/hotel-reservation-theme/order-detail.tpl b/themes/hotel-reservation-theme/order-detail.tpl index b265ab018..e0000be46 100644 --- a/themes/hotel-reservation-theme/order-detail.tpl +++ b/themes/hotel-reservation-theme/order-detail.tpl @@ -116,13 +116,17 @@
{l s='Status'}
- - {if $order_history[0].id_order_state|in_array:$overbooking_order_states} - {l s='Order Not Confirmed'} - {else} - {$order_history[0].ostate_name|escape:'html':'UTF-8'} - {/if} - + {if isset($order_history[0]) && $order_history[0]} + + {if $order_history[0].id_order_state|in_array:$overbooking_order_states} + {l s='Order Not Confirmed'} + {else} + {$order_history[0].ostate_name|escape:'html':'UTF-8'} + {/if} + + {else} + {l s='Processing'} + {/if}
@@ -173,7 +177,7 @@ {/if} {hook h='displayOrderDetailRoomDetailsBefore' id_order=$order->id} -
+
{l s='Room Details'}
@@ -499,13 +503,17 @@
{l s='Status'}
- - {if $order_history[0].id_order_state|in_array:$overbooking_order_states} - {l s='Order Not Confirmed'} - {else} - {$order_history[0].ostate_name|escape:'html':'UTF-8'} - {/if} - + {if isset($order_history[0]) && $order_history[0]} + + {if $order_history[0].id_order_state|in_array:$overbooking_order_states} + {l s='Order Not Confirmed'} + {else} + {$order_history[0].ostate_name|escape:'html':'UTF-8'} + {/if} + + {else} + {l s='Processing'} + {/if}
@@ -777,7 +785,10 @@ {if $hotel_booking_detail.is_refunded || $hotel_booking_detail.is_cancelled}{l s='Cancelled'}{/if}
- {assign var='has_services' value=(isset($rm_v.additional_services) && isset($rm_v.additional_services[$hotel_booking_detail.id_room]) && isset($rm_v.additional_services[$hotel_booking_detail.id_room]['additional_services']))} + + {* Services are indexed with id_htl_booking *} + {assign var='has_services' value=(isset($rm_v.additional_services) && isset($rm_v.additional_services[$hotel_booking_detail.id_htl_booking]) && isset($rm_v.additional_services[$hotel_booking_detail.id_htl_booking]['additional_services']))} + {* Additional Facilities are indexed with id_room *} {assign var='has_facilities' value=(isset($rm_v.extra_demands) && isset($rm_v.extra_demands[$hotel_booking_detail.id_room]) && isset($rm_v.extra_demands[$hotel_booking_detail.id_room]['extra_demands']))} {if $has_services || $has_facilities}
@@ -787,7 +798,7 @@ {l s='Services'}
- {foreach from=$rm_v.additional_services[$hotel_booking_detail.id_room]['additional_services'] item=service} + {foreach from=$rm_v.additional_services[$hotel_booking_detail.id_htl_booking]['additional_services'] item=service} {$service.name} {/foreach}