diff --git a/cron_export_sales_monthly_test.php b/cron_export_sales_monthly_test.php index ae94f70..71e1a81 100644 --- a/cron_export_sales_monthly_test.php +++ b/cron_export_sales_monthly_test.php @@ -554,14 +554,32 @@ if($slipNb > 0) { if ($optVerbose) { echo date('Y-m-d H:i:s')." - Order slip with no detail"."\n"; } - $order_details = Db::getInstance()->ExecuteS(' - SELECT d.*, p.`wholesale_price` - FROM `'._DB_PREFIX_.'order_detail` d - LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = d.`product_id`) - WHERE d.id_order='.(int) $slip['id_order']); - // In case details is not present, we suppose we have all products refund - foreach ($order_details as $k => $details) { - $order_details[$k]['product_quantity_refunded'] = $order_details[$k]['product_quantity']; + // Paybox refund + if (strtolower($order['payment']) == 'paybox') { + $refund_details = Db::getInstance()->executeS(' + SELECT r.`id_order_detail` + FROM `'._DB_PREFIX_.'refund_transaction` r + WHERE r.`id_order` = '. (int) $slip['id_order'] + ); + $realrefund = array_values($refund_details); + // Clean order_details + foreach ($order_details as $k => $od) { + if (!in_array($od['id_order_detail'], $realrefund)) { + unset($order_details[$k]); + } + } + } + // No case, product mark refunded + else { + $order_details = Db::getInstance()->ExecuteS(' + SELECT d.*, p.`wholesale_price` + FROM `'._DB_PREFIX_.'order_detail` d + LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = d.`product_id`) + WHERE d.`product_quantity_refunded` > 0 AND d.`id_order`='.(int) $slip['id_order'] + ); + foreach ($order_details as $k => $details) { + $order_details[$k]['product_quantity_refunded'] = $order_details[$k]['product_quantity']; + } } }