Testing issues resolve and flow testing

This commit is contained in:
Sumit Panwar
2025-03-22 18:17:50 +05:30
parent 5265247e16
commit 9323f3b8ce
124 changed files with 4959 additions and 5681 deletions

View File

@@ -226,14 +226,24 @@ class AdminStatsControllerCore extends AdminStatsTabController
if ($granularity == 'day') {
$sales = array();
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
'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
WHERE os.logable = 1'. (($date_from && $date_to) ? ' AND `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"' : '').'
AND EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
AND (
EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
) OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel, 'spod').'
)'.(!$id_hotel ? ' OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order` AND spod.`id_hotel` = 0 AND spod.`id_htl_booking_detail` = 0
)' : '').'
)
GROUP BY LEFT(`invoice_date`, 10)'
)) {
@@ -249,10 +259,20 @@ class AdminStatsControllerCore extends AdminStatsTabController
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE os.logable = 1'. (($date_from && $date_to) ? ' AND `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"' : '').'
AND EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
AND (
EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
) OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel, 'spod').'
)'.(!$id_hotel ? ' OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order` AND spod.`id_hotel` = 0 AND spod.`id_htl_booking_detail` = 0
)' : '').'
)
GROUP BY LEFT(`invoice_date`, 7)'
)) {
@@ -260,7 +280,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
foreach ($result as $row) {
$sales[strtotime($row['date'].'-01')] = $row['sales'];
}
}
}
return $sales;
} else {
@@ -273,8 +293,22 @@ class AdminStatsControllerCore extends AdminStatsTabController
FROM`'._DB_PREFIX_.'htl_booking_detail` hbd
GROUP BY hbd.`id_order`
) t ON (t.`id_order` = o.`id_order`)
WHERE os.logable = 1'. (($date_from && $date_to) ? ' AND `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"' : '').
HotelBranchInformation::addHotelRestriction($id_hotel)
WHERE os.logable = 1'. (($date_from && $date_to) ? ' AND `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"' : '').'
AND (
EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
) OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel, 'spod').'
)'.(!$id_hotel ? ' OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order` AND spod.`id_hotel` = 0 AND spod.`id_htl_booking_detail` = 0
)' : '').'
)'
);
}
}
@@ -304,8 +338,22 @@ class AdminStatsControllerCore extends AdminStatsTabController
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`)
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').'
'.Shop::addSqlRestriction(false, 'o').'
AND (
EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
) OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel, 'spod').'
)'.(!$id_hotel ? ' OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order` AND spod.`id_hotel` = 0 AND spod.`id_htl_booking_detail` = 0
)' : '').'
)
GROUP BY LEFT(`invoice_date`, 10)')) {
foreach ($result as $row) {
$orders[strtotime($row['date'])] = $row['orders'];
@@ -320,8 +368,22 @@ class AdminStatsControllerCore extends AdminStatsTabController
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`)
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').'
'.Shop::addSqlRestriction(false, 'o').'
AND (
EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
) OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel, 'spod').'
)'.(!$id_hotel ? ' OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order` AND spod.`id_hotel` = 0 AND spod.`id_htl_booking_detail` = 0
)' : '').'
)
GROUP BY LEFT(`invoice_date`, 7)')) {
foreach ($result as $row) {
$orders[strtotime($row['date'].'-01')] = $row['orders'];
@@ -333,10 +395,23 @@ class AdminStatsControllerCore extends AdminStatsTabController
SELECT 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
LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`)
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'));
'.Shop::addSqlRestriction(false, 'o').'
AND (
EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
) OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel, 'spod').'
)'.(!$id_hotel ? ' OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order` AND spod.`id_hotel` = 0 AND spod.`id_htl_booking_detail` = 0
)' : '').'
)');
}
return $orders;
@@ -485,20 +560,26 @@ class AdminStatsControllerCore extends AdminStatsTabController
od.`purchase_supplier_price` > 0,
od.`purchase_supplier_price`,
(od.`original_product_price` / `conversion_rate`) * '.(int)Configuration::get('CONF_AVERAGE_PRODUCT_MARGIN').' / 100
)) as total_purchase_price,
(
SELECT hbd.`id_hotel`
FROM`'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order` LIMIT 1
) AS id_hotel
)) as total_purchase_price
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"
AND os.logable = 1 AND EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
AND os.logable = 1
AND (
EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
) OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel, 'spod').'
)'.(!$id_hotel ? ' OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order` AND spod.`id_hotel` = 0 AND spod.`id_htl_booking_detail` = 0
)' : '').'
)
GROUP BY LEFT(`invoice_date`, 10)')) {
@@ -519,10 +600,21 @@ class AdminStatsControllerCore extends AdminStatsTabController
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"
AND os.logable = 1 AND EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
AND os.logable = 1
AND (
EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
) OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel, 'spod').'
)'.(!$id_hotel ? ' OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order` AND spod.`id_hotel` = 0 AND spod.`id_htl_booking_detail` = 0
)' : '').'
)'
);
}
@@ -540,10 +632,21 @@ class AdminStatsControllerCore extends AdminStatsTabController
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"
AND "'.pSQL($date_to).' 23:59:59" AND EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
AND "'.pSQL($date_to).' 23:59:59"
AND (
EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
) OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel, 'spod').'
)'.(!$id_hotel ? ' OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order` AND spod.`id_hotel` = 0 AND spod.`id_htl_booking_detail` = 0
)' : '').'
)
GROUP BY LEFT(`invoice_date`, 10)')) {
@@ -566,10 +669,20 @@ class AdminStatsControllerCore extends AdminStatsTabController
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (o.current_state = os.id_order_state)
WHERE orr.`payment_mode` != "" AND orr.`id_transaction` != ""
AND `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"
AND EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
AND (
EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
) OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel, 'spod').'
)'.(!$id_hotel ? ' OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order` AND spod.`id_hotel` = 0 AND spod.`id_htl_booking_detail` = 0
)' : '').'
)'
);
}
@@ -580,24 +693,35 @@ class AdminStatsControllerCore extends AdminStatsTabController
$expenses = ($granularity == 'day' ? array() : 0);
$orders = Db::getInstance()->ExecuteS('
SELECT
LEFT(`invoice_date`, 10) as date,
total_paid_tax_incl / o.conversion_rate as total_paid_tax_incl,
total_shipping_tax_excl / o.conversion_rate as total_shipping_tax_excl,
o.module,
ad.id_country,
o.id_currency,
c.id_reference as carrier_reference,
(
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
LEFT JOIN `'._DB_PREFIX_.'address` ad ON o.id_address_delivery = ad.id_address
LEFT JOIN `'._DB_PREFIX_.'carrier` c ON o.id_carrier = c.id_carrier
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 HAVING 1'.HotelBranchInformation::addHotelRestriction($id_hotel));
SELECT
LEFT(`invoice_date`, 10) as date,
total_paid_tax_incl / o.conversion_rate as total_paid_tax_incl,
total_shipping_tax_excl / o.conversion_rate as total_shipping_tax_excl,
o.module,
ad.id_country,
o.id_currency,
c.id_reference as carrier_reference
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'address` ad ON o.id_address_delivery = ad.id_address
LEFT JOIN `'._DB_PREFIX_.'carrier` c ON o.id_carrier = c.id_carrier
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON o.current_state = os.id_order_state
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" AND os.logable = 1 HAVING 1
AND (
EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
WHERE hbd.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel).'
) OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order`' . HotelBranchInformation::addHotelRestriction($id_hotel, 'spod').'
)'.(!$id_hotel ? ' OR EXISTS (
SELECT 1
FROM `'._DB_PREFIX_.'service_product_order_detail` spod
WHERE spod.`id_order` = o.`id_order` AND spod.`id_hotel` = 0 AND spod.`id_htl_booking_detail` = 0
)' : '').'
)'
);
foreach ($orders as $order) {
// Add flat fees for this order
@@ -1634,7 +1758,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
$totalServicesRevenue = 0;
// Calculate services revenue
$servicesRevenueSql = 'SELECT SUM((rtspod.`total_price_tax_excl` / o.`conversion_rate`) / DATEDIFF(hbd.`date_to`, hbd.`date_from`))
FROM `'._DB_PREFIX_.'htl_room_type_service_product_order_detail` rtspod
FROM `'._DB_PREFIX_.'service_product_order_detail` rtspod
LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd
ON (rtspod.`id_htl_booking_detail` = hbd.`id`)
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hbd.`id_product`)
@@ -2124,7 +2248,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
THEN ((od.`original_product_price` / o.`conversion_rate`) * '.(int)Configuration::get('CONF_AVERAGE_PRODUCT_MARGIN').' / 100) / (IF (od.`product_price_calculation_method` = '.Product::PRICE_CALCULATION_METHOD_PER_BOOKING.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1))
END
), 0)
FROM `'._DB_PREFIX_.'htl_room_type_service_product_order_detail` rtspod
FROM `'._DB_PREFIX_.'service_product_order_detail` rtspod
LEFT JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd
ON (rtspod.`id_htl_booking_detail` = hbd.`id`)
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = rtspod.`id_product`)