diff --git a/admin-dev/themes/default/template/controllers/orders/_product_line.tpl b/admin-dev/themes/default/template/controllers/orders/_product_line.tpl
index 1cbfa25a6..65dd0a725 100755
--- a/admin-dev/themes/default/template/controllers/orders/_product_line.tpl
+++ b/admin-dev/themes/default/template/controllers/orders/_product_line.tpl
@@ -96,8 +96,10 @@
{/if}
- {l s='Quantity:'} 0/{$productQuantity-$product['product_quantity_refunded']}
- {l s='Amount:'} €
+ {l s='Quantity:'} 0/{$productQuantity-$product['product_quantity_refunded']}
+ {l s='Amount:'} € ({l s='%s refund' sprintf=$product['amount_refund']})
+
+
|
{if ($can_edit && !$order->hasBeenDelivered())}
diff --git a/classes/order/OrderSlip.php b/classes/order/OrderSlip.php
index 2f8b0af69..320164a7e 100644
--- a/classes/order/OrderSlip.php
+++ b/classes/order/OrderSlip.php
@@ -141,6 +141,14 @@ class OrderSlipCore extends ObjectModel
}
return $order->getProducts($resTab);
}
+
+ public static function getProductSlipResume($id_order_detail)
+ {
+ return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
+ SELECT SUM(product_quantity) product_quantity, SUM(amount_tax_excl) amount_tax_excl, SUM(amount_tax_incl) amount_tax_incl
+ FROM `'._DB_PREFIX_.'order_slip_detail`
+ WHERE `id_order_detail` = '.(int)$id_order_detail);
+ }
public function getProducts()
{
@@ -212,6 +220,18 @@ class OrderSlipCore extends ObjectModel
{
foreach ($order_detail_list as $id_order_detail => $tab)
{
+ $order_detail = new OrderDetail($id_order_detail);
+ $order_slip_resume = self::getProductSlipResume($id_order_detail);
+
+ if ($tab['amount'] + $order_slip_resume['amount_tax_incl'] > $order_detail->total_price_tax_incl)
+ $tab['amount'] = $order_detail->total_price_tax_incl - $order_slip_resume['amount_tax_incl'];
+
+ if ($tab['amount'] == 0)
+ continue;
+
+ if ($tab['quantity'] + $order_slip_resume['product_quantity'] > $order_detail->product_quantity)
+ $tab['quantity'] = $order_detail->product_quantity - $order_slip_resume['product_quantity'];
+
$tab['amount_tax_excl'] = $tab['amount_tax_incl'] = $tab['amount'];
$id_tax = (int)Db::getInstance()->getValue('SELECT `id_tax` FROM `'._DB_PREFIX_.'order_detail_tax` WHERE `id_order_detail` = '.(int)$id_order_detail);
if ($id_tax > 0)
@@ -224,6 +244,12 @@ class OrderSlipCore extends ObjectModel
}
}
+ if ($tab['quantity'] > 0 && $tab['quantity'] > $order_detail->product_quantity_refunded)
+ {
+ $order_detail->product_quantity_refunded = $tab['quantity'];
+ $order_detail->save();
+ }
+
$insertOrderSlip = array(
'id_order_slip' => (int)($this->id),
'id_order_detail' => (int)($id_order_detail),
@@ -231,6 +257,7 @@ class OrderSlipCore extends ObjectModel
'amount_tax_excl' => (float)($tab['amount_tax_excl']),
'amount_tax_incl' => (float)($tab['amount_tax_incl']),
);
+
Db::getInstance()->insert('order_slip_detail', $insertOrderSlip);
}
}
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index 731975fd0..c0f4c42ce 100755
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -454,16 +454,22 @@ class AdminOrdersControllerCore extends AdminController
$amount = 0;
$order_detail_list = array();
foreach ($_POST['partialRefundProduct'] as $id_order_detail => $amount_detail)
- if (isset($amount_detail) && !empty($amount_detail))
+ {
+ $order_detail_list[$id_order_detail]['quantity'] = (int)$_POST['partialRefundProductQuantity'][$id_order_detail];
+
+ if (empty($amount_detail))
{
- $amount += $amount_detail;
- $order_detail_list[$id_order_detail]['quantity'] = (int)$_POST['partialRefundProductQuantity'][$id_order_detail];
- $order_detail_list[$id_order_detail]['amount'] = (float)$amount_detail;
+ $orderDetail = new OrderDetail($id_order_detail);
+ $order_detail_list[$id_order_detail]['amount'] = $orderDetail->unit_price_tax_incl * $order_detail_list[$id_order_detail]['quantity'];
}
+ else
+ $order_detail_list[$id_order_detail]['amount'] = (float)$amount_detail;
+ $amount += $order_detail_list[$id_order_detail]['amount'];
+ }
$shipping_cost_amount = (float)Tools::getValue('partialRefundShippingCost');
if ($shipping_cost_amount > 0)
$amount += $shipping_cost_amount;
-
+
if ($amount > 0)
{
if (!OrderSlip::createPartialOrderSlip($order, $amount, $shipping_cost_amount, $order_detail_list))
@@ -1221,6 +1227,12 @@ class AdminOrdersControllerCore extends AdminController
foreach ($products as &$product)
{
$product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], $product['id_shop']);
+
+ $resume = OrderSlip::getProductSlipResume($product['id_order_detail']);
+ $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity'];
+ $product['amount_refundable'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl'];
+ $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl']);
+
// if the current stock requires a warning
if ($product['current_stock'] == 0 && $display_out_of_stock_warning)
$this->displayWarning($this->l('This product is out of stock: ').' '.$product['product_name']);
diff --git a/controllers/admin/AdminStockManagementController.php b/controllers/admin/AdminStockManagementController.php
index ffb342f85..aec30adf1 100644
--- a/controllers/admin/AdminStockManagementController.php
+++ b/controllers/admin/AdminStockManagementController.php
@@ -289,8 +289,8 @@ class AdminStockManagementControllerCore extends AdminController
'required' => true,
'options' => array(
'query' => StockMvtReason::getStockMvtReasonsWithFilter($this->context->language->id,
- array(Configuration::get('PS_STOCK_MVT_TRANSFER_TO')),
- 1),
+ array(Configuration::get('PS_STOCK_MVT_TRANSFER_TO')),
+ 1),
'id' => 'id_stock_mvt_reason',
'name' => 'name'
),
@@ -398,8 +398,8 @@ class AdminStockManagementControllerCore extends AdminController
'required' => true,
'options' => array(
'query' => StockMvtReason::getStockMvtReasonsWithFilter($this->context->language->id,
- array(Configuration::get('PS_STOCK_MVT_TRANSFER_FROM')),
- -1),
+ array(Configuration::get('PS_STOCK_MVT_TRANSFER_FROM')),
+ -1),
'id' => 'id_stock_mvt_reason',
'name' => 'name'
),
diff --git a/js/admin_order.js b/js/admin_order.js
index 2195c1675..4bd9b9686 100644
--- a/js/admin_order.js
+++ b/js/admin_order.js
@@ -870,4 +870,13 @@ $(document).ready(function() {
});
});
-
+function checkPartialRefundProductQuantity(it)
+{
+ if (parseInt($(it).val()) > parseInt($(it).parent().parent().find('.partialRefundProductQuantity').val()))
+ $(it).val($(it).parent().parent().find('.partialRefundProductQuantity').val());
+}
+function checkPartialRefundProductAmount(it)
+{
+ if (parseInt($(it).val()) > parseInt($(it).parent().parent().find('.partialRefundProductAmount').val()))
+ $(it).val($(it).parent().parent().find('.partialRefundProductAmount').val());
+}
\ No newline at end of file
|