Преглед изворни кода

退款页面添加运费险项

llp пре 1 дан
родитељ
комит
94d8376e36

+ 48 - 0
packages/Webkul/Admin/src/Resources/views/sales/refunds/create.blade.php

@@ -309,6 +309,30 @@
                                         @lang('admin::app.sales.refunds.create.tax-amount')
                                     </p>
 
+                                    <template v-if="totals && totals.shipping_insurance && totals.shipping_insurance.price > 0">
+                                        <p class="text-gray-600 dark:text-gray-300">
+                                            @lang('shippinginsurance::app.shop.label')
+                                        </p>
+                                    </template>
+
+                                    <template v-if="totals && totals.giftcard && totals.giftcard.price > 0">
+                                        <p class="text-gray-600 dark:text-gray-300">
+                                            @lang('gift::app.giftcard.giftcard_amount')
+                                        </p>
+                                    </template>
+
+                                    <template v-if="totals && totals.vip_plus && totals.vip_plus.price > 0">
+                                        <p class="text-gray-600 dark:text-gray-300">
+                                            @lang('member::app.member.discount')
+                                        </p>
+                                    </template>
+
+                                    <template v-if="totals && totals.vip_discount && totals.vip_discount.price > 0">
+                                        <p class="text-gray-600 dark:text-gray-300">
+                                            @lang('member::app.member.vip_discount')
+                                        </p>
+                                    </template>
+
                                     <p class="font-semibold text-gray-600 dark:text-gray-300">
                                         @lang('admin::app.sales.refunds.create.grand-total')
                                     </p>
@@ -327,6 +351,30 @@
                                         @{{ totals.tax.formatted_price }}
                                     </p>
 
+                                    <template v-if="totals && totals.shipping_insurance && totals.shipping_insurance.price > 0">
+                                        <p class="text-gray-600 dark:text-gray-300">
+                                            + @{{ totals.shipping_insurance.formatted_price }}
+                                        </p>
+                                    </template>
+
+                                    <template v-if="totals && totals.giftcard && totals.giftcard.price > 0">
+                                        <p class="text-gray-600 dark:text-gray-300">
+                                            - @{{ totals.giftcard.formatted_price }}
+                                        </p>
+                                    </template>
+
+                                    <template v-if="totals && totals.vip_plus && totals.vip_plus.price > 0">
+                                        <p class="text-gray-600 dark:text-gray-300">
+                                            + @{{ totals.vip_plus.formatted_price }}
+                                        </p>
+                                    </template>
+
+                                    <template v-if="totals && totals.vip_discount && totals.vip_discount.price > 0">
+                                        <p class="text-gray-600 dark:text-gray-300">
+                                            - @{{ totals.vip_discount.formatted_price }}
+                                        </p>
+                                    </template>
+
                                     <p class="text-gray-600 dark:text-gray-300">
                                         @{{ totals.grand_total.formatted_price }}
                                     </p>

+ 64 - 1
packages/Webkul/Admin/src/Resources/views/sales/refunds/view.blade.php

@@ -1,4 +1,19 @@
-@php $order = $refund->order; @endphp
+@php
+$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;
+
+$baseShippingInsurance = round($order->base_shipping_insurance_amount * $shippingRatio, 2);
+$baseGiftcard = round($order->base_giftcard_amount * $subtotalRatio, 2);
+$baseVipPlus = round($order->base_vip_plus_amount * $subtotalRatio, 2);
+$baseVipDiscount = round($order->base_vip_discount_amount * $subtotalRatio, 2);
+@endphp
 
 <x-admin::layouts>
     <!-- Page Title -->
@@ -212,6 +227,30 @@
                             </p>
                         @endif
 
+                        @if ($baseShippingInsurance > 0)
+                            <p class="!leading-5 text-gray-600 dark:text-gray-300">
+                                @lang('shippinginsurance::app.shop.label')
+                            </p>
+                        @endif
+
+                        @if ($baseGiftcard > 0)
+                            <p class="!leading-5 text-gray-600 dark:text-gray-300">
+                                @lang('gift::app.giftcard.giftcard_amount')
+                            </p>
+                        @endif
+
+                        @if ($baseVipPlus > 0)
+                            <p class="!leading-5 text-gray-600 dark:text-gray-300">
+                                @lang('member::app.member.discount')
+                            </p>
+                        @endif
+
+                        @if ($baseVipDiscount > 0)
+                            <p class="!leading-5 text-gray-600 dark:text-gray-300">
+                                @lang('member::app.member.vip_discount')
+                            </p>
+                        @endif
+
                         <p class="!leading-5 text-gray-600 dark:text-gray-300">
                             @lang('admin::app.sales.refunds.view.adjustment-refund')
                         </p>
@@ -280,6 +319,30 @@
                             </p>
                         @endif
 
+                        @if ($baseShippingInsurance > 0)
+                            <p class="!leading-5 text-gray-600 dark:text-gray-300">
+                                + {{ core()->formatBasePrice($baseShippingInsurance) }}
+                            </p>
+                        @endif
+
+                        @if ($baseGiftcard > 0)
+                            <p class="!leading-5 text-gray-600 dark:text-gray-300">
+                                - {{ core()->formatBasePrice($baseGiftcard) }}
+                            </p>
+                        @endif
+
+                        @if ($baseVipPlus > 0)
+                            <p class="!leading-5 text-gray-600 dark:text-gray-300">
+                                + {{ core()->formatBasePrice($baseVipPlus) }}
+                            </p>
+                        @endif
+
+                        @if ($baseVipDiscount > 0)
+                            <p class="!leading-5 text-gray-600 dark:text-gray-300">
+                                - {{ core()->formatBasePrice($baseVipDiscount) }}
+                            </p>
+                        @endif
+
                         <!-- Base Adjustment Refund -->
                         <p class="!leading-5 text-gray-600 dark:text-gray-300">
                             {{ core()->formatBasePrice($refund->base_adjustment_refund) }}

+ 81 - 3
packages/Webkul/Sales/src/Repositories/RefundRepository.php

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