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 80df5f94a..0f967e0b6 100755 --- a/packages/Webkul/Admin/src/Resources/lang/en/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php @@ -413,6 +413,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..70c99ea9c 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 @@ -303,7 +303,7 @@ -
- + @{{ errors.first('refund[shipping]') }} diff --git a/packages/Webkul/Admin/src/Resources/views/sales/refunds/view.blade.php b/packages/Webkul/Admin/src/Resources/views/sales/refunds/view.blade.php index c3e91847d..42cd3d78d 100755 --- a/packages/Webkul/Admin/src/Resources/views/sales/refunds/view.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/sales/refunds/view.blade.php @@ -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..dda4f4815 100755 --- a/packages/Webkul/Sales/src/Models/Order.php +++ b/packages/Webkul/Sales/src/Models/Order.php @@ -40,7 +40,7 @@ class Order extends Model implements OrderContract */ public function getBaseTotalDueAttribute() { - return $this->base_grand_total - $this->base_grand_total_invoiced; + return $this->base_grand_total - $this->base_grand_total_invoiced - $this->base_discount_amount; } /** @@ -48,7 +48,7 @@ class Order extends Model implements OrderContract */ public function getTotalDueAttribute() { - return $this->grand_total - $this->grand_total_invoiced; + return $this->grand_total - $this->grand_total_invoiced - $this->discount_amount; } /** @@ -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/RefundRepository.php b/packages/Webkul/Sales/src/Repositories/RefundRepository.php index 505daf786..3f792a32d 100644 --- a/packages/Webkul/Sales/src/Repositories/RefundRepository.php +++ b/packages/Webkul/Sales/src/Repositories/RefundRepository.php @@ -180,29 +180,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();