Refund issues fixed

This commit is contained in:
jitendra 2019-09-19 13:52:33 +05:30
parent 84969849d1
commit ccd86eee76
9 changed files with 41 additions and 31 deletions

View File

@ -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)]));

View File

@ -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' => [

View File

@ -413,6 +413,8 @@ return [
'status' => 'Status',
'action' => 'Action',
'view-title' => 'Refund #:refund_id',
'invalid-refund-amount-error' => 'Refund amount should be non zero.'
]
],

View File

@ -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.'
]
],

View File

@ -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' => [

View File

@ -303,7 +303,7 @@
<td>-</td>
<td>
<div class="control-group" :class="[errors.has('refund[shipping]') ? 'has-error' : '']" style="width: 100px; margin-bottom: 0;">
<input type="text" v-validate="'required|min_value:0|max_value:{{$order->base_shipping_invoiced - $order->base_shipping_refunded}}'" class="control" id="refund[shipping]" name="refund[shipping]" :value="refund.summary.shipping.price" data-vv-as="&quot;{{ __('admin::app.sales.refunds.refund-shipping') }}&quot;" style="width: 100%; margin: 0"/>
<input type="text" v-validate="'required|min_value:0|max_value:{{$order->base_shipping_invoiced - $order->base_shipping_refunded}}'" class="control" id="refund[shipping]" name="refund[shipping]" v-model="refund.summary.shipping.price" data-vv-as="&quot;{{ __('admin::app.sales.refunds.refund-shipping') }}&quot;" style="width: 100%; margin: 0"/>
<span class="control-error" v-if="errors.has('refund[shipping]')">
@{{ errors.first('refund[shipping]') }}

View File

@ -213,9 +213,7 @@
<th>{{ __('admin::app.sales.orders.qty') }}</th>
<th>{{ __('admin::app.sales.orders.subtotal') }}</th>
<th>{{ __('admin::app.sales.orders.tax-amount') }}</th>
@if ($refund->base_discount_amount > 0)
<th>{{ __('admin::app.sales.orders.discount-amount') }}</th>
@endif
<th>{{ __('admin::app.sales.orders.discount-amount') }}</th>
<th>{{ __('admin::app.sales.orders.grand-total') }}</th>
</tr>
</thead>
@ -242,14 +240,18 @@
<td>{{ core()->formatBasePrice($item->base_tax_amount) }}</td>
@if ($refund->base_discount_amount > 0)
<td>{{ core()->formatBasePrice($item->base_discount_amount) }}</td>
@endif
<td>{{ core()->formatBasePrice($item->base_discount_amount) }}</td>
<td>{{ core()->formatBasePrice($item->base_total + $item->base_tax_amount - $item->base_discount_amount) }}</td>
</tr>
@endforeach
@if (! $refund->items->count())
<tr>
<td class="empty" colspan="7">{{ __('admin::app.common.no-result-found') }}</td>
<tr>
@endif
</tbody>
</table>
</div>

View File

@ -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;

View File

@ -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();