51 lines
2.1 KiB
PHP
51 lines
2.1 KiB
PHP
<?php
|
|
class OrderReturn extends OrderReturnCore
|
|
{
|
|
public static function getOrderDetailReturnQty($product, $id_state = 0)
|
|
{
|
|
$qty = 0;
|
|
|
|
// Get quantity from shipping details
|
|
if(Db::getInstance()->getRow('
|
|
SELECT `id_order`
|
|
FROM `'._DB_PREFIX_.'shipping_history`
|
|
WHERE `id_order` = '.(int) $product['id_order'].'
|
|
AND `id_sale` = '.(int) $product['id_sale'].'
|
|
') || ($id_state != 0 && $id_state == 4)) {
|
|
$qty = (int) $product['product_quantity'] - max((int) $product['product_quantity_refunded'], (int) $product['product_quantity_return']);
|
|
} else {
|
|
$qty = (int) Db::getInstance()->getValue('
|
|
SELECT SUM(`quantity`)
|
|
FROM `'._DB_PREFIX_.'lapostews`
|
|
WHERE `id_order_detail` = '.(int) $product['id_order_detail'].'
|
|
') + (int) Db::getInstance()->getValue('
|
|
SELECT SUM(`quantity`)
|
|
FROM `'._DB_PREFIX_.'mondialrelay_parcel`
|
|
WHERE `id_order_detail` = '.(int) $product['id_order_detail'].'
|
|
') + (int) Db::getInstance()->getValue('
|
|
SELECT SUM(`quantity`)
|
|
FROM `'._DB_PREFIX_.'philea_parcel`
|
|
WHERE `id_order_detail` = '.(int) $product['id_order_detail'].'
|
|
') - max($product['product_quantity_return'], $product['product_quantity_refunded']);
|
|
}
|
|
|
|
// Use order quantity as fallback
|
|
if ($qty == 0 && $id_state > 3) {
|
|
$qty = (int) $product['product_quantity'] - max((int) $product['product_quantity_refunded'], (int) $product['product_quantity_return']);
|
|
}
|
|
|
|
// Remove product quantity mark as return
|
|
$qty -= (int) Db::getInstance()->getValue('
|
|
SELECT SUM(d.`product_quantity`)
|
|
FROM `'._DB_PREFIX_.'order_return_detail` d
|
|
LEFT JOIN `'._DB_PREFIX_.'order_return` r
|
|
ON d.`id_order_return` = r.`id_order_return`
|
|
WHERE d.`id_order_detail` = '.(int) $product['id_order_detail'].'
|
|
AND r.`state` < 3
|
|
');
|
|
|
|
return $qty;
|
|
}
|
|
}
|
|
|