[-] BO : #PSCFV-139 - Improving Retial refund
This commit is contained in:
@@ -96,8 +96,10 @@
|
||||
{/if}
|
||||
</td>
|
||||
<td class="partial_refund_fields current-edit" style="text-align:left;display:none">
|
||||
<div style="width:40%;margin-top:5px;float:left">{l s='Quantity:'}</div> <div style="width:60%;margin-top:2px;float:left"><input type="text" size="3" name="partialRefundProductQuantity[{{$product['id_order_detail']}}]" value="0" /> 0/{$productQuantity-$product['product_quantity_refunded']}</div>
|
||||
<div style="width:40%;margin-top:5px;float:left">{l s='Amount:'}</div> <div style="width:60%;margin-top:2px;float:left"><input type="text" size="3" name="partialRefundProduct[{$product['id_order_detail']}]" /> €</div>
|
||||
<div style="width:40%;margin-top:5px;float:left">{l s='Quantity:'}</div> <div style="width:60%;margin-top:2px;float:left"><input onchange="checkPartialRefundProductQuantity(this)" type="text" size="3" name="partialRefundProductQuantity[{{$product['id_order_detail']}}]" value="0" /> 0/{$productQuantity-$product['product_quantity_refunded']}</div>
|
||||
<div style="width:40%;margin-top:5px;float:left">{l s='Amount:'}</div> <div style="width:60%;margin-top:2px;float:left"><input onchange="checkPartialRefundProductAmount(this)" type="text" size="3" name="partialRefundProduct[{$product['id_order_detail']}]" /> €</div> ({l s='%s refund' sprintf=$product['amount_refund']})
|
||||
<input type="hidden" value="{$product['quantity_refundable']}" class="partialRefundProductQuantity" />
|
||||
<input type="hidden" value="{$product['amount_refundable']}" class="partialRefundProductAmount" />
|
||||
</td>
|
||||
{if ($can_edit && !$order->hasBeenDelivered())}
|
||||
<td class="product_invoice" colspan="2" style="display: none;text-align:center;">
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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']);
|
||||
|
||||
@@ -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'
|
||||
),
|
||||
|
||||
+10
-1
@@ -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());
|
||||
}
|
||||
Reference in New Issue
Block a user