diff --git a/classes/CustomerMessage.php b/classes/CustomerMessage.php index 99522fa0d..a4b6c920d 100644 --- a/classes/CustomerMessage.php +++ b/classes/CustomerMessage.php @@ -38,6 +38,9 @@ class CustomerMessageCore extends ObjectModel public $date_upd; public $read; + const QLO_CUSTOMER_MESSAGE_BY_EMPLOYEE = 1; + const QLO_CUSTOMER_MESSAGE_BY_CUSTOMER = 2; + /** * @see ObjectModel::$definition */ diff --git a/classes/CustomerThread.php b/classes/CustomerThread.php index 70db8c507..7e1b721af 100644 --- a/classes/CustomerThread.php +++ b/classes/CustomerThread.php @@ -120,7 +120,17 @@ class CustomerThreadCore extends ObjectModel return $return; } - public static function getCustomerMessages($id_customer, $read = null, $id_order = null) + /** + * Retrieves customer messages based on specified conditions. + * + * @param int $id_customer Customer ID. + * @param bool|null $read Return read (true), unread (false), or all messages (null). + * @param int|null $id_order Filter messages by order ID. + * @param int|null $messageBy Filter messages by sender (employees, customer, or both). + * + * @return array List of messages matching the conditions. + */ + public static function getCustomerMessages($id_customer, $read = null, $id_order = null, $messageBy = null) { $sql = 'SELECT * FROM '._DB_PREFIX_.'customer_thread ct @@ -135,6 +145,14 @@ class CustomerThreadCore extends ObjectModel $sql .= ' AND ct.`id_order` = '.(int)$id_order; } + if ($messageBy !== null) { + if (CustomerMessage::QLO_CUSTOMER_MESSAGE_BY_EMPLOYEE == $messageBy) { + $sql .= ' AND cm.`id_employee` != 0'; + } else if (CustomerMessage::QLO_CUSTOMER_MESSAGE_BY_CUSTOMER == $messageBy) { + $sql .= ' AND cm.`id_employee` = 0'; + } + } + $sql .= ' ORDER BY cm.date_add DESC'; return Db::getInstance()->executeS($sql); diff --git a/classes/order/Order.php b/classes/order/Order.php index 3b8565bc6..67e8e48c2 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2536,7 +2536,7 @@ class OrderCore extends ObjectModel foreach ($tax_calculator->getTaxesAmount($discounted_price_tax_excl) as $id_tax => $unit_amount) { $total_tax_base = 0; $total_tax_base = Tools::processPriceRounding($discounted_price_tax_excl, $quantity); - $totalPrice = Tools::processPriceRounding($unit_amount, $quantity); + $total_amount = Tools::processPriceRounding($unit_amount, $quantity); if (!isset($breakdown[$id_tax])) { $breakdown[$id_tax] = array('tax_base' => 0, 'tax_amount' => 0); diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index ae8553e62..c523ffd3c 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -82,7 +82,6 @@ class AdminCustomersControllerCore extends AdminController $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( 'title' => $this->l('ID'), diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 30236549b..b3a65eac7 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -2431,7 +2431,7 @@ class AdminOrdersControllerCore extends AdminController $helper->title = $this->l('Messages'); $helper->tooltip = $this->l('Messages is the number of customer messages for this order.'); $helper->href = $this->context->link->getAdminLink('AdminCustomerThreads').'&id_order='.$objOrder->id; - $helper->value = count(CustomerThread::getCustomerMessages($objOrder->id_customer, null, $objOrder->id)); + $helper->value = count(CustomerThread::getCustomerMessages($objOrder->id_customer, null, $objOrder->id, CustomerMessage::QLO_CUSTOMER_MESSAGE_BY_CUSTOMER)); $this->kpis[] = $helper; $objHotelBookingDetail = new HotelBookingDetail(); diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index 325499f8a..109e93623 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -225,7 +225,7 @@ class AdminStatsControllerCore extends AdminStatsTabController { if ($granularity == 'day') { $sales = array(); - $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS( + if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS( 'SELECT LEFT(`invoice_date`, 10) AS date, SUM(total_paid_tax_excl / o.conversion_rate) AS sales FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state @@ -236,14 +236,15 @@ class AdminStatsControllerCore extends AdminStatsTabController WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).' ) GROUP BY LEFT(`invoice_date`, 10)' - ); - foreach ($result as $row) { - $sales[strtotime($row['date'])] = $row['sales']; - } + )) { + foreach ($result as $row) { + $sales[strtotime($row['date'])] = $row['sales']; + } + } return $sales; } elseif ($granularity == 'month') { $sales = array(); - $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS( + if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS( 'SELECT LEFT(`invoice_date`, 7) AS date, SUM(total_paid_tax_excl / o.conversion_rate) AS sales FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state @@ -254,11 +255,12 @@ class AdminStatsControllerCore extends AdminStatsTabController WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).' ) GROUP BY LEFT(`invoice_date`, 7)' - ); + )) { - foreach ($result as $row) { - $sales[strtotime($row['date'].'-01')] = $row['sales']; - } + foreach ($result as $row) { + $sales[strtotime($row['date'].'-01')] = $row['sales']; + } + } return $sales; } else { @@ -296,7 +298,7 @@ class AdminStatsControllerCore extends AdminStatsTabController { if ($granularity == 'day') { $orders = array(); - $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' + if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT LEFT(`invoice_date`, 10) as date, COUNT(DISTINCT o.`id_order`) as orders FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state @@ -304,14 +306,15 @@ class AdminStatsControllerCore extends AdminStatsTabController WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 '.Shop::addSqlRestriction(false, 'o') .HotelBranchInformation::addHotelRestriction($id_hotel, 'hbd').' - GROUP BY LEFT(`invoice_date`, 10)'); - foreach ($result as $row) { - $orders[strtotime($row['date'])] = $row['orders']; - } + GROUP BY LEFT(`invoice_date`, 10)')) { + foreach ($result as $row) { + $orders[strtotime($row['date'])] = $row['orders']; + } + } return $orders; } elseif ($granularity == 'month') { $orders = array(); - $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' + if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT LEFT(`invoice_date`, 7) as date, COUNT(DISTINCT o.`id_order`) as orders FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state @@ -319,9 +322,10 @@ class AdminStatsControllerCore extends AdminStatsTabController WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 '.Shop::addSqlRestriction(false, 'o') .HotelBranchInformation::addHotelRestriction($id_hotel, 'hbd').' - GROUP BY LEFT(`invoice_date`, 7)'); - foreach ($result as $row) { - $orders[strtotime($row['date'].'-01')] = $row['orders']; + GROUP BY LEFT(`invoice_date`, 7)')) { + foreach ($result as $row) { + $orders[strtotime($row['date'].'-01')] = $row['orders']; + } } return $orders; } else { @@ -362,7 +366,7 @@ class AdminStatsControllerCore extends AdminStatsTabController SELECT SUM(IF(c.id_gender IS NOT NULL, 1, 0)) as total, SUM(IF(type = 0, 1, 0)) as male, SUM(IF(type = 1, 1, 0)) as female, SUM(IF(type = 2, 1, 0)) as neutral FROM `'._DB_PREFIX_.'customer` c LEFT JOIN `'._DB_PREFIX_.'gender` g ON c.id_gender = g.id_gender - WHERE c.active = 1 AND c.deleted = 0 '.Shop::addSqlRestriction()); + WHERE 1 AND c.deleted = 0 '.Shop::addSqlRestriction()); if (!$row['total']) { return false; @@ -474,7 +478,7 @@ class AdminStatsControllerCore extends AdminStatsTabController { if ($granularity == 'day') { $purchases = array(); - $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' + if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT LEFT(`invoice_date`, 10) as date, SUM(od.`product_quantity` * IF( @@ -496,10 +500,11 @@ class AdminStatsControllerCore extends AdminStatsTabController FROM `qlo_htl_booking_detail` hbd WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).' ) - GROUP BY LEFT(`invoice_date`, 10)'); + GROUP BY LEFT(`invoice_date`, 10)')) { - foreach ($result as $row) { - $purchases[strtotime($row['date'])] = $row['total_purchase_price']; + foreach ($result as $row) { + $purchases[strtotime($row['date'])] = $row['total_purchase_price']; + } } return $purchases; @@ -527,7 +532,7 @@ class AdminStatsControllerCore extends AdminStatsTabController { if ($granularity == 'day') { $refunds = array(); - $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' + if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT LEFT(`invoice_date`, 10) as date, SUM(orr.`refunded_amount`) as total_refund_amount @@ -540,10 +545,11 @@ class AdminStatsControllerCore extends AdminStatsTabController FROM `qlo_htl_booking_detail` hbd WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).' ) - GROUP BY LEFT(`invoice_date`, 10)'); + GROUP BY LEFT(`invoice_date`, 10)')) { - foreach ($result as $row) { - $refunds[strtotime($row['date'])] = $row['total_refund_amount']; + foreach ($result as $row) { + $refunds[strtotime($row['date'])] = $row['total_refund_amount']; + } } return $refunds;