Parcourir la source

fix: purchase master

Muhammad Iqbal Afandi il y a 3 ans
Parent
révision
86a835f00b

+ 2
- 2
app/Http/Controllers/PurchaseController.php Voir le fichier

@@ -190,7 +190,7 @@ class PurchaseController extends Controller
190 190
                     "unit" => $purchase->product->unit,
191 191
                 ]
192 192
             ),
193
-            "historyProductPurchase" => Inertia::lazy(
193
+            "productPurchase" => Inertia::lazy(
194 194
                 fn() => PurchaseDetail::historyProductPurchase(
195 195
                     request()->only("productNumber", "supplierId")
196 196
                 )
@@ -198,7 +198,7 @@ class PurchaseController extends Controller
198 198
                     ->get()
199 199
                     ->transform(
200 200
                         fn($purchaseDetail) => [
201
-                            "id" => $purchaseDetail->id,
201
+                            "number" => $purchaseDetail->product_number,
202 202
                             "price" => $purchaseDetail->price,
203 203
                             "qty" => $purchaseDetail->qty,
204 204
                             "ppn" => $purchaseDetail->purchase->ppn,

+ 73
- 0
resources/js/pages/Purchases/Components/HistoryProduct.vue Voir le fichier

@@ -0,0 +1,73 @@
1
+<script setup>
2
+import { watchEffect, watch, computed, inject } from 'vue'
3
+import { Inertia } from '@inertiajs/inertia'
4
+import AppInputText from '@/components/AppInputText.vue'
5
+import AppInputNumber from '@/components/AppInputNumber.vue'
6
+
7
+const props = defineProps({
8
+  productPurchase: Object,
9
+})
10
+
11
+const form = inject('form')
12
+
13
+watchEffect(() => {
14
+  if (props.productPurchase?.number) {
15
+    form.price = props.productPurchase.price
16
+
17
+    form.qty = props.productPurchase.qty
18
+  } else {
19
+    form.price = null
20
+  }
21
+})
22
+
23
+watch(
24
+  () => form.product,
25
+  () => {
26
+    if (form.product?.number) {
27
+      Inertia.reload({
28
+        data: {
29
+          productNumber: form.product.number,
30
+          supplierId: form.supplier.id,
31
+        },
32
+        only: ['productPurchase'],
33
+      })
34
+    }
35
+  }
36
+)
37
+
38
+const productPurchasePrice = computed(() => props.productPurchase?.price)
39
+
40
+const productPurchasePpn = computed(() => props.productPurchase?.ppn)
41
+
42
+const productPurchaseQty = computed(() => props.productPurchase?.qty)
43
+</script>
44
+
45
+<template>
46
+  <div class="col-12">
47
+    <h3 class="text-lg">Riwayat Produk Sebelumnya</h3>
48
+  </div>
49
+
50
+  <div class="col-12 md:col-6">
51
+    <AppInputNumber
52
+      disabled
53
+      class="mb-0"
54
+      label="Harga "
55
+      placeholder="harga"
56
+      v-model="productPurchasePrice"
57
+    />
58
+
59
+    <span v-if="productPurchasePpn" class="text-xs">
60
+      Harga sudah termasuk PPN {{ ppn }} %
61
+    </span>
62
+  </div>
63
+
64
+  <div class="col-12 md:col-6">
65
+    <AppInputText
66
+      disabled
67
+      label="Kuantitas"
68
+      placeholder="kuantitas"
69
+      type="number"
70
+      v-model="productPurchaseQty"
71
+    />
72
+  </div>
73
+</template>

+ 4
- 59
resources/js/pages/Purchases/Create.vue Voir le fichier

@@ -1,6 +1,5 @@
1 1
 <script setup>
2
-import { computed, watch, watchEffect } from 'vue'
3
-import { Inertia } from '@inertiajs/inertia'
2
+import { computed, provide } from 'vue'
4 3
 import { optionStatus } from './config'
5 4
 import { cartTable } from './config'
6 5
 import Details from './Components/Details.vue'
@@ -8,6 +7,7 @@ import Cart from './Components/Cart.vue'
8 7
 import { useProductCart } from './Composables/useProductCart'
9 8
 import { useDialog } from './Composables/useDialog'
10 9
 import { useForm } from '@/composables/useForm'
10
+import HistoryProduct from './Components/HistoryProduct.vue'
11 11
 import AppInputText from '@/components/AppInputText.vue'
12 12
 import AppInputNumber from '@/components/AppInputNumber.vue'
13 13
 import AppDropdown from '@/components/AppDropdown.vue'
@@ -56,39 +56,10 @@ const onSubmit = () => {
56 56
     })
57 57
 }
58 58
 
59
-watchEffect(() => {
60
-  if (props.productPurchase?.number) {
61
-    form.price = props.productPurchase.price
62
-
63
-    form.qty = props.productPurchase.qty
64
-  } else {
65
-    form.price = null
66
-  }
67
-})
68
-
69
-watch(
70
-  () => form.product,
71
-  () => {
72
-    if (form.product?.number) {
73
-      Inertia.reload({
74
-        data: {
75
-          productNumber: form.product.number,
76
-          supplierId: form.supplier.id,
77
-        },
78
-        only: ['productPurchase'],
79
-      })
80
-    }
81
-  }
82
-)
59
+provide('form', form)
83 60
 
84 61
 const productUnit = computed(() => form.product?.unit)
85 62
 
86
-const productPurchasePrice = computed(() => props.productPurchase?.price)
87
-
88
-const productPurchasePpn = computed(() => props.productPurchase?.ppn)
89
-
90
-const productPurchaseQty = computed(() => props.productPurchase?.qty)
91
-
92 63
 const dropdownStatus = computed(() => {
93 64
   return optionStatus.filter((val) => val.value != 'success')
94 65
 })
@@ -212,33 +183,7 @@ const { onShowCreateProduct, onShowCreateSupplier } = useDialog()
212 183
 
213 184
                   <Divider type="dashed" />
214 185
 
215
-                  <div class="col-12">
216
-                    <h3 class="text-lg">Riwayat Produk Sebelumnya</h3>
217
-                  </div>
218
-
219
-                  <div class="col-12 md:col-6">
220
-                    <AppInputNumber
221
-                      disabled
222
-                      class="mb-0"
223
-                      label="Harga "
224
-                      placeholder="harga"
225
-                      v-model="productPurchasePrice"
226
-                    />
227
-
228
-                    <span v-if="productPurchasePpn" class="text-xs">
229
-                      Harga sudah termasuk PPN {{ ppn }} %
230
-                    </span>
231
-                  </div>
232
-
233
-                  <div class="col-12 md:col-6">
234
-                    <AppInputText
235
-                      disabled
236
-                      label="Kuantitas"
237
-                      placeholder="kuantitas"
238
-                      type="number"
239
-                      v-model="productPurchaseQty"
240
-                    />
241
-                  </div>
186
+                  <HistoryProduct :product-purchase="productPurchase" />
242 187
 
243 188
                   <Divider type="dashed" />
244 189
 

+ 17
- 12
resources/js/pages/Purchases/Edit.vue Voir le fichier

@@ -1,17 +1,19 @@
1 1
 <script setup>
2
+import { computed } from 'vue'
2 3
 import { optionStatus } from './config'
3 4
 import { cartTable } from './config'
4 5
 import Details from './Components/Details.vue'
5 6
 import Cart from './Components/Cart.vue'
6
-import HistoryProduct from './Components/HistoryProduct.vue'
7 7
 import { useProductCart } from './Composables/useProductCart'
8
-import { onShowDialog } from './Composables/onShowDialog'
8
+import { useDialog } from './Composables/useDialog'
9 9
 import { useForm } from '@/composables/useForm'
10
+import HistoryProduct from './Components/HistoryProduct.vue'
10 11
 import AppInputText from '@/components/AppInputText.vue'
11 12
 import AppInputNumber from '@/components/AppInputNumber.vue'
12 13
 import AppDropdown from '@/components/AppDropdown.vue'
13 14
 import AppAutoComplete from '@/components/AppAutoComplete.vue'
14 15
 import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
16
+import { provide } from 'vue'
15 17
 
16 18
 const props = defineProps({
17 19
   id: Number,
@@ -25,7 +27,7 @@ const props = defineProps({
25 27
     default: [],
26 28
   },
27 29
   purchaseDetail: Array,
28
-  historyProductPurchase: Object,
30
+  productPurchase: Object,
29 31
 })
30 32
 
31 33
 const form = useForm({
@@ -50,6 +52,10 @@ const onSubmit = () => {
50 52
     })
51 53
 }
52 54
 
55
+provide('form', form)
56
+
57
+const productUnit = computed(() => form.product?.unit)
58
+
53 59
 const {
54 60
   productCart,
55 61
   productCartDeleted,
@@ -60,7 +66,7 @@ const {
60 66
   totalProductPrice,
61 67
 } = useProductCart(form, props.purchaseDetail)
62 68
 
63
-const { onShowCreateProduct } = onShowDialog()
69
+const { onShowCreateProduct } = useDialog()
64 70
 </script>
65 71
 
66 72
 <template>
@@ -112,7 +118,7 @@ const { onShowCreateProduct } = onShowDialog()
112 118
                       field="name"
113 119
                       refresh-data="products"
114 120
                       v-model="form.product"
115
-                      :error="form.errors.products"
121
+                      :error="form.errors.product"
116 122
                       :suggestions="products"
117 123
                     >
118 124
                       <template #item="slotProps">
@@ -141,20 +147,19 @@ const { onShowCreateProduct } = onShowDialog()
141 147
                       disabled
142 148
                       label="Satuan"
143 149
                       placeholder="satuan"
144
-                      v-model="form.product.unit"
150
+                      v-model="productUnit"
145 151
                     />
146 152
                   </div>
147 153
 
148
-                  <HistoryProduct
149
-                    :product="form.product"
150
-                    :supplier="form.supplier"
151
-                  />
154
+                  <Divider type="dashed" />
155
+
156
+                  <HistoryProduct :product-purchase="productPurchase" />
152 157
 
153 158
                   <Divider type="dashed" />
154 159
 
155 160
                   <div class="col-12 md:col-6">
156 161
                     <AppInputNumber
157
-                      :disabled="!form.supplier?.id"
162
+                      :disabled="!form.product?.id"
158 163
                       label="Harga"
159 164
                       placeholder="harga"
160 165
                       v-model="form.price"
@@ -163,7 +168,7 @@ const { onShowCreateProduct } = onShowDialog()
163 168
 
164 169
                   <div class="col-12 md:col-6">
165 170
                     <AppInputText
166
-                      :disabled="!form.supplier?.id"
171
+                      :disabled="!form.product?.id"
167 172
                       label="Kuantitas"
168 173
                       placeholder="kuantitas"
169 174
                       type="number"