Skip to content

Commit

Permalink
[-] BO : Fix #PSCFV-11428 choose to refund voucher
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha Froment committed Oct 21, 2014
1 parent 5358b6c commit 7c5d1e7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@
statesShipped.push({$state['id_order_state']});
{/if}
{/foreach}
var order_discount_price = {if ($order->getTaxCalculationMethod() == $smarty.const.PS_TAX_EXC)}
{$order->total_discounts_tax_excl}
{else}
{$order->total_discounts_tax_incl}
{/if};
var okButton = "{l s='Yes'}";
var cancelButton = "{l s='No'}";
var alertTitle = "{l s='Voucher refund'}";
var alertMsg = "{l s='Do you want to refund the voucher?'}";
</script>

{assign var="hook_invoice" value={hook h="displayInvoice" id_order=$order->id}}
Expand Down
11 changes: 10 additions & 1 deletion controllers/admin/AdminOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ public function postProcess()
$this->reinjectQuantity($order_detail, $order_detail_list[$id_order_detail]['quantity']);
}

if (Tools::isSubmit('refund_voucher_off'))
$amount -= Tools::getValue('order_discount_price');

$shipping_cost_amount = (float)str_replace(',', '.', Tools::getValue('partialRefundShippingCost'));
if ($shipping_cost_amount > 0)
$amount += $shipping_cost_amount;
Expand Down Expand Up @@ -867,14 +870,17 @@ public function postProcess()
if (Tools::isSubmit('generateCreditSlip') && !count($this->errors))
{
$product_list = array();
if (Tools::isSubmit('refund_voucher_off'))
$amount = $order_detail->unit_price_tax_incl * $full_quantity_list[$id_order_detail] - Tools::getValue('order_discount_price');

foreach ($full_product_list as $id_order_detail)
{
$order_detail = new OrderDetail((int)$id_order_detail);
$product_list[$id_order_detail] = array(
'id_order_detail' => $id_order_detail,
'quantity' => $full_quantity_list[$id_order_detail],
'unit_price' => $order_detail->unit_price_tax_excl,
'amount' => $order_detail->unit_price_tax_incl * $full_quantity_list[$id_order_detail],
'amount' => $amount ? $amount : $order_detail->unit_price_tax_incl * $full_quantity_list[$id_order_detail],
);
}

Expand Down Expand Up @@ -935,6 +941,9 @@ public function postProcess()
if (Tools::isSubmit('shippingBack'))
$total += $order->total_shipping;

if (Tools::isSubmit('refund_voucher_off'))
$total -= Tools::getValue('order_discount_price');

$cartrule->reduction_amount = $total;
$cartrule->reduction_tax = true;
$cartrule->minimum_amount_currency = $order->id_currency;
Expand Down
33 changes: 33 additions & 0 deletions js/admin_order.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,24 @@ $(document).ready(function() {
$('.partial_refund_fields').hide();
$('.standard_refund_fields').fadeIn();
}

if (order_discount_price)
$('.container-command-top-spacing').submit(function(e) {
e.preventDefault();
var that = $(this);
$.alerts.okButton= okButton;
$.alerts.cancelButton= cancelButton;
jConfirm(alertMsg, alertTitle, function(confirm){
if (confirm === false) {
that.append('<input type="hidden" name="refund_voucher_off"/>');
that.append('<input type="hidden" name="order_discount_price" value=' + order_discount_price + '/>');
}
that.append('<input type="hidden" name="cancelProduct" value="Refund products"/>');
that.unbind('submit').submit();
});
});
});

$('#desc-order-partial_refund').click(function() {
$('.cancel_product_change_link:visible').trigger('click');
closeAddProduct();
Expand All @@ -871,6 +888,22 @@ $(document).ready(function() {
$('.product_action').hide();
$('.partial_refund_fields').fadeIn();
}

if (order_discount_price)
$('.container-command-top-spacing').submit(function(e) {
e.preventDefault();
var that = $(this);
$.alerts.okButton= okButton;
$.alerts.cancelButton= cancelButton;
jConfirm(alertMsg, alertTitle, function(confirm){
if (confirm === false) {
that.append('<input type="hidden" name="refund_voucher_off"/>');
that.append('<input type="hidden" name="order_discount_price" value=' + order_discount_price + '/>');
}
that.append('<input type="hidden" name="partialRefund"/>');
that.unbind('submit').submit();
});
});
});
});

Expand Down

0 comments on commit 7c5d1e7

Please sign in to comment.