From 1cf431bb2245089e195577b09bb5196b477e7dd1 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Thu, 4 Jan 2018 16:23:18 +0100 Subject: [PATCH] Complete refund details --- cron_export_sales_monthly_test.php | 33 +++++++++++++++++++----------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/cron_export_sales_monthly_test.php b/cron_export_sales_monthly_test.php index 71e1a81..9c3cb4e 100644 --- a/cron_export_sales_monthly_test.php +++ b/cron_export_sales_monthly_test.php @@ -554,31 +554,40 @@ 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.`product_quantity_refunded` > 0 AND d.`id_order`='.(int) $slip['id_order'] + ); // 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); + ); + $realrefund = array(); + foreach ($refund_details as $r) { + $realrefund[] = $r['id_order_detail']; + } // Clean order_details foreach ($order_details as $k => $od) { - if (!in_array($od['id_order_detail'], $realrefund)) { + if (in_array($od['id_order_detail'], $realrefund)) { + if ($optVerbose) { + echo date('Y-m-d H:i:s')." - Refund detail"."\n"; + } + } else { unset($order_details[$k]); } } } - // No case, product mark refunded + // No case, get line 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']; + foreach ($order_details as $k => $detail) { + if ($detail['product_quantity_refunded'] == 0) { + unset($order_details[$k]); + } } } }