@7365admin1/layer-common 4.17.1-staging.330 → 4.17.1-staging.331
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/InventoryImportDialog.vue +117 -0
- package/components/InventoryItemDetail.vue +158 -0
- package/components/InventoryItemDialog.vue +125 -0
- package/components/InventoryLinesDialog.vue +288 -0
- package/components/InventoryMain.vue +226 -0
- package/components/InventoryMyStockTab.vue +114 -0
- package/components/InventoryPhotoInput.vue +70 -0
- package/components/InventoryReportsTab.vue +181 -0
- package/components/InventoryRequestsTab.vue +218 -0
- package/components/InventorySettingsTab.vue +94 -0
- package/components/InventoryStockTab.vue +177 -0
- package/components/InventoryTechniciansTab.vue +81 -0
- package/components/InventoryUsageDialog.vue +203 -0
- package/composables/useCleaningPermission.ts +2 -7
- package/composables/useCommonPermission.ts +22 -0
- package/composables/useInventory.ts +97 -0
- package/composables/useInventoryPermission.ts +31 -0
- package/composables/useLandscapingPermission.ts +2 -6
- package/composables/useMechanicalElectricalPermission.ts +2 -0
- package/composables/usePestControlPermission.ts +2 -0
- package/composables/usePoolMaintenancePermission.ts +2 -0
- package/composables/usePropertyPermission.ts +2 -0
- package/composables/useSecurityPermission.ts +2 -0
- package/constants/permissions.ts +1 -1
- package/package.json +1 -1
- package/types/inventory.d.ts +89 -0
- package/utils/module-routes.ts +1 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-dialog v-model="show" max-width="760" persistent scrollable>
|
|
3
|
+
<v-card class="screen-modal">
|
|
4
|
+
<v-card-title class="d-flex align-center">
|
|
5
|
+
Import Items from Excel
|
|
6
|
+
<v-spacer />
|
|
7
|
+
<v-btn icon="mdi-close" variant="text" class="screen-modal__close" aria-label="Close" @click="show = false" />
|
|
8
|
+
</v-card-title>
|
|
9
|
+
<v-card-text class="screen-modal__body">
|
|
10
|
+
<ol class="text-body-2 mb-4 pl-4">
|
|
11
|
+
<li class="mb-1">
|
|
12
|
+
Download the template and fill in one row per item, with the quantity in the store today.
|
|
13
|
+
<v-btn variant="text" size="small" class="text-none" prepend-icon="mdi-download" :loading="downloading" @click="download">Download template</v-btn>
|
|
14
|
+
</li>
|
|
15
|
+
<li class="mb-1">Upload the file. We check it first; nothing is saved yet.</li>
|
|
16
|
+
<li>Review the result and confirm. Items already in the store are skipped, so uploading twice never doubles stock.</li>
|
|
17
|
+
</ol>
|
|
18
|
+
|
|
19
|
+
<v-file-input
|
|
20
|
+
v-model="file"
|
|
21
|
+
accept=".xlsx"
|
|
22
|
+
label="Excel file (.xlsx)"
|
|
23
|
+
prepend-icon="mdi-file-excel-outline"
|
|
24
|
+
density="comfortable"
|
|
25
|
+
show-size
|
|
26
|
+
@update:model-value="result = null"
|
|
27
|
+
/>
|
|
28
|
+
|
|
29
|
+
<template v-if="result">
|
|
30
|
+
<v-alert :type="result.errors ? 'warning' : 'success'" variant="tonal" class="mb-3">
|
|
31
|
+
<template v-if="result.committed">{{ result.ready }} item(s) added.</template>
|
|
32
|
+
<template v-else>{{ result.ready }} item(s) ready to add.</template>
|
|
33
|
+
<span v-if="result.skipped"> {{ result.skipped }} skipped.</span>
|
|
34
|
+
<span v-if="result.errors"> {{ result.errors }} row(s) need fixing (they will not be added).</span>
|
|
35
|
+
</v-alert>
|
|
36
|
+
<v-table density="compact" height="280" fixed-header>
|
|
37
|
+
<thead>
|
|
38
|
+
<tr>
|
|
39
|
+
<th>Row</th>
|
|
40
|
+
<th>Item</th>
|
|
41
|
+
<th>Result</th>
|
|
42
|
+
</tr>
|
|
43
|
+
</thead>
|
|
44
|
+
<tbody>
|
|
45
|
+
<tr v-for="r in result.rows" :key="r.row">
|
|
46
|
+
<td>{{ r.row }}</td>
|
|
47
|
+
<td>{{ r.name || "—" }}</td>
|
|
48
|
+
<td :class="r.status === 'error' ? 'text-error' : r.status === 'skipped' ? 'text-medium-emphasis' : 'text-success'">
|
|
49
|
+
{{ label[r.status] }}{{ r.message ? `: ${r.message}` : "" }}
|
|
50
|
+
</td>
|
|
51
|
+
</tr>
|
|
52
|
+
</tbody>
|
|
53
|
+
</v-table>
|
|
54
|
+
</template>
|
|
55
|
+
</v-card-text>
|
|
56
|
+
<div class="screen-modal__footer">
|
|
57
|
+
<v-btn class="screen-btn-ghost" variant="outlined" :disabled="busy" @click="show = false">{{ result?.committed ? "Close" : "Cancel" }}</v-btn>
|
|
58
|
+
<v-btn v-if="!result" class="screen-btn-primary" variant="flat" :disabled="!selected" :loading="busy" @click="run(false)">Check file</v-btn>
|
|
59
|
+
<v-btn v-else-if="!result.committed" class="screen-btn-primary" variant="flat" :disabled="!result.ready" :loading="busy" @click="run(true)">
|
|
60
|
+
Add {{ result.ready }} item(s)
|
|
61
|
+
</v-btn>
|
|
62
|
+
</div>
|
|
63
|
+
</v-card>
|
|
64
|
+
</v-dialog>
|
|
65
|
+
</template>
|
|
66
|
+
|
|
67
|
+
<script setup lang="ts">
|
|
68
|
+
import useInventory, { saveBlob } from "../composables/useInventory";
|
|
69
|
+
|
|
70
|
+
const show = defineModel<boolean>({ default: false });
|
|
71
|
+
const props = defineProps({ store: { type: Object as PropType<TInventoryStore>, required: true } });
|
|
72
|
+
const emit = defineEmits(["done"]);
|
|
73
|
+
|
|
74
|
+
const { importItems, importTemplate } = useInventory();
|
|
75
|
+
const notify = inject<(text: string, color?: string) => void>("inventoryNotify", () => {});
|
|
76
|
+
|
|
77
|
+
const file = ref<File | File[] | null>(null);
|
|
78
|
+
const selected = computed<File | null>(() => (Array.isArray(file.value) ? file.value[0] ?? null : file.value));
|
|
79
|
+
const result = ref<Awaited<ReturnType<typeof importItems>> | null>(null);
|
|
80
|
+
const busy = ref(false);
|
|
81
|
+
const downloading = ref(false);
|
|
82
|
+
const label: Record<string, string> = { ready: "Ready", added: "Added", skipped: "Skipped", error: "Needs fixing" };
|
|
83
|
+
|
|
84
|
+
async function download() {
|
|
85
|
+
downloading.value = true;
|
|
86
|
+
try {
|
|
87
|
+
saveBlob(await importTemplate(), "inventory-import-template.xlsx");
|
|
88
|
+
} catch {
|
|
89
|
+
notify("Could not download the template.", "error");
|
|
90
|
+
} finally {
|
|
91
|
+
downloading.value = false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function run(commit: boolean) {
|
|
96
|
+
if (!selected.value) return;
|
|
97
|
+
busy.value = true;
|
|
98
|
+
try {
|
|
99
|
+
result.value = await importItems(props.store._id, selected.value, commit);
|
|
100
|
+
if (commit) {
|
|
101
|
+
notify(`${result.value.ready} item(s) added.`);
|
|
102
|
+
emit("done");
|
|
103
|
+
}
|
|
104
|
+
} catch (error: any) {
|
|
105
|
+
notify(error?.data?.message || "Could not read the file.", "error");
|
|
106
|
+
} finally {
|
|
107
|
+
busy.value = false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
watch(show, (open) => {
|
|
112
|
+
if (open) {
|
|
113
|
+
file.value = null;
|
|
114
|
+
result.value = null;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
</script>
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-dialog v-model="show" max-width="820" scrollable>
|
|
3
|
+
<v-card v-if="item" class="screen-modal">
|
|
4
|
+
<v-card-title class="d-flex align-center">
|
|
5
|
+
{{ item.name }}
|
|
6
|
+
<v-spacer />
|
|
7
|
+
<v-btn icon="mdi-close" variant="text" class="screen-modal__close" aria-label="Close" @click="show = false" />
|
|
8
|
+
</v-card-title>
|
|
9
|
+
<v-card-text class="screen-modal__body">
|
|
10
|
+
<div class="d-flex flex-wrap ga-4 mb-4">
|
|
11
|
+
<v-img v-if="item.photo" :src="getFileUrl(item.photo)" width="120" height="120" cover class="rounded flex-grow-0" />
|
|
12
|
+
<div class="flex-grow-1">
|
|
13
|
+
<div class="text-h5 mb-1" :class="item.lowStock ? 'text-error' : ''">{{ item.onHand }} {{ item.unit }} in store</div>
|
|
14
|
+
<div class="text-body-2 text-medium-emphasis">
|
|
15
|
+
{{ [item.code && `Code ${item.code}`, item.category, item.reorderLevel ? `Alert at ${item.reorderLevel}` : "", item.unitCost !== undefined ? `$${Number(item.unitCost).toFixed(2)} each` : ""].filter(Boolean).join(" · ") }}
|
|
16
|
+
</div>
|
|
17
|
+
<div v-if="item.description" class="text-body-2 mt-2">{{ item.description }}</div>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div class="d-flex flex-wrap ga-2 mb-4" v-if="store.access.canManage">
|
|
22
|
+
<v-btn class="text-none screen-btn-ghost" variant="outlined" prepend-icon="mdi-pencil-outline" @click="emit('edit', item)">Edit item</v-btn>
|
|
23
|
+
<v-btn class="text-none screen-btn-ghost" variant="outlined" prepend-icon="mdi-counter" @click="counting = !counting">Stock count</v-btn>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<v-form v-if="counting" ref="countForm" class="mb-4">
|
|
27
|
+
<AppCard class="pa-4">
|
|
28
|
+
<div class="text-subtitle-2 mb-2">How many are on the shelf right now?</div>
|
|
29
|
+
<div class="d-flex flex-wrap ga-2">
|
|
30
|
+
<v-text-field v-model.number="counted" type="number" min="0" label="Counted" :suffix="item.unit" density="comfortable" style="max-width: 160px" :rules="[(v: any) => (Number.isInteger(Number(v)) && Number(v) >= 0) || 'Enter a whole number']" />
|
|
31
|
+
<v-text-field v-model="reason" label="Reason for the difference" density="comfortable" class="flex-grow-1" :rules="[requiredRule]" placeholder="e.g. 2 broken, found extra box" />
|
|
32
|
+
<v-btn class="text-none screen-btn-primary" variant="flat" :loading="saving" @click="saveCount">Save count</v-btn>
|
|
33
|
+
</div>
|
|
34
|
+
<div v-if="counted !== null && counted !== ('' as any)" class="text-caption mt-1">
|
|
35
|
+
Difference: {{ Number(counted) - item.onHand > 0 ? "+" : "" }}{{ Number(counted) - item.onHand }}
|
|
36
|
+
</div>
|
|
37
|
+
</AppCard>
|
|
38
|
+
</v-form>
|
|
39
|
+
|
|
40
|
+
<div class="text-subtitle-2 mb-2">History</div>
|
|
41
|
+
<v-table density="compact">
|
|
42
|
+
<thead>
|
|
43
|
+
<tr>
|
|
44
|
+
<th>Date</th>
|
|
45
|
+
<th>What happened</th>
|
|
46
|
+
<th class="text-right">Store</th>
|
|
47
|
+
<th class="text-right">Balance</th>
|
|
48
|
+
<th>Details</th>
|
|
49
|
+
</tr>
|
|
50
|
+
</thead>
|
|
51
|
+
<tbody>
|
|
52
|
+
<tr v-for="t in history" :key="t._id">
|
|
53
|
+
<td class="text-no-wrap">{{ formatDate(t.date) }}</td>
|
|
54
|
+
<td>{{ typeLabels[t.type] }}</td>
|
|
55
|
+
<td class="text-right" :class="t.storeChange > 0 ? 'text-success' : t.storeChange < 0 ? 'text-error' : ''">
|
|
56
|
+
{{ t.storeChange > 0 ? "+" : "" }}{{ t.storeChange || (t.type === "use" ? "" : 0) }}
|
|
57
|
+
</td>
|
|
58
|
+
<td class="text-right">{{ t.type === "use" ? "" : t.storeBalance }}</td>
|
|
59
|
+
<td class="text-caption">{{ describe(t) }}</td>
|
|
60
|
+
</tr>
|
|
61
|
+
<tr v-if="!history.length && !loading">
|
|
62
|
+
<td colspan="5" class="text-center text-medium-emphasis py-4">Nothing recorded yet.</td>
|
|
63
|
+
</tr>
|
|
64
|
+
</tbody>
|
|
65
|
+
</v-table>
|
|
66
|
+
<div class="text-center mt-2" v-if="page < pages">
|
|
67
|
+
<v-btn variant="text" class="text-none" :loading="loading" @click="load(page + 1)">Show more</v-btn>
|
|
68
|
+
</div>
|
|
69
|
+
</v-card-text>
|
|
70
|
+
</v-card>
|
|
71
|
+
</v-dialog>
|
|
72
|
+
</template>
|
|
73
|
+
|
|
74
|
+
<script setup lang="ts">
|
|
75
|
+
import useInventory from "../composables/useInventory";
|
|
76
|
+
import useFile from "../composables/useFile";
|
|
77
|
+
import useUtils from "../composables/useUtils";
|
|
78
|
+
|
|
79
|
+
const show = defineModel<boolean>({ default: false });
|
|
80
|
+
const props = defineProps({
|
|
81
|
+
store: { type: Object as PropType<TInventoryStore>, required: true },
|
|
82
|
+
item: { type: Object as PropType<TInventoryItem | null>, default: null },
|
|
83
|
+
});
|
|
84
|
+
const emit = defineEmits(["edit", "done"]);
|
|
85
|
+
|
|
86
|
+
const { getTransactions, count, typeLabels } = useInventory();
|
|
87
|
+
const { getFileUrl } = useFile();
|
|
88
|
+
const { requiredRule, standardFormatDate } = useUtils();
|
|
89
|
+
const notify = inject<(text: string, color?: string) => void>("inventoryNotify", () => {});
|
|
90
|
+
|
|
91
|
+
const history = ref<TInventoryTransaction[]>([]);
|
|
92
|
+
const page = ref(1);
|
|
93
|
+
const pages = ref(0);
|
|
94
|
+
const loading = ref(false);
|
|
95
|
+
const counting = ref(false);
|
|
96
|
+
const counted = ref<number | null>(null);
|
|
97
|
+
const reason = ref("");
|
|
98
|
+
const saving = ref(false);
|
|
99
|
+
const countForm = ref();
|
|
100
|
+
|
|
101
|
+
const formatDate = (d: string) => standardFormatDate(d);
|
|
102
|
+
|
|
103
|
+
function describe(t: TInventoryTransaction) {
|
|
104
|
+
const parts: string[] = [];
|
|
105
|
+
if (t.type === "receive") parts.push(t.supplier || "", t.reference ? `PO ${t.reference}` : "");
|
|
106
|
+
if (t.type === "issue") parts.push(`${t.qty} to ${t.holderName}`, t.reference || "");
|
|
107
|
+
if (t.type === "return") parts.push(`${t.qty} from ${t.holderName}`);
|
|
108
|
+
if (t.type === "use")
|
|
109
|
+
parts.push(
|
|
110
|
+
`${t.holderName} used ${t.qty}`,
|
|
111
|
+
t.location?.type === "tenant_unit" ? `${t.location.unitName} ${t.location.tenantName || ""}` : t.location?.area || "",
|
|
112
|
+
t.reference || "",
|
|
113
|
+
);
|
|
114
|
+
if (t.type === "adjust") parts.push(t.remarks || "");
|
|
115
|
+
if (t.type === "opening") parts.push(t.remarks || "");
|
|
116
|
+
return parts.filter(Boolean).join(" · ");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function load(p = 1) {
|
|
120
|
+
if (!props.item) return;
|
|
121
|
+
loading.value = true;
|
|
122
|
+
try {
|
|
123
|
+
const res = await getTransactions(props.store._id, { item: props.item._id, page: p, limit: 20 });
|
|
124
|
+
history.value = p === 1 ? res.items : [...history.value, ...res.items];
|
|
125
|
+
page.value = p;
|
|
126
|
+
pages.value = res.pages;
|
|
127
|
+
} catch {
|
|
128
|
+
if (p === 1) history.value = [];
|
|
129
|
+
} finally {
|
|
130
|
+
loading.value = false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function saveCount() {
|
|
135
|
+
const { valid } = await countForm.value.validate();
|
|
136
|
+
if (!valid || !props.item) return;
|
|
137
|
+
saving.value = true;
|
|
138
|
+
try {
|
|
139
|
+
await count(props.store._id, { item: props.item._id, countedQty: Number(counted.value), reason: reason.value });
|
|
140
|
+
notify("Stock count saved.");
|
|
141
|
+
counting.value = false;
|
|
142
|
+
show.value = false;
|
|
143
|
+
emit("done");
|
|
144
|
+
} catch (error: any) {
|
|
145
|
+
notify(error?.data?.message || "Could not save the count.", "error");
|
|
146
|
+
} finally {
|
|
147
|
+
saving.value = false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
watch(show, (open) => {
|
|
152
|
+
if (!open) return;
|
|
153
|
+
counting.value = false;
|
|
154
|
+
counted.value = props.item?.onHand ?? null;
|
|
155
|
+
reason.value = "";
|
|
156
|
+
load(1);
|
|
157
|
+
});
|
|
158
|
+
</script>
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-dialog v-model="show" max-width="620" persistent scrollable>
|
|
3
|
+
<v-card class="screen-modal">
|
|
4
|
+
<v-card-title class="d-flex align-center">
|
|
5
|
+
{{ item ? "Edit Item" : "Add Item" }}
|
|
6
|
+
<v-spacer />
|
|
7
|
+
<v-btn icon="mdi-close" variant="text" class="screen-modal__close" aria-label="Close" @click="show = false" />
|
|
8
|
+
</v-card-title>
|
|
9
|
+
<v-card-text class="screen-modal__body">
|
|
10
|
+
<v-form ref="form">
|
|
11
|
+
<InputLabel title="Item name" required class="mb-1" />
|
|
12
|
+
<v-text-field v-model="f.name" :rules="[requiredRule]" density="comfortable" placeholder="e.g. Philips T8 2ft 9W LED Tube" />
|
|
13
|
+
<v-row dense>
|
|
14
|
+
<v-col cols="12" sm="4">
|
|
15
|
+
<InputLabel title="Unit" required class="mb-1" />
|
|
16
|
+
<v-combobox v-model="f.unit" :items="units" :rules="[requiredRule]" density="comfortable" />
|
|
17
|
+
</v-col>
|
|
18
|
+
<v-col cols="12" sm="4">
|
|
19
|
+
<InputLabel title="Item code" class="mb-1" />
|
|
20
|
+
<v-text-field v-model="f.code" density="comfortable" />
|
|
21
|
+
</v-col>
|
|
22
|
+
<v-col cols="12" sm="4">
|
|
23
|
+
<InputLabel title="Category" class="mb-1" />
|
|
24
|
+
<v-text-field v-model="f.category" density="comfortable" placeholder="e.g. Lighting" />
|
|
25
|
+
</v-col>
|
|
26
|
+
<v-col cols="12" sm="4">
|
|
27
|
+
<InputLabel title="Low stock alert at" class="mb-1" />
|
|
28
|
+
<v-text-field v-model.number="f.reorderLevel" type="number" min="0" density="comfortable" :rules="[wholeRule]" hint="0 = no alert" persistent-hint />
|
|
29
|
+
</v-col>
|
|
30
|
+
<v-col cols="12" sm="4">
|
|
31
|
+
<InputLabel title="Unit price" class="mb-1" />
|
|
32
|
+
<v-text-field v-model.number="f.unitCost" type="number" min="0" step="0.01" prefix="$" density="comfortable" :rules="[moneyRule]" />
|
|
33
|
+
</v-col>
|
|
34
|
+
<v-col v-if="!item" cols="12" sm="4">
|
|
35
|
+
<InputLabel title="Current stock" class="mb-1" />
|
|
36
|
+
<v-text-field v-model.number="f.openingQty" type="number" min="0" density="comfortable" :rules="[wholeRule]" hint="Quantity in the store today" persistent-hint />
|
|
37
|
+
</v-col>
|
|
38
|
+
</v-row>
|
|
39
|
+
<InputLabel title="Description" class="mb-1 mt-2" />
|
|
40
|
+
<v-textarea v-model="f.description" rows="2" auto-grow density="comfortable" placeholder="Size, model, where it is used" />
|
|
41
|
+
<InputLabel title="Photo" class="mb-1" />
|
|
42
|
+
<InventoryPhotoInput v-model="photo" :max="1" />
|
|
43
|
+
<v-switch
|
|
44
|
+
v-if="item"
|
|
45
|
+
v-model="inUse"
|
|
46
|
+
color="primary"
|
|
47
|
+
class="mt-2"
|
|
48
|
+
hide-details
|
|
49
|
+
:label="inUse ? 'In use' : 'Not in use (hidden from requests)'"
|
|
50
|
+
/>
|
|
51
|
+
</v-form>
|
|
52
|
+
</v-card-text>
|
|
53
|
+
<div class="screen-modal__footer">
|
|
54
|
+
<v-btn class="screen-btn-ghost" variant="outlined" :disabled="saving" @click="show = false">Cancel</v-btn>
|
|
55
|
+
<v-btn class="screen-btn-primary" variant="flat" :loading="saving" @click="save">{{ item ? "Save" : "Add item" }}</v-btn>
|
|
56
|
+
</div>
|
|
57
|
+
</v-card>
|
|
58
|
+
</v-dialog>
|
|
59
|
+
</template>
|
|
60
|
+
|
|
61
|
+
<script setup lang="ts">
|
|
62
|
+
import useInventory from "../composables/useInventory";
|
|
63
|
+
import useUtils from "../composables/useUtils";
|
|
64
|
+
|
|
65
|
+
const show = defineModel<boolean>({ default: false });
|
|
66
|
+
const props = defineProps({
|
|
67
|
+
store: { type: Object as PropType<TInventoryStore>, required: true },
|
|
68
|
+
item: { type: Object as PropType<TInventoryItem | null>, default: null },
|
|
69
|
+
});
|
|
70
|
+
const emit = defineEmits(["done"]);
|
|
71
|
+
|
|
72
|
+
const { createItem, updateItem } = useInventory();
|
|
73
|
+
const { requiredRule } = useUtils();
|
|
74
|
+
const notify = inject<(text: string, color?: string) => void>("inventoryNotify", () => {});
|
|
75
|
+
|
|
76
|
+
const units = ["pcs", "box", "set", "pack", "roll", "can", "bottle", "litre", "kg", "metre"];
|
|
77
|
+
const wholeRule = (v: any) => v === "" || v === null || (Number.isInteger(Number(v)) && Number(v) >= 0) || "Enter a whole number";
|
|
78
|
+
const moneyRule = (v: any) => v === "" || v === null || Number(v) >= 0 || "Enter a valid price";
|
|
79
|
+
|
|
80
|
+
const form = ref();
|
|
81
|
+
const saving = ref(false);
|
|
82
|
+
const blank = () => ({ name: "", unit: "pcs", code: "", category: "", reorderLevel: 0, unitCost: 0, openingQty: 0, description: "" });
|
|
83
|
+
const f = reactive(blank());
|
|
84
|
+
const photo = ref<string[]>([]);
|
|
85
|
+
const inUse = ref(true);
|
|
86
|
+
|
|
87
|
+
watch(show, (open) => {
|
|
88
|
+
if (!open) return;
|
|
89
|
+
const i = props.item;
|
|
90
|
+
Object.assign(f, blank(), i ? { name: i.name, unit: i.unit, code: i.code, category: i.category, reorderLevel: i.reorderLevel, unitCost: i.unitCost ?? 0, description: i.description } : {});
|
|
91
|
+
photo.value = i?.photo ? [i.photo] : [];
|
|
92
|
+
inUse.value = i ? i.status === "active" : true;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
async function save() {
|
|
96
|
+
const { valid } = await form.value.validate();
|
|
97
|
+
if (!valid) return;
|
|
98
|
+
saving.value = true;
|
|
99
|
+
const body = {
|
|
100
|
+
name: f.name,
|
|
101
|
+
unit: f.unit,
|
|
102
|
+
code: f.code,
|
|
103
|
+
category: f.category,
|
|
104
|
+
reorderLevel: Number(f.reorderLevel || 0),
|
|
105
|
+
unitCost: Number(f.unitCost || 0),
|
|
106
|
+
description: f.description,
|
|
107
|
+
photo: photo.value[0] ?? "",
|
|
108
|
+
};
|
|
109
|
+
try {
|
|
110
|
+
if (props.item) {
|
|
111
|
+
await updateItem(props.item._id, { ...body, status: inUse.value ? "active" : "inactive" });
|
|
112
|
+
notify("Item saved.");
|
|
113
|
+
} else {
|
|
114
|
+
await createItem(props.store._id, { ...body, openingQty: Number(f.openingQty || 0) });
|
|
115
|
+
notify("Item added.");
|
|
116
|
+
}
|
|
117
|
+
show.value = false;
|
|
118
|
+
emit("done");
|
|
119
|
+
} catch (error: any) {
|
|
120
|
+
notify(error?.data?.message || "Could not save the item.", "error");
|
|
121
|
+
} finally {
|
|
122
|
+
saving.value = false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
</script>
|