Fixed: revenue KPI not updating after order refund
Co-authored-by: Name <azharbhat.qlo098@webkul.in>
This commit is contained in:
@@ -644,11 +644,11 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT
|
||||
LEFT(`invoice_date`, 10) as date,
|
||||
SUM(orr.`refunded_amount`) as total_refund_amount
|
||||
SUM(orr.`refunded_amount` * (o.`total_paid_tax_excl` / o.`total_paid_tax_incl`) / o.`conversion_rate`) as total_refund_amount
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_return` orr ON (o.id_order = orr.id_order)
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (o.current_state = os.id_order_state)
|
||||
WHERE orr.`payment_mode` != "" AND `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00"
|
||||
WHERE os.`logable` = 1 AND o.`total_paid_tax_incl` > 0 AND orr.`payment_mode` != "" AND `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00"
|
||||
AND "'.pSQL($date_to).' 23:59:59"
|
||||
AND (
|
||||
EXISTS (
|
||||
@@ -1646,9 +1646,9 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
|
||||
public static function getRevenue($dateFrom, $dateTo, $idHotel = false, $orderSource = '')
|
||||
{
|
||||
$sql = 'SELECT SUM(total_paid_tax_excl - refunded_amount)
|
||||
$sql = 'SELECT SUM(GREATEST(total_paid_tax_excl - refunded_amount, 0))
|
||||
FROM (SELECT o.`total_paid_tax_excl` / o.`conversion_rate` AS total_paid_tax_excl,
|
||||
(SELECT IFNULL(SUM(orr.`refunded_amount`), 0) FROM`'._DB_PREFIX_.'order_return` orr WHERE orr.`id_order` = o.`id_order`) AS refunded_amount,
|
||||
(SELECT IFNULL(SUM(orr.`refunded_amount`), 0) FROM`'._DB_PREFIX_.'order_return` orr WHERE orr.`id_order` = o.`id_order`) * IF(o.`total_paid_tax_incl` > 0, o.`total_paid_tax_excl` / o.`total_paid_tax_incl`, 1) / o.`conversion_rate` AS refunded_amount,
|
||||
(SELECT hbd.`id_hotel` FROM`'._DB_PREFIX_.'htl_booking_detail` hbd WHERE hbd.`id_order` = o.`id_order` LIMIT 1) AS id_hotel
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
|
||||
|
||||
Reference in New Issue
Block a user