|
|
@@ -1,12 +1,14 @@
|
|
1
|
1
|
<script setup>
|
|
2
|
|
-import { computed } from 'vue'
|
|
|
2
|
+import { computed, watch, watchEffect } from 'vue'
|
|
|
3
|
+import { Inertia } from '@inertiajs/inertia'
|
|
|
4
|
+import { once } from 'lodash'
|
|
|
5
|
+import { ppn } from '@/utils/helpers'
|
|
3
|
6
|
import { optionStatus } from './config'
|
|
4
|
7
|
import { cartTable } from './config'
|
|
5
|
8
|
import Details from './Components/Details.vue'
|
|
6
|
9
|
import Cart from './Components/Cart.vue'
|
|
7
|
|
-import HistoryProduct from './Components/HistoryProduct.vue'
|
|
8
|
10
|
import { useProductCart } from './Composables/useProductCart'
|
|
9
|
|
-import { onShowDialog } from './Composables/onShowDialog'
|
|
|
11
|
+import { useDialog } from './Composables/useDialog'
|
|
10
|
12
|
import { useForm } from '@/composables/useForm'
|
|
11
|
13
|
import AppInputText from '@/components/AppInputText.vue'
|
|
12
|
14
|
import AppInputNumber from '@/components/AppInputNumber.vue'
|
|
|
@@ -25,7 +27,7 @@ const props = defineProps({
|
|
25
|
27
|
type: Array,
|
|
26
|
28
|
default: [],
|
|
27
|
29
|
},
|
|
28
|
|
- historyProductPurchase: Object,
|
|
|
30
|
+ productPurchase: Object,
|
|
29
|
31
|
})
|
|
30
|
32
|
|
|
31
|
33
|
const form = useForm({
|
|
|
@@ -56,20 +58,53 @@ const onSubmit = () => {
|
|
56
|
58
|
})
|
|
57
|
59
|
}
|
|
58
|
60
|
|
|
|
61
|
+watchEffect(() => {
|
|
|
62
|
+ if (props.productPurchase?.number) {
|
|
|
63
|
+ form.price = props.productPurchase.price
|
|
|
64
|
+
|
|
|
65
|
+ form.qty = props.productPurchase.qty
|
|
|
66
|
+ } else {
|
|
|
67
|
+ form.price = null
|
|
|
68
|
+ }
|
|
|
69
|
+})
|
|
|
70
|
+
|
|
|
71
|
+watch(
|
|
|
72
|
+ () => form.product,
|
|
|
73
|
+ () => {
|
|
|
74
|
+ if (form.product?.number) {
|
|
|
75
|
+ Inertia.reload({
|
|
|
76
|
+ data: {
|
|
|
77
|
+ productNumber: form.product.number,
|
|
|
78
|
+ supplierId: form.supplier.id,
|
|
|
79
|
+ },
|
|
|
80
|
+ only: ['productPurchase'],
|
|
|
81
|
+ })
|
|
|
82
|
+ }
|
|
|
83
|
+ }
|
|
|
84
|
+)
|
|
|
85
|
+
|
|
|
86
|
+const productUnit = computed(() => form.product?.unit)
|
|
|
87
|
+
|
|
|
88
|
+const productPurchasePrice = computed(() => props.productPurchase?.price)
|
|
|
89
|
+
|
|
|
90
|
+const productPurchasePpn = computed(() => props.productPurchase?.ppn)
|
|
|
91
|
+
|
|
|
92
|
+const productPurchaseQty = computed(() => props.productPurchase?.qty)
|
|
|
93
|
+
|
|
59
|
94
|
const dropdownStatus = computed(() => {
|
|
60
|
95
|
return optionStatus.filter((val) => val.value != 'success')
|
|
61
|
96
|
})
|
|
62
|
97
|
|
|
63
|
98
|
const {
|
|
64
|
99
|
productCart,
|
|
|
100
|
+ productErrors,
|
|
65
|
101
|
onClearProductCart,
|
|
66
|
102
|
onAddProduct,
|
|
67
|
103
|
onDeleteProduct,
|
|
68
|
|
- onEditProduct,
|
|
69
|
104
|
totalProductPrice,
|
|
70
|
105
|
} = useProductCart(form)
|
|
71
|
106
|
|
|
72
|
|
-const { onShowCreateProduct, onShowCreateSupplier } = onShowDialog()
|
|
|
107
|
+const { onShowCreateProduct, onShowCreateSupplier } = useDialog()
|
|
73
|
108
|
</script>
|
|
74
|
109
|
|
|
75
|
110
|
<template>
|
|
|
@@ -144,7 +179,7 @@ const { onShowCreateProduct, onShowCreateSupplier } = onShowDialog()
|
|
144
|
179
|
field="name"
|
|
145
|
180
|
refresh-data="products"
|
|
146
|
181
|
v-model="form.product"
|
|
147
|
|
- :error="form.errors.products"
|
|
|
182
|
+ :error="form.errors.product"
|
|
148
|
183
|
:suggestions="products"
|
|
149
|
184
|
>
|
|
150
|
185
|
<template #item="slotProps">
|
|
|
@@ -168,27 +203,50 @@ const { onShowCreateProduct, onShowCreateSupplier } = onShowDialog()
|
|
168
|
203
|
</AppAutoComplete>
|
|
169
|
204
|
</div>
|
|
170
|
205
|
|
|
171
|
|
- <div v-if="form.product?.number" class="col-12 md:col-6">
|
|
|
206
|
+ <div class="col-12 md:col-6">
|
|
172
|
207
|
<AppInputText
|
|
173
|
208
|
disabled
|
|
174
|
209
|
label="Satuan"
|
|
175
|
210
|
placeholder="satuan"
|
|
176
|
|
- v-model="form.product.unit"
|
|
|
211
|
+ v-model="productUnit"
|
|
177
|
212
|
/>
|
|
178
|
213
|
</div>
|
|
179
|
214
|
|
|
180
|
215
|
<Divider type="dashed" />
|
|
181
|
216
|
|
|
182
|
|
- <HistoryProduct
|
|
183
|
|
- :product="form.product"
|
|
184
|
|
- :supplier="form.supplier"
|
|
185
|
|
- />
|
|
|
217
|
+ <div class="col-12">
|
|
|
218
|
+ <h3 class="text-lg">Riwayat Produk Sebelumnya</h3>
|
|
|
219
|
+ </div>
|
|
|
220
|
+
|
|
|
221
|
+ <div class="col-12 md:col-6">
|
|
|
222
|
+ <AppInputNumber
|
|
|
223
|
+ disabled
|
|
|
224
|
+ class="mb-0"
|
|
|
225
|
+ label="Harga "
|
|
|
226
|
+ placeholder="harga"
|
|
|
227
|
+ v-model="productPurchasePrice"
|
|
|
228
|
+ />
|
|
|
229
|
+
|
|
|
230
|
+ <span v-if="productPurchasePpn" class="text-xs">
|
|
|
231
|
+ Harga sudah termasuk PPN {{ ppn }} %
|
|
|
232
|
+ </span>
|
|
|
233
|
+ </div>
|
|
|
234
|
+
|
|
|
235
|
+ <div class="col-12 md:col-6">
|
|
|
236
|
+ <AppInputText
|
|
|
237
|
+ disabled
|
|
|
238
|
+ label="Kuantitas"
|
|
|
239
|
+ placeholder="kuantitas"
|
|
|
240
|
+ type="number"
|
|
|
241
|
+ v-model="productPurchaseQty"
|
|
|
242
|
+ />
|
|
|
243
|
+ </div>
|
|
186
|
244
|
|
|
187
|
245
|
<Divider type="dashed" />
|
|
188
|
246
|
|
|
189
|
247
|
<div class="col-12 md:col-6">
|
|
190
|
248
|
<AppInputNumber
|
|
191
|
|
- :disabled="!form.supplier?.id"
|
|
|
249
|
+ :disabled="!form.product?.id"
|
|
192
|
250
|
label="Harga Terbaru"
|
|
193
|
251
|
placeholder="harga terbaru"
|
|
194
|
252
|
v-model="form.price"
|
|
|
@@ -197,7 +255,7 @@ const { onShowCreateProduct, onShowCreateSupplier } = onShowDialog()
|
|
197
|
255
|
|
|
198
|
256
|
<div class="col-12 md:col-6">
|
|
199
|
257
|
<AppInputText
|
|
200
|
|
- :disabled="!form.supplier?.id"
|
|
|
258
|
+ :disabled="!form.product?.id"
|
|
201
|
259
|
label="Kuantitas"
|
|
202
|
260
|
placeholder="kuantitas"
|
|
203
|
261
|
type="number"
|
|
|
@@ -212,8 +270,12 @@ const { onShowCreateProduct, onShowCreateSupplier } = onShowDialog()
|
|
212
|
270
|
label="Tambah Produk"
|
|
213
|
271
|
icon="pi pi-check"
|
|
214
|
272
|
class="p-button-outlined"
|
|
|
273
|
+ :class="{ 'p-button-danger': productErrors.length }"
|
|
215
|
274
|
:disabled="
|
|
216
|
|
- !form.price || !form.qty || !form.product?.number
|
|
|
275
|
+ !form.price ||
|
|
|
276
|
+ !Number(form.qty) ||
|
|
|
277
|
+ !form.product?.number ||
|
|
|
278
|
+ productErrors.length
|
|
217
|
279
|
"
|
|
218
|
280
|
@click="onAddProduct"
|
|
219
|
281
|
/>
|
|
|
@@ -227,9 +289,9 @@ const { onShowCreateProduct, onShowCreateSupplier } = onShowDialog()
|
|
227
|
289
|
title="Keranjang Produk"
|
|
228
|
290
|
:product-cart="productCart"
|
|
229
|
291
|
:header-table="cartTable"
|
|
|
292
|
+ :btn-edit-show="false"
|
|
230
|
293
|
v-model:checked-ppn="form.checkedPpn"
|
|
231
|
294
|
@delete="onDeleteProduct"
|
|
232
|
|
- @edit="onEditProduct"
|
|
233
|
295
|
/>
|
|
234
|
296
|
</div>
|
|
235
|
297
|
</div>
|