ソースを参照

fix: purchase master

コミット
3b7916b4eb

+ 1
- 1
app/Http/Controllers/PurchaseController.php ファイルの表示

80
                     ->transform(
80
                     ->transform(
81
                         fn($purchaseDetail) => [
81
                         fn($purchaseDetail) => [
82
                             "number" => $purchaseDetail->product_number,
82
                             "number" => $purchaseDetail->product_number,
83
-                            "price" => $purchaseDetail->price,
83
+                            "price" => $purchaseDetail->getRawOriginal("price"),
84
                             "qty" => $purchaseDetail->qty,
84
                             "qty" => $purchaseDetail->qty,
85
                             "ppn" => $purchaseDetail->purchase->ppn,
85
                             "ppn" => $purchaseDetail->purchase->ppn,
86
                         ]
86
                         ]

+ 2
- 2
app/Models/PurchaseDetail.php ファイルの表示

20
                 $ppn = Ppn::first()->ppn;
20
                 $ppn = Ppn::first()->ppn;
21
 
21
 
22
                 return $this->purchase->ppn
22
                 return $this->purchase->ppn
23
-                    ? HelperService::addPPN($value, $ppn)
24
-                    : $value;
23
+                    ? HelperService::addPPN($value, $ppn) * $this->qty
24
+                    : $value * $this->qty;
25
             }
25
             }
26
         );
26
         );
27
     }
27
     }

+ 10
- 1
resources/js/pages/Purchases/Components/HistoryProduct.vue ファイルの表示

1
 <script setup>
1
 <script setup>
2
 import { watchEffect, watch, computed, inject } from 'vue'
2
 import { watchEffect, watch, computed, inject } from 'vue'
3
 import { Inertia } from '@inertiajs/inertia'
3
 import { Inertia } from '@inertiajs/inertia'
4
+import { ppn as ppnUtils } from '@/utils/helpers'
4
 import AppInputText from '@/components/AppInputText.vue'
5
 import AppInputText from '@/components/AppInputText.vue'
5
 import AppInputNumber from '@/components/AppInputNumber.vue'
6
 import AppInputNumber from '@/components/AppInputNumber.vue'
6
 
7
 
7
 const props = defineProps({
8
 const props = defineProps({
9
+  ppn: Number,
8
   productPurchase: Object,
10
   productPurchase: Object,
9
 })
11
 })
10
 
12
 
35
   }
37
   }
36
 )
38
 )
37
 
39
 
38
-const productPurchasePrice = computed(() => props.productPurchase?.price)
40
+const productPurchasePrice = computed(() => {
41
+  if (props.productPurchase?.number) {
42
+    return ppnUtils(
43
+      props.productPurchase.price,
44
+      props.productPurchase?.ppn ?? 0
45
+    )
46
+  }
47
+})
39
 
48
 
40
 const productPurchasePpn = computed(() => props.productPurchase?.ppn)
49
 const productPurchasePpn = computed(() => props.productPurchase?.ppn)
41
 
50
 

+ 4
- 6
resources/js/pages/Purchases/Composables/useCart.js ファイルの表示

1
 import { reactive } from 'vue'
1
 import { reactive } from 'vue'
2
-import { FormValidationError } from '@/utils/helpers'
2
+import { FormValidationError, ppn } from '@/utils/helpers'
3
 
3
 
4
 export function useCart(form, initialProducts = []) {
4
 export function useCart(form, initialProducts = []) {
5
   const cart = reactive(initialProducts)
5
   const cart = reactive(initialProducts)
75
 
75
 
76
   const totalCartPrice = () => {
76
   const totalCartPrice = () => {
77
     const itemPrices = cart.map((product) => {
77
     const itemPrices = cart.map((product) => {
78
-      if (form.checkedPpn) {
79
-        return product.price + product.price * (form.ppn / 100)
80
-      } else {
81
-        return product.price
82
-      }
78
+      return form.checkedPpn
79
+        ? ppn(product.price, form.ppn) * product.qty
80
+        : product.price * product.qty
83
     })
81
     })
84
 
82
 
85
     return itemPrices.reduce((prev, current) => prev + current, 0)
83
     return itemPrices.reduce((prev, current) => prev + current, 0)

+ 6
- 3
resources/js/pages/Purchases/Create.vue ファイルの表示

183
 
183
 
184
                   <Divider type="dashed" />
184
                   <Divider type="dashed" />
185
 
185
 
186
-                  <HistoryProduct :product-purchase="productPurchase" />
186
+                  <HistoryProduct
187
+                    :ppn="ppn"
188
+                    :product-purchase="productPurchase"
189
+                  />
187
 
190
 
188
                   <Divider type="dashed" />
191
                   <Divider type="dashed" />
189
 
192
 
190
                   <div class="col-12 md:col-6">
193
                   <div class="col-12 md:col-6">
191
                     <AppInputNumber
194
                     <AppInputNumber
192
-                      label="Harga Terbaru"
193
-                      placeholder="harga terbaru"
195
+                      label="Harga"
196
+                      placeholder="harga"
194
                       :disabled="!form.product?.id"
197
                       :disabled="!form.product?.id"
195
                       v-model="form.price"
198
                       v-model="form.price"
196
                     />
199
                     />