diff --git a/packages/Webkul/Admin/src/Http/Controllers/Sales/RefundController.php b/packages/Webkul/Admin/src/Http/Controllers/Sales/RefundController.php
index 669965513..47a891a25 100755
--- a/packages/Webkul/Admin/src/Http/Controllers/Sales/RefundController.php
+++ b/packages/Webkul/Admin/src/Http/Controllers/Sales/RefundController.php
@@ -115,10 +115,16 @@ class RefundController extends Controller
$totals = $this->refundRepository->getOrderItemsRefundSummary($data['refund']['items'], $orderId);
- $maxRefundAmount = $totals['grand_total']['price'] - $order->refunds()->sum('base_adjustment_refund') + $order->refunds()->sum('base_adjustment_fee');
+ $maxRefundAmount = $totals['grand_total']['price'] - $order->refunds()->sum('base_adjustment_refund');
$refundAmount = $totals['grand_total']['price'] - $totals['shipping']['price'] + $data['refund']['shipping'] + $data['refund']['adjustment_refund'] - $data['refund']['adjustment_fee'];
+ if (! $refundAmount) {
+ session()->flash('error', trans('admin::app.sales.refunds.invalid-refund-amount-error'));
+
+ return redirect()->back();
+ }
+
if ($refundAmount > $maxRefundAmount) {
session()->flash('error', trans('admin::app.sales.refunds.refund-limit-error', ['amount' => core()->formatBasePrice($maxRefundAmount)]));
diff --git a/packages/Webkul/Admin/src/Resources/lang/ar/app.php b/packages/Webkul/Admin/src/Resources/lang/ar/app.php
index a0bc2885f..5fb8f1497 100644
--- a/packages/Webkul/Admin/src/Resources/lang/ar/app.php
+++ b/packages/Webkul/Admin/src/Resources/lang/ar/app.php
@@ -350,7 +350,9 @@ return [
'date' => 'Refund Date',
'customer-name' => 'Customer Name',
'status' => 'Status',
- 'action' => 'Action'
+ 'action' => 'Action',
+ 'view-title' => 'Refund #:refund_id',
+ 'invalid-refund-amount-error' => 'Refund amount should be non zero.'
]
],
'catalog' => [
diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php
index 9b8f5c95b..3d47aed68 100755
--- a/packages/Webkul/Admin/src/Resources/lang/en/app.php
+++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php
@@ -414,6 +414,8 @@ return [
'status' => 'Status',
'action' => 'Action',
'view-title' => 'Refund #:refund_id',
+ 'invalid-refund-amount-error' => 'Refund amount should be non zero.'
+
]
],
diff --git a/packages/Webkul/Admin/src/Resources/lang/fa/app.php b/packages/Webkul/Admin/src/Resources/lang/fa/app.php
index efa6f4ecf..0e7f0953b 100644
--- a/packages/Webkul/Admin/src/Resources/lang/fa/app.php
+++ b/packages/Webkul/Admin/src/Resources/lang/fa/app.php
@@ -377,7 +377,9 @@ return [
'date' => 'Refund Date',
'customer-name' => 'Customer Name',
'status' => 'Status',
- 'action' => 'Action'
+ 'action' => 'Action',
+ 'view-title' => 'Refund #:refund_id',
+ 'invalid-refund-amount-error' => 'Refund amount should be non zero.'
]
],
diff --git a/packages/Webkul/Admin/src/Resources/lang/pt_BR/app.php b/packages/Webkul/Admin/src/Resources/lang/pt_BR/app.php
index 547534691..4b9a31102 100755
--- a/packages/Webkul/Admin/src/Resources/lang/pt_BR/app.php
+++ b/packages/Webkul/Admin/src/Resources/lang/pt_BR/app.php
@@ -358,7 +358,9 @@ return [
'date' => 'Refund Date',
'customer-name' => 'Customer Name',
'status' => 'Status',
- 'action' => 'Action'
+ 'action' => 'Action',
+ 'view-title' => 'Refund #:refund_id',
+ 'invalid-refund-amount-error' => 'Refund amount should be non zero.'
]
],
'catalog' => [
diff --git a/packages/Webkul/Admin/src/Resources/views/sales/refunds/create.blade.php b/packages/Webkul/Admin/src/Resources/views/sales/refunds/create.blade.php
index 216393cf7..e28fcbbd2 100755
--- a/packages/Webkul/Admin/src/Resources/views/sales/refunds/create.blade.php
+++ b/packages/Webkul/Admin/src/Resources/views/sales/refunds/create.blade.php
@@ -43,7 +43,7 @@
- #{{ $order->id }}
+ #{{ $order->increment_id }}
@@ -303,7 +303,7 @@
- |
@@ -213,9 +213,7 @@
| {{ __('admin::app.sales.orders.qty') }} |
{{ __('admin::app.sales.orders.subtotal') }} |
{{ __('admin::app.sales.orders.tax-amount') }} |
- @if ($refund->base_discount_amount > 0)
- {{ __('admin::app.sales.orders.discount-amount') }} |
- @endif
+ {{ __('admin::app.sales.orders.discount-amount') }} |
{{ __('admin::app.sales.orders.grand-total') }} |
@@ -242,14 +240,18 @@
{{ core()->formatBasePrice($item->base_tax_amount) }} |
- @if ($refund->base_discount_amount > 0)
- {{ core()->formatBasePrice($item->base_discount_amount) }} |
- @endif
+ {{ core()->formatBasePrice($item->base_discount_amount) }} |
{{ core()->formatBasePrice($item->base_total + $item->base_tax_amount - $item->base_discount_amount) }} |
@endforeach
+ @if (! $refund->items->count())
+
+ | {{ __('admin::app.common.no-result-found') }} |
+
+ @endif
+
diff --git a/packages/Webkul/Sales/src/Models/Order.php b/packages/Webkul/Sales/src/Models/Order.php
index 98f882c6a..e3907ba6f 100755
--- a/packages/Webkul/Sales/src/Models/Order.php
+++ b/packages/Webkul/Sales/src/Models/Order.php
@@ -208,7 +208,7 @@ class Order extends Model implements OrderContract
return true;
}
- if ($this->base_grand_total_invoiced - $this->base_grand_total_refunded > 0)
+ if ($this->base_grand_total_invoiced - $this->base_grand_total_refunded - $this->refunds()->sum('base_adjustment_fee') > 0)
return true;
return false;
diff --git a/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php b/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php
index 9c60c59d0..041f84ddc 100755
--- a/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php
+++ b/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php
@@ -98,9 +98,7 @@ class InvoiceRepository extends Repository
'base_currency_code' => $order->base_currency_code,
'channel_currency_code' => $order->channel_currency_code,
'order_currency_code' => $order->order_currency_code,
- 'order_address_id' => $order->billing_address->id,
- "discount_amount" => $order->discount_amount,
- "base_discount_amount" => $order->base_discount_amount,
+ 'order_address_id' => $order->billing_address->id
]);
foreach ($data['invoice']['items'] as $itemId => $qty) {
@@ -174,49 +172,40 @@ class InvoiceRepository extends Repository
return $invoice;
}
-
+
/**
* @param mixed $invoice
* @return mixed
*/
public function collectTotals($invoice)
{
- $subTotal = $baseSubTotal = 0;
- $taxAmount = $baseTaxAmount = 0;
- $discountAmount = $baseDiscountAmount = 0;
+ $invoice->sub_total = $invoice->base_sub_total = 0;
+ $invoice->tax_amount = $invoice->base_tax_amount = 0;
+ $invoice->discount_amount = $invoice->base_discount_amount = 0;
foreach ($invoice->items as $invoiceItem) {
- $subTotal += $invoiceItem->total;
- $baseSubTotal += $invoiceItem->base_total;
+ $invoice->sub_total += $invoiceItem->total;
+ $invoice->base_sub_total += $invoiceItem->base_total;
- $taxAmount += $invoiceItem->tax_amount;
- $baseTaxAmount += $invoiceItem->base_tax_amount;
+ $invoice->tax_amount += $invoiceItem->tax_amount;
+ $invoice->base_tax_amount += $invoiceItem->base_tax_amount;
- $discountAmount += $invoiceItem->discount_amount;
- $baseDiscountAmount += $invoiceItem->base_discount_amount;
+ $invoice->discount_amount += $invoiceItem->discount_amount;
+ $invoice->base_discount_amount += $invoiceItem->base_discount_amount;
}
- $shippingAmount = $invoice->order->shipping_amount;
- $baseShippingAmount = $invoice->order->base_shipping_amount;
+ $invoice->shipping_amount = $invoice->order->shipping_amount;
+ $invoice->base_shipping_amount = $invoice->order->base_shipping_amount;
if ($invoice->order->shipping_amount) {
foreach ($invoice->order->invoices as $prevInvoice) {
if ((float) $prevInvoice->shipping_amount)
- $shippingAmount = $baseShippingAmount = 0;
+ $invoice->shipping_amount = $invoice->base_shipping_amount = 0;
}
}
- $invoice->sub_total = $subTotal;
- $invoice->base_sub_total = $baseSubTotal;
-
- $invoice->shipping_amount = $shippingAmount;
- $invoice->base_shipping_amount = $baseShippingAmount;
-
- $invoice->tax_amount = $taxAmount;
- $invoice->base_tax_amount = $baseTaxAmount;
-
- $invoice->grand_total = $subTotal + $taxAmount + $shippingAmount - $discountAmount;
- $invoice->base_grand_total = $baseSubTotal + $baseTaxAmount + $baseShippingAmount - $baseDiscountAmount;
+ $invoice->grand_total = $invoice->sub_total + $invoice->tax_amount + $invoice->shipping_amount - $invoice->discount_amount;
+ $invoice->base_grand_total = $invoice->base_sub_total + $invoice->base_tax_amount + $invoice->base_shipping_amount - $invoice->base_discount_amount;
$invoice->save();
diff --git a/packages/Webkul/Sales/src/Repositories/OrderItemRepository.php b/packages/Webkul/Sales/src/Repositories/OrderItemRepository.php
index 0ccd5adb6..bf39afaa2 100755
--- a/packages/Webkul/Sales/src/Repositories/OrderItemRepository.php
+++ b/packages/Webkul/Sales/src/Repositories/OrderItemRepository.php
@@ -135,7 +135,7 @@ class OrderItemRepository extends Repository
/**
* Returns qty to product inventory after order cancelation
*
- * @param mixed $orderItem
+ * @param OrderItem $orderItem
* @return void
*/
public function returnQtyToProductInventory($orderItem)
@@ -150,9 +150,8 @@ class OrderItemRepository extends Repository
if (! $orderedInventory)
return ;
- if (($qty = $orderedInventory->qty - $orderItem->qty_to_cancel) < 0) {
+ if (($qty = $orderedInventory->qty - $quantity) < 0)
$qty = 0;
- }
$orderedInventory->update([
'qty' => $qty
diff --git a/packages/Webkul/Sales/src/Repositories/OrderRepository.php b/packages/Webkul/Sales/src/Repositories/OrderRepository.php
index 86c370d54..16038c95e 100755
--- a/packages/Webkul/Sales/src/Repositories/OrderRepository.php
+++ b/packages/Webkul/Sales/src/Repositories/OrderRepository.php
@@ -265,9 +265,11 @@ class OrderRepository extends Repository
*/
public function collectTotals($order)
{
+ //Order invoice total
$order->sub_total_invoiced = $order->base_sub_total_invoiced = 0;
$order->shipping_invoiced = $order->base_shipping_invoiced = 0;
$order->tax_amount_invoiced = $order->base_tax_amount_invoiced = 0;
+ $order->discount_invoiced = $order->base_discount_invoiced = 0;
foreach ($order->invoices as $invoice) {
$order->sub_total_invoiced += $invoice->sub_total;
@@ -286,7 +288,7 @@ class OrderRepository extends Repository
$order->grand_total_invoiced = $order->sub_total_invoiced + $order->shipping_invoiced + $order->tax_amount_invoiced - $order->discount_invoiced;
$order->base_grand_total_invoiced = $order->base_sub_total_invoiced + $order->base_shipping_invoiced + $order->base_tax_amount_invoiced - $order->base_discount_invoiced;
-
+ //Order refund total
$order->sub_total_refunded = $order->base_sub_total_refunded = 0;
$order->shipping_refunded = $order->base_shipping_refunded = 0;
$order->tax_amount_refunded = $order->base_tax_amount_refunded = 0;
diff --git a/packages/Webkul/Sales/src/Repositories/RefundItemRepository.php b/packages/Webkul/Sales/src/Repositories/RefundItemRepository.php
index 31eaa9405..674f29d5b 100644
--- a/packages/Webkul/Sales/src/Repositories/RefundItemRepository.php
+++ b/packages/Webkul/Sales/src/Repositories/RefundItemRepository.php
@@ -25,4 +25,41 @@ class RefundItemRepository extends Repository
{
return RefundItem::class;
}
+
+ /**
+ * Returns qty to product inventory after order refund
+ *
+ * @param RefundItem $refundItem
+ * @param integer $quantity
+ * @return void
+ */
+ public function returnQtyToProductInventory($refundItem, $quantity)
+ {
+ return;
+ if (! $product = $refundItem->product)
+ return;
+
+ if ($qtyShipped = $refundItem->order_item->qty_shipped) {
+
+ } else {
+
+ }
+
+ $orderedInventory = $product->ordered_inventories()
+ ->where('channel_id', $refundItem->order->channel->id)
+ ->first();
+
+ if ($orderedInventory) {
+
+ } else {
+
+ }
+
+ if (($qty = $orderedInventory->qty - $quantity) < 0)
+ $qty = 0;
+
+ $orderedInventory->update([
+ 'qty' => $qty
+ ]);
+ }
}
\ No newline at end of file
diff --git a/packages/Webkul/Sales/src/Repositories/RefundRepository.php b/packages/Webkul/Sales/src/Repositories/RefundRepository.php
index 505daf786..c7d1e0291 100644
--- a/packages/Webkul/Sales/src/Repositories/RefundRepository.php
+++ b/packages/Webkul/Sales/src/Repositories/RefundRepository.php
@@ -151,6 +151,10 @@ class RefundRepository extends Repository
'product_type' => $childOrderItem->product_type,
'additional' => $childOrderItem->additional
]);
+
+ $this->refundItemRepository->returnQtyToProductInventory($childOrderItem, $qty);
+ } else {
+ $this->refundItemRepository->returnQtyToProductInventory($orderItem, $qty);
}
$this->orderItemRepository->collectTotals($orderItem);
@@ -180,29 +184,23 @@ class RefundRepository extends Repository
*/
public function collectTotals($refund)
{
- $subTotal = $baseSubTotal = 0;
- $taxAmount = $baseTaxAmount = 0;
- $discountAmount = $baseDiscountAmount = 0;
+ $refund->sub_total = $refund->base_sub_total = 0;
+ $refund->tax_amount = $refund->base_tax_amount = 0;
+ $refund->discount_amount = $refund->base_discount_amount = 0;
foreach ($refund->items as $refundItem) {
- $subTotal += $refundItem->total;
- $baseSubTotal += $refundItem->base_total;
+ $refund->sub_total += $refundItem->total;
+ $refund->base_sub_total += $refundItem->base_total;
- $taxAmount += $refundItem->tax_amount;
- $baseTaxAmount += $refundItem->base_tax_amount;
+ $refund->tax_amount += $refundItem->tax_amount;
+ $refund->base_tax_amount += $refundItem->base_tax_amount;
- $discountAmount += $refundItem->discount_amount;
- $baseDiscountAmount += $refundItem->base_discount_amount;
+ $refund->discount_amount += $refundItem->discount_amount;
+ $refund->base_discount_amount += $refundItem->base_discount_amount;
}
- $refund->sub_total = $subTotal;
- $refund->base_sub_total = $baseSubTotal;
-
- $refund->tax_amount = $taxAmount;
- $refund->base_tax_amount = $baseTaxAmount;
-
- $refund->grand_total = $subTotal + $taxAmount + $refund->shipping_amount + $refund->adjustment_refund - $refund->adjustment_fee - $discountAmount;
- $refund->base_grand_total = $baseSubTotal + $baseTaxAmount + $refund->base_shipping_amount + $refund->base_adjustment_refund - $refund->adjustment_fee - $baseDiscountAmount;
+ $refund->grand_total = $refund->sub_total + $refund->tax_amount + $refund->shipping_amount + $refund->adjustment_refund - $refund->adjustment_fee - $refund->discount_amount;
+ $refund->base_grand_total = $refund->base_sub_total + $refund->base_tax_amount + $refund->base_shipping_amount + $refund->base_adjustment_refund - $refund->adjustment_fee - $refund->base_discount_amount;
$refund->save();
diff --git a/packages/Webkul/Shop/src/Resources/views/customers/account/orders/view.blade.php b/packages/Webkul/Shop/src/Resources/views/customers/account/orders/view.blade.php
index 86b5dc357..167a34a2b 100755
--- a/packages/Webkul/Shop/src/Resources/views/customers/account/orders/view.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/customers/account/orders/view.blade.php
@@ -68,6 +68,7 @@
|
{{ $item->type == 'configurable' ? $item->child->sku : $item->sku }}
|
+
{{ $item->name }}
@if (isset($item['additional']['attributes']))
@@ -76,7 +77,11 @@
@endforeach
@endif
|
- {{ core()->formatPrice($item->price, $order->order_currency_code) }} |
+
+
+ {{ core()->formatPrice($item->price, $order->order_currency_code) }}
+ |
+
{{ __('shop::app.customer.account.order.view.item-ordered', ['qty_ordered' => $item->qty_ordered]) }}
@@ -98,10 +103,22 @@
{{ $item->qty_canceled ? __('shop::app.customer.account.order.view.item-canceled', ['qty_canceled' => $item->qty_canceled]) : '' }}
|
- {{ core()->formatPrice($item->total, $order->order_currency_code) }} |
- {{ number_format($item->tax_percent, 2) }}% |
- {{ core()->formatPrice($item->tax_amount, $order->order_currency_code) }} |
- {{ core()->formatPrice($item->total + $item->tax_amount, $order->order_currency_code) }} |
+
+
+ {{ core()->formatPrice($item->total, $order->order_currency_code) }}
+ |
+
+
+ {{ number_format($item->tax_percent, 2) }}%
+ |
+
+
+ {{ core()->formatPrice($item->tax_amount, $order->order_currency_code) }}
+ |
+
+
+ {{ core()->formatPrice($item->total + $item->tax_amount - $item->discount_amount, $order->order_currency_code) }}
+ |
@endforeach