Muhammad Iqbal Afandi преди 3 години
родител
ревизия
3b7916b4eb

+ 1
- 1
app/Http/Controllers/PurchaseController.php Целия файл

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

+ 2
- 2
app/Models/PurchaseDetail.php Целия файл

@@ -20,8 +20,8 @@ class PurchaseDetail extends Model
20 20
                 $ppn = Ppn::first()->ppn;
21 21
 
22 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,10 +1,12 @@
1 1
 <script setup>
2 2
 import { watchEffect, watch, computed, inject } from 'vue'
3 3
 import { Inertia } from '@inertiajs/inertia'
4
+import { ppn as ppnUtils } from '@/utils/helpers'
4 5
 import AppInputText from '@/components/AppInputText.vue'
5 6
 import AppInputNumber from '@/components/AppInputNumber.vue'
6 7
 
7 8
 const props = defineProps({
9
+  ppn: Number,
8 10
   productPurchase: Object,
9 11
 })
10 12
 
@@ -35,7 +37,14 @@ watch(
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 49
 const productPurchasePpn = computed(() => props.productPurchase?.ppn)
41 50
 

+ 4
- 6
resources/js/pages/Purchases/Composables/useCart.js Целия файл

@@ -1,5 +1,5 @@
1 1
 import { reactive } from 'vue'
2
-import { FormValidationError } from '@/utils/helpers'
2
+import { FormValidationError, ppn } from '@/utils/helpers'
3 3
 
4 4
 export function useCart(form, initialProducts = []) {
5 5
   const cart = reactive(initialProducts)
@@ -75,11 +75,9 @@ export function useCart(form, initialProducts = []) {
75 75
 
76 76
   const totalCartPrice = () => {
77 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 83
     return itemPrices.reduce((prev, current) => prev + current, 0)

+ 6
- 3
resources/js/pages/Purchases/Create.vue Целия файл

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