Merge branch 'develop' into gli-2145

This commit is contained in:
vishalsingh.qlo325
2024-08-05 20:10:19 +05:30
18 changed files with 738 additions and 463 deletions

View File

@@ -454,10 +454,8 @@ class AdminAddressesControllerCore extends AdminController
** we delete its id_address to force the creation of a new one */
if ((int)Tools::getValue('id_order')) {
$this->_redirect = false;
if (isset($_POST['address_type'])) {
$_POST['id_address'] = '';
$this->id_object = null;
}
// set deleted=1 as customer can have only one address and this address is for an order only
$_POST['deleted'] = 1;
}
// Check the requires fields which are settings in the BO
@@ -478,10 +476,18 @@ class AdminAddressesControllerCore extends AdminController
if ($this->action == 'save' && ($id_order = (int)Tools::getValue('id_order')) && !count($this->errors) && !empty($address_type)) {
if (!Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'orders SET `id_address_'.bqSQL($address_type).'` = '.(int)$this->object->id.' WHERE `id_order` = '.(int)$id_order)) {
$this->errors[] = Tools::displayError('An error occurred while linking this address to its order.');
} else {
Tools::redirectAdmin(urldecode(Tools::getValue('back')).'&conf=4');
}
}
// in case of save and stay, redirect after save with current address.
// Because the current address can not be same as the current one(We have to delete it and create a new one in case address is used in orders)
if (empty($this->errors) && Tools::isSubmit('submitAdd'.$this->table.'AndStay')) {
$idCurrentAddress = Customer::getCustomerIdAddress($this->object->id_customer, false);
if ($idCurrentAddress != $this->object->id) {
$this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$idCurrentAddress.'&conf=4&update'.$this->table.'&token='.$this->token;
}
}
return $return;
}

View File

@@ -133,7 +133,7 @@ class AdminCustomerPreferencesControllerCore extends AdminController
'PS_KPI_FREQUENT_CUSTOMER_NB_ORDERS' => array(
'title' => $this->l('Number of orders to use to calculate frequent customers'),
'hint' => $this->l('Set the number of orders to use to calculate frequent customers.'),
'validation' => 'isUnsignedInt',
'validation' => 'isInt',
'cast' => 'intval',
'type' => 'text',
'class' => 'fixed-width-xxl',
@@ -173,6 +173,14 @@ class AdminCustomerPreferencesControllerCore extends AdminController
);
}
public function beforeUpdateOptions()
{
$fieldData = $this->fields_options['customer_kpi']['fields']['PS_KPI_FREQUENT_CUSTOMER_NB_ORDERS'];
if (!Tools::getValue('PS_KPI_FREQUENT_CUSTOMER_NB_ORDERS')) {
$this->errors[] = sprintf(Tools::displayError('field %s must be greater than 0.'), $fieldData['title']);;
}
}
/**
* Update PS_B2B_ENABLE and enables / disables the associated tabs
* @param $value integer Value of option

View File

@@ -79,6 +79,9 @@ class AdminCustomersControllerCore extends AdminController
$this->_join = 'LEFT JOIN '._DB_PREFIX_.'gender_lang gl ON (a.id_gender = gl.id_gender AND gl.id_lang = '.(int)$this->context->language->id.')';
$this->_join .= ' LEFT JOIN '._DB_PREFIX_.'group_lang grl ON (a.id_default_group = grl.id_group AND grl.id_lang = '.(int)$this->context->language->id.')';
$this->_join .= ' LEFT JOIN '._DB_PREFIX_.'orders o ON (a.id_customer = o.id_customer)';
$this->_group = 'GROUP BY a.`id_customer`';
$this->_use_found_rows = false;
$this->fields_list = array(
'id_customer' => array(
@@ -123,6 +126,7 @@ class AdminCustomersControllerCore extends AdminController
),
'total_orders' => array(
'title' => $this->l('Number of orders'),
'type' => 'range',
'optional' => true,
'visible_default' => true,
'havingFilter' => true,
@@ -163,6 +167,7 @@ class AdminCustomersControllerCore extends AdminController
'date_add' => array(
'title' => $this->l('Registration'),
'type' => 'date',
'filter_key' => 'a!date_add',
'align' => 'text-right'
),
'connect' => array(
@@ -175,6 +180,12 @@ class AdminCustomersControllerCore extends AdminController
'title' => $this->l('Banned'),
'type' => 'bool',
'displayed' => false,
),
'order_date' => array(
'title' => $this->l('Order date'),
'type' => 'date',
'filter_key' => 'o!date_add',
'displayed' => false
)
));
@@ -183,19 +194,8 @@ class AdminCustomersControllerCore extends AdminController
parent::__construct();
$this->_select = '
a.date_add, gl.name as title, grl.name as default_group_name, (
SELECT SUM(total_paid_real / conversion_rate)
FROM '._DB_PREFIX_.'orders o
WHERE o.id_customer = a.id_customer
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o').'
AND o.valid = 1
) as total_spent, (
SELECT COUNT(o.`id_order`)
FROM '._DB_PREFIX_.'orders o
WHERE o.id_customer = a.id_customer
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o').'
AND o.valid = 1
) as total_orders, (
a.date_add, gl.name as title, grl.name as default_group_name, COUNT(o.`id_order`) as total_orders,
o.`date_add` as order_date, SUM(total_paid_real / conversion_rate) as total_spent, (
SELECT c.date_add FROM '._DB_PREFIX_.'guest g
LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest
WHERE g.id_customer = a.id_customer
@@ -707,7 +707,8 @@ class AdminCustomersControllerCore extends AdminController
$helper->icon = 'icon-star';
$helper->color = 'color2';
$helper->title = $this->l('Total Frequent Customers', null, null, false);
$helper->subtitle = $this->l('All Time', null, null, false);
$helper->subtitle = $this->l('1 year', null, null, false);
$helper->href = $this->context->link->getAdminLink('AdminCustomers').'&submitFiltercustomer=1&customerFilter_total_orders%5B0%5D='.Configuration::get('PS_KPI_FREQUENT_CUSTOMER_NB_ORDERS').'&customerFilter_o%21date_add%5B0%5D='.date('Y-m-d', strtotime('-365 day')).'&customerFilter_o%21date_add%5B1%5D='.date('Y-m-d');
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_frequent_customers';
$helper->tooltip = $this->l('The total number of frequent customers in given period of time.', null, null, false);
$kpis[] = $helper;

View File

@@ -2266,6 +2266,88 @@ class AdminOrdersControllerCore extends AdminController
} else {
$this->errors = Tools::displayError('An error occurred while resolving overbooking.');
}
// Set old orders address as current order address
} elseif (Tools::getValue('action') && Tools::getValue('action') == 'set_old_orders_address') {
if ($idOrder = Tools::getValue('id_order')) {
if (Validate::isLoadedObject($objOrder = new Order($idOrder))) {
$idAddressInvoice = $objOrder->id_address_invoice;
if ($idAddressInvoice && Validate::isLoadedObject(new Address($idAddressInvoice))) {
// get all customer orders and set old orders address as current order address
if ($customerOrders = Order::getCustomerOrders($objOrder->id_customer)) {
foreach ($customerOrders as $order) {
$objOrder = new Order($order['id_order']);
$objOrder->id_address_invoice = $idAddressInvoice;
$objOrder->update();
}
}
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$idOrder.'&vieworder&conf=6&token='.$this->token);
} else {
$this->errors = Tools::displayError('Address not found. Please try again.');
}
} else {
$this->errors = Tools::displayError('Order not found. Please try again.');
}
} else {
$this->errors = Tools::displayError('Order not found. Please try again.');
}
// Set customer current active address as current order address
} elseif (Tools::getValue('action') && Tools::getValue('action') == 'set_address_current_address') {
if ($idOrder = Tools::getValue('id_order')) {
if (Validate::isLoadedObject($objOrder = new Order($idOrder))) {
$idAddressInvoice = $objOrder->id_address_invoice;
if ($idAddressInvoice && Validate::isLoadedObject($objOrderAddress = new Address($idAddressInvoice))) {
$updateAddress = 1;
if ($idCustomerAddress = Customer::getCustomerIdAddress($objOrder->id_customer)) {
// only proceed if current active address and current order address are different
if ($idCustomerAddress != $idAddressInvoice) {
if (Validate::isLoadedObject($objActiveAddress = new Address($idCustomerAddress))) {
// set current active address information from order address
$objOrderAddress->id = $objOrderAddress->id_address = $objActiveAddress->id;
$objOrderAddress->deleted = 0;
$objOrderAddress->update();
} else {
$this->errors = Tools::displayError('Customer address not found. Please try again.');
}
}
} else {
// If customer has no active address, create new customer address with the order address
$objOrderAddress->id = $objOrderAddress->id_address = null;
$objOrderAddress->deleted = 0;
$objOrderAddress->add();
}
if (!count($this->errors)) {
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$idOrder.'&vieworder&conf=6&token='.$this->token);
}
} else {
$this->errors = Tools::displayError('Address not found. Please try again.');
}
} else {
$this->errors = Tools::displayError('Order not found. Please try again.');
}
} else {
$this->errors = Tools::displayError('Order not found. Please try again.');
}
} elseif (Tools::getValue('action') && Tools::getValue('action') == 'set_order_active_address') {
if ($idOrder = Tools::getValue('id_order')) {
if (Validate::isLoadedObject($objOrder = new Order($idOrder))) {
// get currenct active address of the customer
if ($idCustomerAddress = Customer::getCustomerIdAddress($objOrder->id_customer)) {
$objOrder->id_address_invoice = $idCustomerAddress;
if ($objOrder->update()) {
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$idOrder.'&vieworder&conf=6&token='.$this->token);
} else {
$this->errors[] = Tools::displayError('Some error occurred while updating address detail. Please try again.');
}
} else {
$this->errors = Tools::displayError('Customer address not found. Please try again.');
}
} else {
$this->errors = Tools::displayError('Order not found. Please try again.');
}
} else {
$this->errors = Tools::displayError('Order not found. Please try again.');
}
}
// Sending loader image for the modals to be used for all the modals ajax processes
@@ -2883,7 +2965,27 @@ class AdminOrdersControllerCore extends AdminController
// Overbookings information of the order
$orderOverBookings = $objHotelBookingDetail->getOverbookedRooms($order->id, 0, '', '', 0, 0, 1);
// Guest address info
$guestFormattedAddress = '';
$idOrderAddressInvoice = 0;
$ordersWithDiffInvAddr = 0;
$idCurrentAddress = Customer::getCustomerIdAddress($order->id_customer);
if ($order->id_address_invoice && Validate::isLoadedObject($objGuestAddress = new Address($order->id_address_invoice))) {
$idOrderAddressInvoice = $order->id_address_invoice;
$guestFormattedAddress = AddressFormat::generateAddress($objGuestAddress, array(), "<br />");
// get customer orders without same id_address_invoice
if ($customerOrders = Order::getCustomerOrders($order->id_customer, false, null, $idOrderAddressInvoice, 1)) {
if ($customerOrders > 1) {
$ordersWithDiffInvAddr = 1;
}
}
}
$this->tpl_view_vars = array(
'guestFormattedAddress' => $guestFormattedAddress,
'idOrderAddressInvoice' => $idOrderAddressInvoice,
'ordersWithDiffInvAddr' => $ordersWithDiffInvAddr,
'idCurrentAddress' => $idCurrentAddress,
'totalRefundedRooms' => $totalRefundedRooms,
'orderOverBookings' => $orderOverBookings,
// refund info
@@ -6268,6 +6370,14 @@ class AdminOrdersControllerCore extends AdminController
$res &= $objOrderDetail->update();
}
if ($objOrderDetail->id_order_invoice != 0) {
// values changes as values are calculated
$objOrderInvoice = new OrderInvoice($objOrderDetail->id_order_invoice);
$objOrderInvoice->total_paid_tax_excl -= $priceTaxExcl;
$objOrderInvoice->total_paid_tax_incl -= $priceTaxIncl;
$res &= $objOrderInvoice->update();
}
$order->total_paid_tax_excl -= $priceTaxExcl;
$order->total_paid_tax_incl -= $priceTaxIncl;
$order->total_paid -= $priceTaxIncl;
@@ -6300,6 +6410,9 @@ class AdminOrdersControllerCore extends AdminController
// valiadate services being added
if (Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail($idBookingDetail))) {
$objOrder = new Order($objHotelBookingDetail->id_order);
$objOrderDetail = new OrderDetail($objHotelBookingDetail->id_order_detail);
$objOrderInvoice = new OrderInvoice($objOrderDetail->id_order_invoice);
// set context currency So that we can get prices in the order currency
$this->context->currency = new Currency($objOrder->id_currency);
@@ -6481,7 +6594,7 @@ class AdminOrdersControllerCore extends AdminController
}
$order_detail = new OrderDetail();
$order_detail->createList($order, $cart, $order->getCurrentOrderState(), $productList, (isset($order_invoice) ? $order_invoice->id : 0), true);
$order_detail->createList($order, $cart, $order->getCurrentOrderState(), $productList, (isset($objOrderInvoice) ? $objOrderInvoice->id : 0), true);
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
$objRoomTypeServiceProductOrderDetail->id_product = $product['id_product'];
@@ -6505,16 +6618,18 @@ class AdminOrdersControllerCore extends AdminController
$order->total_paid_tax_excl += Tools::ps_round((float)($totalPriceChangeTaxExcl), 2);
$order->total_paid_tax_incl += Tools::ps_round((float)($totalPriceChangeTaxIncl), 2);
if (isset($order_invoice) && Validate::isLoadedObject($order_invoice)) {
$order->total_shipping = $order_invoice->total_shipping_tax_incl;
$order->total_shipping_tax_incl = $order_invoice->total_shipping_tax_incl;
$order->total_shipping_tax_excl = $order_invoice->total_shipping_tax_excl;
// update invoice total
if (isset($objOrderInvoice) && Validate::isLoadedObject($objOrderInvoice)) {
$objOrderInvoice->total_paid_tax_excl += Tools::ps_round((float)($totalPriceChangeTaxExcl), 2);
$objOrderInvoice->total_paid_tax_incl += Tools::ps_round((float)($totalPriceChangeTaxIncl), 2);
$objOrderInvoice->save();
}
// discount
$order->total_discounts += (float)abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
$order->total_discounts_tax_excl += (float)abs($cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS));
$order->total_discounts_tax_incl += (float)abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
// Save changes of order
$order->update();
if (Validate::isLoadedObject($specific_price)) {
@@ -6713,8 +6828,9 @@ class AdminOrdersControllerCore extends AdminController
$order_invoice = new OrderInvoice($order_detail->id_order_invoice);
$order_invoice->total_paid_tax_excl += $priceDiffTaxExcl;
$order_invoice->total_paid_tax_incl += $priceDiffTaxIncl;
$res &= $order_invoice->update();
$order_invoice->update();
}
$order = new Order($objBookingDetail->id_order);
$order->total_paid_tax_excl += $priceDiffTaxExcl;
$order->total_paid_tax_incl += $priceDiffTaxIncl;

View File

@@ -910,7 +910,12 @@ class AdminStatsControllerCore extends AdminStatsTabController
case 'total_frequent_customers':
$nbOrdersFrequentCustomers = Configuration::get('PS_KPI_FREQUENT_CUSTOMER_NB_ORDERS');
$value = AdminStatsController::getTotalFrequentCustomers($nbOrdersFrequentCustomers, 0);
$value = AdminStatsController::getTotalFrequentCustomers(
date('Y-m-d', strtotime('-365 day')),
date('Y-m-d'),
$nbOrdersFrequentCustomers,
0
);
break;
@@ -1829,7 +1834,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
return $result;
}
public static function getTotalFrequentCustomers($nbOrders = 5, $idHotel = null)
public static function getTotalFrequentCustomers($dateFrom, $dateTo, $nbOrders = 5, $idHotel = null)
{
$sql = 'SELECT COUNT(t.`id_customer`)
FROM (
@@ -1840,7 +1845,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
WHERE hbd.`id_order` = o.`id_order` LIMIT 1
) AS id_hotel
FROM `'._DB_PREFIX_.'orders` o
WHERE o.`valid` = 1
WHERE o.`valid` = 1 AND o.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"
GROUP BY o.`id_customer`
HAVING 1 '.(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel) : '').'
) AS t

View File

@@ -250,6 +250,9 @@ class GuestTrackingControllerCore extends FrontController
$total_convenience_fee_te = 0;
$total_convenience_fee_ti = 0;
$objOrderReturn = new OrderReturn();
$refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1);
foreach ($orderProducts as $type_key => $type_value) {
if (in_array($type_value['product_id'], $processedProducts)) {
continue;
@@ -307,6 +310,14 @@ class GuestTrackingControllerCore extends FrontController
if ($data_v['is_back_order']) {
$anyBackOrder = 1;
}
if ($refundReqBookings && in_array($data_v['id'], $refundReqBookings) && $data_v['is_refunded']) {
if ($data_v['is_cancelled']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1;
} else {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1;
}
}
} else {
$num_days = $objBookingDetail->getNumberOfDays($data_v['date_from'], $data_v['date_to']);
$cartHotelData[$type_key]['date_diff'][$date_join]['num_rm'] = 1;
@@ -326,6 +337,16 @@ class GuestTrackingControllerCore extends FrontController
if ($data_v['is_back_order']) {
$anyBackOrder = 1;
}
$cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] = 0;
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] = 0;
if ($refundReqBookings && in_array($data_v['id'], $refundReqBookings) && $data_v['is_refunded']) {
if ($data_v['is_cancelled']) {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_cancelled'] += 1;
} else {
$cartHotelData[$type_key]['date_diff'][$date_join]['count_refunded'] += 1;
}
}
}
$cartHotelData[$type_key]['date_diff'][$date_join]['is_refunded'] = $data_v['is_refunded'];
@@ -583,6 +604,7 @@ class GuestTrackingControllerCore extends FrontController
'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD,
'use_tax' => Configuration::get('PS_TAX'),
'guestInformations' => (array)$customer,
'view_on_map' => Configuration::get('WK_GOOGLE_ACTIVE_MAP'),
));
}
@@ -627,6 +649,7 @@ class GuestTrackingControllerCore extends FrontController
'map_input_text' => $objHotelBranchInformation->map_input_text,
),
'hotel_name' => $objHotelBranchInformation->hotel_name,
'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON'))
));
$this->addJS(