@7365admin1/layer-common 4.17.1-staging.330 → 4.17.1-staging.332
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/DashboardMain.vue +19 -3
- package/components/InventoryImportDialog.vue +117 -0
- package/components/InventoryItemDetail.vue +158 -0
- package/components/InventoryItemDialog.vue +125 -0
- package/components/InventoryLegacyImportDialog.vue +108 -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 +279 -0
- package/components/InventoryRequestsTab.vue +218 -0
- package/components/InventorySettingsTab.vue +94 -0
- package/components/InventoryStockTab.vue +180 -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 +105 -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
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
:key="card.key"
|
|
18
18
|
class="print-kpi-card"
|
|
19
19
|
>
|
|
20
|
-
<span class="print-kpi-title">{{ card
|
|
20
|
+
<span class="print-kpi-title">{{ cardTitle(card) }}</span>
|
|
21
21
|
<template
|
|
22
22
|
v-if="card.key === 'supplyAlert' && Array.isArray(card.raw?.items)"
|
|
23
23
|
>
|
|
@@ -331,7 +331,7 @@
|
|
|
331
331
|
:icon="card.icon"
|
|
332
332
|
:tint="card.tint"
|
|
333
333
|
:color="card.color"
|
|
334
|
-
:label="card
|
|
334
|
+
:label="cardTitle(card)"
|
|
335
335
|
:value="card.value"
|
|
336
336
|
:chip="kpiChipText(card)"
|
|
337
337
|
:down="Number(card.percentage) < 0"
|
|
@@ -1422,7 +1422,15 @@ const moduleWidgetPermissions: Record<string, string[]> = {
|
|
|
1422
1422
|
],
|
|
1423
1423
|
staffStatus: ["attendance-mgmt:see-all-attendance"],
|
|
1424
1424
|
attendance: ["attendance-mgmt:see-all-attendance"],
|
|
1425
|
-
|
|
1425
|
+
// Inventory roles see the tile too: where a store serves the site it lists
|
|
1426
|
+
// the items at or below their alert level (core new-dashboard.repo).
|
|
1427
|
+
supplyAlert: [
|
|
1428
|
+
"supply-mgmt:see-all-supplies",
|
|
1429
|
+
"inventory:view-inventory",
|
|
1430
|
+
"inventory:request-stock",
|
|
1431
|
+
"inventory:approve-requests",
|
|
1432
|
+
"inventory:manage-inventory",
|
|
1433
|
+
],
|
|
1426
1434
|
feedbacks: [
|
|
1427
1435
|
"feedbacks:see-all-feedback",
|
|
1428
1436
|
"feedback:see-all-feedback",
|
|
@@ -1880,6 +1888,14 @@ const finalDashboardData = computed<Record<string, any>>(() => {
|
|
|
1880
1888
|
* new colour. That also makes each tile the design's own chip pairing, which
|
|
1881
1889
|
* is the ruling this project already follows.
|
|
1882
1890
|
*/
|
|
1891
|
+
/**
|
|
1892
|
+
* Where an Inventory store serves the site, the supply tile lists real low
|
|
1893
|
+
* stock (items at or below their alert level), so it is named for that.
|
|
1894
|
+
*/
|
|
1895
|
+
function cardTitle(card: { key: string; title: string; raw?: any }) {
|
|
1896
|
+
return card.key === "supplyAlert" && card.raw?.basis === "below-alert-level" ? "Low Stock" : card.title;
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1883
1899
|
const KPI_TONES = {
|
|
1884
1900
|
info: { color: "var(--info)", tint: "var(--info-bg)" },
|
|
1885
1901
|
err: { color: "var(--err)", tint: "var(--err-bg)" },
|
|
@@ -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>
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-dialog v-model="show" max-width="720" persistent scrollable>
|
|
3
|
+
<v-card class="screen-modal">
|
|
4
|
+
<v-card-title class="d-flex align-center">
|
|
5
|
+
Copy from the old Equipment list
|
|
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
|
+
<p class="text-body-2 mb-4">
|
|
11
|
+
Bring the items already kept under Equipment Management into this store, with their current quantities.
|
|
12
|
+
We check first; nothing is added until you confirm. Items already in the store are skipped.
|
|
13
|
+
</p>
|
|
14
|
+
<v-progress-linear v-if="loading" indeterminate color="primary" />
|
|
15
|
+
<p v-else-if="!groups.length" class="text-body-2 text-medium-emphasis">There is no old Equipment list at this store's properties.</p>
|
|
16
|
+
<v-radio-group v-else v-model="serviceType" hide-details class="mb-2" @update:model-value="result = null">
|
|
17
|
+
<v-radio v-for="g in groups" :key="g.serviceType" :value="g.serviceType" :label="`${label(g.serviceType)} (${g.count} items)`" />
|
|
18
|
+
</v-radio-group>
|
|
19
|
+
|
|
20
|
+
<template v-if="result">
|
|
21
|
+
<v-alert :type="result.errors ? 'warning' : 'success'" variant="tonal" class="mb-3">
|
|
22
|
+
<template v-if="result.committed">{{ result.ready }} item(s) added.</template>
|
|
23
|
+
<template v-else>{{ result.ready }} item(s) ready to add.</template>
|
|
24
|
+
<span v-if="result.skipped"> {{ result.skipped }} skipped.</span>
|
|
25
|
+
<span v-if="result.errors"> {{ result.errors }} could not be read.</span>
|
|
26
|
+
</v-alert>
|
|
27
|
+
<v-table density="compact" height="260" fixed-header>
|
|
28
|
+
<thead>
|
|
29
|
+
<tr>
|
|
30
|
+
<th>Item</th>
|
|
31
|
+
<th>Result</th>
|
|
32
|
+
</tr>
|
|
33
|
+
</thead>
|
|
34
|
+
<tbody>
|
|
35
|
+
<tr v-for="r in result.rows" :key="r.row">
|
|
36
|
+
<td>{{ r.name || "—" }}</td>
|
|
37
|
+
<td :class="r.status === 'error' ? 'text-error' : r.status === 'skipped' ? 'text-medium-emphasis' : 'text-success'">{{ r.message }}</td>
|
|
38
|
+
</tr>
|
|
39
|
+
</tbody>
|
|
40
|
+
</v-table>
|
|
41
|
+
</template>
|
|
42
|
+
</v-card-text>
|
|
43
|
+
<div class="screen-modal__footer">
|
|
44
|
+
<v-btn class="screen-btn-ghost" variant="outlined" :disabled="busy" @click="show = false">{{ result?.committed ? "Close" : "Cancel" }}</v-btn>
|
|
45
|
+
<v-btn v-if="!result" class="screen-btn-primary" variant="flat" :disabled="!serviceType" :loading="busy" @click="run(false)">Check</v-btn>
|
|
46
|
+
<v-btn v-else-if="!result.committed" class="screen-btn-primary" variant="flat" :disabled="!result.ready" :loading="busy" @click="run(true)">
|
|
47
|
+
Add {{ result.ready }} item(s)
|
|
48
|
+
</v-btn>
|
|
49
|
+
</div>
|
|
50
|
+
</v-card>
|
|
51
|
+
</v-dialog>
|
|
52
|
+
</template>
|
|
53
|
+
|
|
54
|
+
<script setup lang="ts">
|
|
55
|
+
import useInventory from "../composables/useInventory";
|
|
56
|
+
|
|
57
|
+
const show = defineModel<boolean>({ default: false });
|
|
58
|
+
const props = defineProps({ store: { type: Object as PropType<TInventoryStore>, required: true } });
|
|
59
|
+
const emit = defineEmits(["done"]);
|
|
60
|
+
|
|
61
|
+
const { getLegacyEquipment, importLegacyEquipment } = useInventory();
|
|
62
|
+
const notify = inject<(text: string, color?: string) => void>("inventoryNotify", () => {});
|
|
63
|
+
|
|
64
|
+
const SERVICE_LABELS: Record<string, string> = {
|
|
65
|
+
cleaning_services: "Cleaning",
|
|
66
|
+
mechanical_electrical_services: "M&E",
|
|
67
|
+
pest_control_services: "Pest Control",
|
|
68
|
+
pool_maintenance_services: "Pool Maintenance",
|
|
69
|
+
landscaping_services: "Landscaping",
|
|
70
|
+
};
|
|
71
|
+
const label = (serviceType: string) => SERVICE_LABELS[serviceType] ?? serviceType;
|
|
72
|
+
|
|
73
|
+
const groups = ref<{ serviceType: string; count: number }[]>([]);
|
|
74
|
+
const serviceType = ref("");
|
|
75
|
+
const loading = ref(false);
|
|
76
|
+
const busy = ref(false);
|
|
77
|
+
const result = ref<Awaited<ReturnType<typeof importLegacyEquipment>> | null>(null);
|
|
78
|
+
|
|
79
|
+
async function run(commit: boolean) {
|
|
80
|
+
busy.value = true;
|
|
81
|
+
try {
|
|
82
|
+
result.value = await importLegacyEquipment(props.store._id, serviceType.value, commit);
|
|
83
|
+
if (commit) {
|
|
84
|
+
notify(`${result.value.ready} item(s) added.`);
|
|
85
|
+
emit("done");
|
|
86
|
+
}
|
|
87
|
+
} catch (error: any) {
|
|
88
|
+
notify(error?.data?.message || "Could not copy the list.", "error");
|
|
89
|
+
} finally {
|
|
90
|
+
busy.value = false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
watch(show, async (open) => {
|
|
95
|
+
if (!open) return;
|
|
96
|
+
result.value = null;
|
|
97
|
+
serviceType.value = "";
|
|
98
|
+
loading.value = true;
|
|
99
|
+
try {
|
|
100
|
+
groups.value = await getLegacyEquipment(props.store._id);
|
|
101
|
+
if (groups.value.length === 1) serviceType.value = groups.value[0].serviceType;
|
|
102
|
+
} catch {
|
|
103
|
+
groups.value = [];
|
|
104
|
+
} finally {
|
|
105
|
+
loading.value = false;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
</script>
|