|
|
@@ -209,8 +209,49 @@ class RefundRepository extends Repository
|
|
|
$refund->tax_amount += $refund->shipping_tax_amount;
|
|
|
$refund->base_tax_amount += $refund->base_shipping_tax_amount;
|
|
|
|
|
|
- $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->base_adjustment_fee - $refund->base_discount_amount;
|
|
|
+ $order = $refund->order;
|
|
|
+
|
|
|
+ $subtotalRatio = $order->base_sub_total > 0
|
|
|
+ ? $refund->base_sub_total / $order->base_sub_total
|
|
|
+ : 0;
|
|
|
+
|
|
|
+ $shippingRatio = $order->base_shipping_amount > 0
|
|
|
+ ? $refund->base_shipping_amount / $order->base_shipping_amount
|
|
|
+ : 0;
|
|
|
+
|
|
|
+ $giftcardAmount = round($order->giftcard_amount * $subtotalRatio, 2);
|
|
|
+ $baseGiftcardAmount = round($order->base_giftcard_amount * $subtotalRatio, 2);
|
|
|
+
|
|
|
+ $shippingInsuranceAmount = round($order->shipping_insurance_amount * $shippingRatio, 2);
|
|
|
+ $baseShippingInsuranceAmount = round($order->base_shipping_insurance_amount * $shippingRatio, 2);
|
|
|
+
|
|
|
+ $vipPlusAmount = round($order->vip_plus_amount * $subtotalRatio, 2);
|
|
|
+ $baseVipPlusAmount = round($order->base_vip_plus_amount * $subtotalRatio, 2);
|
|
|
+
|
|
|
+ $vipDiscountAmount = round($order->vip_discount_amount * $subtotalRatio, 2);
|
|
|
+ $baseVipDiscountAmount = round($order->base_vip_discount_amount * $subtotalRatio, 2);
|
|
|
+
|
|
|
+ $refund->grand_total = $refund->sub_total
|
|
|
+ + $refund->tax_amount
|
|
|
+ + $refund->shipping_amount
|
|
|
+ + $shippingInsuranceAmount
|
|
|
+ - $giftcardAmount
|
|
|
+ + $vipPlusAmount
|
|
|
+ - $vipDiscountAmount
|
|
|
+ + $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
|
|
|
+ + $baseShippingInsuranceAmount
|
|
|
+ - $baseGiftcardAmount
|
|
|
+ + $baseVipPlusAmount
|
|
|
+ - $baseVipDiscountAmount
|
|
|
+ + $refund->base_adjustment_refund
|
|
|
+ - $refund->base_adjustment_fee
|
|
|
+ - $refund->base_discount_amount;
|
|
|
|
|
|
$refund->save();
|
|
|
|
|
|
@@ -260,7 +301,44 @@ class RefundRepository extends Repository
|
|
|
|
|
|
$totals['shipping']['price'] += $data['shipping'];
|
|
|
|
|
|
- $totals['grand_total']['price'] += $totals['subtotal']['price'] + $totals['tax']['price'] + $totals['shipping']['price'] + $data['adjustment_refund'] - $data['adjustment_fee'] - $totals['discount']['price'];
|
|
|
+ $subtotalRatio = $order->base_sub_total > 0
|
|
|
+ ? $totals['subtotal']['price'] / $order->base_sub_total
|
|
|
+ : 0;
|
|
|
+
|
|
|
+ $shippingRatio = $order->base_shipping_amount > 0
|
|
|
+ ? $data['shipping'] / $order->base_shipping_amount
|
|
|
+ : 0;
|
|
|
+
|
|
|
+ $totals['giftcard'] = [
|
|
|
+ 'price' => round($order->base_giftcard_amount * $subtotalRatio, 2),
|
|
|
+ 'label' => trans('gift::app.giftcard.giftcard_amount'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $totals['shipping_insurance'] = [
|
|
|
+ 'price' => round($order->base_shipping_insurance_amount * $shippingRatio, 2),
|
|
|
+ 'label' => trans('shippinginsurance::app.shop.label'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $totals['vip_plus'] = [
|
|
|
+ 'price' => round($order->base_vip_plus_amount * $subtotalRatio, 2),
|
|
|
+ 'label' => trans('member::app.member.discount'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $totals['vip_discount'] = [
|
|
|
+ 'price' => round($order->base_vip_discount_amount * $subtotalRatio, 2),
|
|
|
+ 'label' => trans('member::app.member.vip_discount'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $totals['grand_total']['price'] += $totals['subtotal']['price']
|
|
|
+ + $totals['tax']['price']
|
|
|
+ + $totals['shipping']['price']
|
|
|
+ + $totals['shipping_insurance']['price']
|
|
|
+ - $totals['giftcard']['price']
|
|
|
+ + $totals['vip_plus']['price']
|
|
|
+ - $totals['vip_discount']['price']
|
|
|
+ + $data['adjustment_refund']
|
|
|
+ - $data['adjustment_fee']
|
|
|
+ - $totals['discount']['price'];
|
|
|
|
|
|
$totals = array_map(function ($item) {
|
|
|
$item['formatted_price'] = core()->formatBasePrice($item['price']);
|