Complete refund details

This commit is contained in:
Michael RICOIS 2018-01-04 16:23:18 +01:00
parent d4afb73dba
commit 1cf431bb22

View File

@ -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]);
}
}
}
}