@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,177 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<v-row dense class="mb-2">
|
|
4
|
+
<v-col cols="6" md="3">
|
|
5
|
+
<AppKpiTile icon="mdi-package-variant-closed" label="Items" :value="total" />
|
|
6
|
+
</v-col>
|
|
7
|
+
<v-col cols="6" md="3">
|
|
8
|
+
<AppKpiTile icon="mdi-alert-outline" label="Low stock" :value="lowCount" :down="lowCount > 0" sub="at or below the alert level" />
|
|
9
|
+
</v-col>
|
|
10
|
+
</v-row>
|
|
11
|
+
|
|
12
|
+
<div class="d-flex flex-wrap ga-2 align-center mb-3">
|
|
13
|
+
<v-btn v-if="store.access.canManage" class="text-none screen-btn-primary" variant="flat" prepend-icon="mdi-truck-delivery-outline" @click="open('receive')">
|
|
14
|
+
Receive Stock
|
|
15
|
+
</v-btn>
|
|
16
|
+
<v-btn v-if="store.access.canApprove" class="text-none screen-btn-primary" variant="flat" prepend-icon="mdi-hand-extended-outline" @click="open('issue')">
|
|
17
|
+
Issue Stock
|
|
18
|
+
</v-btn>
|
|
19
|
+
<v-btn v-if="store.access.canRequest && !store.access.canManage" class="text-none screen-btn-primary" variant="flat" prepend-icon="mdi-cart-arrow-down" @click="open('request')">
|
|
20
|
+
Request Stock
|
|
21
|
+
</v-btn>
|
|
22
|
+
<v-menu v-if="store.access.canManage">
|
|
23
|
+
<template #activator="{ props: menu }">
|
|
24
|
+
<v-btn v-bind="menu" class="text-none screen-btn-ghost" variant="outlined" append-icon="mdi-chevron-down">Add Items</v-btn>
|
|
25
|
+
</template>
|
|
26
|
+
<v-list density="compact">
|
|
27
|
+
<v-list-item prepend-icon="mdi-plus" title="Add one item" @click="editItem(null)" />
|
|
28
|
+
<v-list-item prepend-icon="mdi-file-excel-outline" title="Import from Excel" @click="showImport = true" />
|
|
29
|
+
</v-list>
|
|
30
|
+
</v-menu>
|
|
31
|
+
<v-spacer />
|
|
32
|
+
<v-checkbox v-model="lowOnly" label="Low stock only" density="compact" hide-details class="flex-grow-0" />
|
|
33
|
+
<v-text-field
|
|
34
|
+
v-model="search"
|
|
35
|
+
density="compact"
|
|
36
|
+
placeholder="Search item, code or category"
|
|
37
|
+
clearable
|
|
38
|
+
prepend-inner-icon="mdi-magnify"
|
|
39
|
+
hide-details
|
|
40
|
+
style="min-width: 260px; max-width: 320px"
|
|
41
|
+
/>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<TableMain
|
|
45
|
+
:headers="headers"
|
|
46
|
+
:items="items"
|
|
47
|
+
:loading="loading"
|
|
48
|
+
:show-header="true"
|
|
49
|
+
v-model:page="page"
|
|
50
|
+
:pages="pages"
|
|
51
|
+
:page-range="pageRange"
|
|
52
|
+
@refresh="load"
|
|
53
|
+
@row-click="(row: any) => openItem(row.item)"
|
|
54
|
+
>
|
|
55
|
+
<template #item.name="{ item }">
|
|
56
|
+
<div class="d-flex align-center ga-3 py-1">
|
|
57
|
+
<v-avatar rounded size="36" color="grey-lighten-3">
|
|
58
|
+
<v-img v-if="item.photo" :src="getFileUrl(item.photo)" cover />
|
|
59
|
+
<v-icon v-else icon="mdi-package-variant" size="20" />
|
|
60
|
+
</v-avatar>
|
|
61
|
+
<div>
|
|
62
|
+
<div class="font-weight-medium">{{ item.name }}</div>
|
|
63
|
+
<div class="text-caption text-medium-emphasis">{{ [item.code, item.category].filter(Boolean).join(" · ") }}</div>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
</template>
|
|
67
|
+
<template #item.onHand="{ item }">
|
|
68
|
+
<span :class="item.lowStock ? 'text-error font-weight-bold' : 'font-weight-medium'">{{ item.onHand }}</span>
|
|
69
|
+
<span class="text-medium-emphasis ml-1">{{ item.unit }}</span>
|
|
70
|
+
<v-chip v-if="item.lowStock" size="x-small" color="error" variant="tonal" class="ml-2">Low</v-chip>
|
|
71
|
+
<v-chip v-if="item.status === 'inactive'" size="x-small" variant="tonal" class="ml-2">Not in use</v-chip>
|
|
72
|
+
</template>
|
|
73
|
+
<template #item.reorderLevel="{ value }">{{ value || "—" }}</template>
|
|
74
|
+
<template #item.unitCost="{ value }">{{ value !== undefined ? money(value) : "—" }}</template>
|
|
75
|
+
<template #no-data>
|
|
76
|
+
<div class="py-8 text-center">
|
|
77
|
+
<div class="text-body-1 mb-1">{{ search || lowOnly ? "No items match." : "No items in this store yet." }}</div>
|
|
78
|
+
<div v-if="!search && !lowOnly && store.access.canManage" class="text-body-2 text-medium-emphasis">
|
|
79
|
+
Use <strong>Add Items</strong> to add them one by one or import your Excel list.
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
</template>
|
|
83
|
+
</TableMain>
|
|
84
|
+
|
|
85
|
+
<InventoryLinesDialog v-model="lines.show" :mode="lines.mode" :store="store" :site-id="siteId" :sites="sites" @done="done" />
|
|
86
|
+
<InventoryItemDialog v-model="itemDialog.show" :store="store" :item="itemDialog.item" @done="done" />
|
|
87
|
+
<InventoryImportDialog v-model="showImport" :store="store" @done="done" />
|
|
88
|
+
<InventoryItemDetail v-model="detail.show" :store="store" :item="detail.item" @edit="editItem" @done="done" />
|
|
89
|
+
</div>
|
|
90
|
+
</template>
|
|
91
|
+
|
|
92
|
+
<script setup lang="ts">
|
|
93
|
+
import useInventory from "../composables/useInventory";
|
|
94
|
+
import useFile from "../composables/useFile";
|
|
95
|
+
import useUtils from "../composables/useUtils";
|
|
96
|
+
|
|
97
|
+
const props = defineProps({
|
|
98
|
+
store: { type: Object as PropType<TInventoryStore>, required: true },
|
|
99
|
+
siteId: { type: String, required: true },
|
|
100
|
+
sites: { type: Array as PropType<{ _id: string; name: string }[]>, default: () => [] },
|
|
101
|
+
});
|
|
102
|
+
const emit = defineEmits(["changed"]);
|
|
103
|
+
|
|
104
|
+
const { getItems } = useInventory();
|
|
105
|
+
const { getFileUrl } = useFile();
|
|
106
|
+
const { debounce } = useUtils();
|
|
107
|
+
|
|
108
|
+
const items = ref<TInventoryItem[]>([]);
|
|
109
|
+
const loading = ref(false);
|
|
110
|
+
const page = ref(1);
|
|
111
|
+
const pages = ref(0);
|
|
112
|
+
const total = ref(0);
|
|
113
|
+
const lowCount = ref(0);
|
|
114
|
+
const search = ref("");
|
|
115
|
+
const lowOnly = ref(false);
|
|
116
|
+
const limit = 20;
|
|
117
|
+
const pageRange = computed(() => (total.value ? `${(page.value - 1) * limit + 1}-${Math.min(page.value * limit, total.value)} of ${total.value}` : "0 of 0"));
|
|
118
|
+
|
|
119
|
+
const headers = computed(() => [
|
|
120
|
+
{ title: "Item", value: "name" },
|
|
121
|
+
{ title: "In store", value: "onHand" },
|
|
122
|
+
{ title: "Low stock alert at", value: "reorderLevel" },
|
|
123
|
+
...(props.store.access.canManage || props.store.access.canApprove ? [{ title: "Unit price", value: "unitCost" }] : []),
|
|
124
|
+
]);
|
|
125
|
+
|
|
126
|
+
const money = (v: number) => `$${Number(v).toFixed(2)}`;
|
|
127
|
+
|
|
128
|
+
async function load() {
|
|
129
|
+
loading.value = true;
|
|
130
|
+
try {
|
|
131
|
+
const res = await getItems(props.store._id, {
|
|
132
|
+
page: page.value,
|
|
133
|
+
limit,
|
|
134
|
+
search: search.value || "",
|
|
135
|
+
lowStock: lowOnly.value || undefined,
|
|
136
|
+
includeInactive: props.store.access.canManage || undefined,
|
|
137
|
+
});
|
|
138
|
+
items.value = res.items;
|
|
139
|
+
pages.value = res.pages;
|
|
140
|
+
total.value = res.total;
|
|
141
|
+
lowCount.value = res.lowCount;
|
|
142
|
+
} catch {
|
|
143
|
+
items.value = [];
|
|
144
|
+
} finally {
|
|
145
|
+
loading.value = false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const lines = reactive({ show: false, mode: "receive" as "receive" | "issue" | "request" });
|
|
150
|
+
function open(mode: "receive" | "issue" | "request") {
|
|
151
|
+
Object.assign(lines, { show: true, mode });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const itemDialog = reactive({ show: false, item: null as TInventoryItem | null });
|
|
155
|
+
function editItem(item: TInventoryItem | null) {
|
|
156
|
+
detail.show = false;
|
|
157
|
+
Object.assign(itemDialog, { show: true, item });
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const detail = reactive({ show: false, item: null as TInventoryItem | null });
|
|
161
|
+
function openItem(item: TInventoryItem) {
|
|
162
|
+
Object.assign(detail, { show: true, item });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const showImport = ref(false);
|
|
166
|
+
|
|
167
|
+
function done() {
|
|
168
|
+
load();
|
|
169
|
+
emit("changed");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
watch(page, load);
|
|
173
|
+
watch(lowOnly, () => (page.value === 1 ? load() : (page.value = 1)));
|
|
174
|
+
watch(search, debounce(() => (page.value === 1 ? load() : (page.value = 1)), 400));
|
|
175
|
+
watch(() => props.store._id, () => (page.value === 1 ? load() : (page.value = 1)));
|
|
176
|
+
onMounted(load);
|
|
177
|
+
</script>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<div class="d-flex flex-wrap ga-2 align-center mb-3">
|
|
4
|
+
<div class="text-body-2 text-medium-emphasis">Stock currently in each person's hands, taken from this store and not yet used or returned.</div>
|
|
5
|
+
<v-spacer />
|
|
6
|
+
<v-text-field v-model="search" density="compact" placeholder="Search name or item" clearable hide-details append-inner-icon="mdi-magnify" style="max-width: 280px" />
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
<v-progress-linear v-if="loading" indeterminate color="primary" />
|
|
10
|
+
<div v-else-if="!groups.length" class="text-center text-medium-emphasis py-10">Nobody is holding stock from this store.</div>
|
|
11
|
+
|
|
12
|
+
<AppCard v-for="g in groups" :key="g.holder" class="pa-4 mb-3">
|
|
13
|
+
<div class="d-flex align-center mb-2">
|
|
14
|
+
<div class="font-weight-medium">{{ g.holderName || "Unnamed" }}</div>
|
|
15
|
+
<v-spacer />
|
|
16
|
+
<v-btn class="text-none screen-btn-ghost" variant="outlined" size="small" prepend-icon="mdi-keyboard-return" @click="openReturn(g)">Receive return</v-btn>
|
|
17
|
+
</div>
|
|
18
|
+
<div class="d-flex flex-wrap ga-2">
|
|
19
|
+
<v-chip v-for="h in g.items" :key="h._id" variant="tonal">{{ h.itemName }}: {{ h.qty }} {{ h.unit }}</v-chip>
|
|
20
|
+
</div>
|
|
21
|
+
</AppCard>
|
|
22
|
+
|
|
23
|
+
<InventoryLinesDialog
|
|
24
|
+
v-model="ret.show"
|
|
25
|
+
mode="return"
|
|
26
|
+
:store="store"
|
|
27
|
+
:holder-id="ret.holder"
|
|
28
|
+
:holder-name="ret.holderName"
|
|
29
|
+
:holdings="ret.items"
|
|
30
|
+
@done="changed"
|
|
31
|
+
/>
|
|
32
|
+
</div>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<script setup lang="ts">
|
|
36
|
+
import useInventory from "../composables/useInventory";
|
|
37
|
+
|
|
38
|
+
const props = defineProps({ store: { type: Object as PropType<TInventoryStore>, required: true } });
|
|
39
|
+
const emit = defineEmits(["changed"]);
|
|
40
|
+
|
|
41
|
+
const { getHoldings } = useInventory();
|
|
42
|
+
const holdings = ref<TInventoryHolding[]>([]);
|
|
43
|
+
const loading = ref(false);
|
|
44
|
+
const search = ref("");
|
|
45
|
+
|
|
46
|
+
const groups = computed(() => {
|
|
47
|
+
const q = (search.value || "").toLowerCase();
|
|
48
|
+
const map = new Map<string, { holder: string; holderName: string; items: TInventoryHolding[] }>();
|
|
49
|
+
for (const h of holdings.value) {
|
|
50
|
+
if (q && !h.holderName.toLowerCase().includes(q) && !h.itemName.toLowerCase().includes(q)) continue;
|
|
51
|
+
const key = String(h.holder);
|
|
52
|
+
if (!map.has(key)) map.set(key, { holder: key, holderName: h.holderName, items: [] });
|
|
53
|
+
map.get(key)!.items.push(h);
|
|
54
|
+
}
|
|
55
|
+
return [...map.values()];
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
async function load() {
|
|
59
|
+
loading.value = true;
|
|
60
|
+
try {
|
|
61
|
+
holdings.value = await getHoldings(props.store._id, "all");
|
|
62
|
+
} catch {
|
|
63
|
+
holdings.value = [];
|
|
64
|
+
} finally {
|
|
65
|
+
loading.value = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const ret = reactive({ show: false, holder: "", holderName: "", items: [] as TInventoryHolding[] });
|
|
70
|
+
function openReturn(g: { holder: string; holderName: string; items: TInventoryHolding[] }) {
|
|
71
|
+
Object.assign(ret, { show: true, holder: g.holder, holderName: g.holderName, items: g.items });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function changed() {
|
|
75
|
+
load();
|
|
76
|
+
emit("changed");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
watch(() => props.store._id, load);
|
|
80
|
+
onMounted(load);
|
|
81
|
+
</script>
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-dialog v-model="show" max-width="620" persistent scrollable>
|
|
3
|
+
<v-card v-if="holding" class="screen-modal">
|
|
4
|
+
<v-card-title class="d-flex align-center">
|
|
5
|
+
Record Usage
|
|
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="font-weight-medium">{{ holding.itemName }}</div>
|
|
11
|
+
<div class="text-body-2 text-medium-emphasis mb-4">You have {{ holding.qty }} {{ holding.unit }} in hand.</div>
|
|
12
|
+
<v-form ref="form">
|
|
13
|
+
<InputLabel title="How many did you use?" required class="mb-1" />
|
|
14
|
+
<v-text-field
|
|
15
|
+
v-model.number="qty"
|
|
16
|
+
type="number"
|
|
17
|
+
min="1"
|
|
18
|
+
:max="holding.qty"
|
|
19
|
+
:suffix="holding.unit"
|
|
20
|
+
density="comfortable"
|
|
21
|
+
style="max-width: 200px"
|
|
22
|
+
:rules="[(v: any) => (Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= holding!.qty) || `1 to ${holding!.qty}`]"
|
|
23
|
+
/>
|
|
24
|
+
|
|
25
|
+
<InputLabel title="Where?" required class="mb-1" />
|
|
26
|
+
<v-btn-toggle v-model="where" mandatory divided variant="outlined" density="comfortable" class="mb-3">
|
|
27
|
+
<v-btn value="tenant_unit" class="text-none" prepend-icon="mdi-door">Tenant unit</v-btn>
|
|
28
|
+
<v-btn value="common_area" class="text-none" prepend-icon="mdi-office-building-outline">Common area</v-btn>
|
|
29
|
+
</v-btn-toggle>
|
|
30
|
+
|
|
31
|
+
<v-select
|
|
32
|
+
v-if="store.sites.length > 1"
|
|
33
|
+
v-model="site"
|
|
34
|
+
:items="siteChoices"
|
|
35
|
+
item-title="name"
|
|
36
|
+
item-value="_id"
|
|
37
|
+
label="Property"
|
|
38
|
+
density="comfortable"
|
|
39
|
+
:rules="[requiredRule]"
|
|
40
|
+
/>
|
|
41
|
+
|
|
42
|
+
<v-autocomplete
|
|
43
|
+
v-if="where === 'tenant_unit'"
|
|
44
|
+
v-model="unit"
|
|
45
|
+
:items="units"
|
|
46
|
+
item-title="name"
|
|
47
|
+
item-value="_id"
|
|
48
|
+
label="Unit"
|
|
49
|
+
placeholder="Search unit or tenant name"
|
|
50
|
+
density="comfortable"
|
|
51
|
+
no-filter
|
|
52
|
+
:loading="unitsLoading"
|
|
53
|
+
:rules="[requiredRule]"
|
|
54
|
+
@update:search="searchUnits"
|
|
55
|
+
>
|
|
56
|
+
<template #item="{ props: p, item }">
|
|
57
|
+
<v-list-item v-bind="p" :subtitle="item.raw.tenantName" />
|
|
58
|
+
</template>
|
|
59
|
+
</v-autocomplete>
|
|
60
|
+
<v-combobox
|
|
61
|
+
v-else
|
|
62
|
+
v-model="area"
|
|
63
|
+
:items="areas"
|
|
64
|
+
label="Common area"
|
|
65
|
+
placeholder="e.g. Lift lobby L3"
|
|
66
|
+
density="comfortable"
|
|
67
|
+
:rules="[requiredRule]"
|
|
68
|
+
/>
|
|
69
|
+
|
|
70
|
+
<InputLabel title="Work order / reference no. (optional)" class="mb-1" />
|
|
71
|
+
<v-text-field v-model="reference" density="comfortable" placeholder="e.g. EE202507-0002" />
|
|
72
|
+
|
|
73
|
+
<v-row dense>
|
|
74
|
+
<v-col cols="12" sm="6">
|
|
75
|
+
<InputLabel title="Photo before (optional)" class="mb-1" />
|
|
76
|
+
<InventoryPhotoInput v-model="photosBefore" :max="3" />
|
|
77
|
+
</v-col>
|
|
78
|
+
<v-col cols="12" sm="6">
|
|
79
|
+
<InputLabel title="Photo after (optional)" class="mb-1" />
|
|
80
|
+
<InventoryPhotoInput v-model="photosAfter" :max="3" />
|
|
81
|
+
</v-col>
|
|
82
|
+
</v-row>
|
|
83
|
+
|
|
84
|
+
<InputLabel title="Date used" class="mb-1 mt-3" />
|
|
85
|
+
<v-text-field v-model="date" type="date" :max="today" density="comfortable" style="max-width: 200px" />
|
|
86
|
+
<InputLabel title="Remarks (optional)" class="mb-1" />
|
|
87
|
+
<v-textarea v-model="remarks" rows="2" auto-grow density="comfortable" />
|
|
88
|
+
</v-form>
|
|
89
|
+
</v-card-text>
|
|
90
|
+
<div class="screen-modal__footer">
|
|
91
|
+
<v-btn class="screen-btn-ghost" variant="outlined" :disabled="saving" @click="show = false">Cancel</v-btn>
|
|
92
|
+
<v-btn class="screen-btn-primary" variant="flat" :loading="saving" @click="save">Save usage</v-btn>
|
|
93
|
+
</div>
|
|
94
|
+
</v-card>
|
|
95
|
+
</v-dialog>
|
|
96
|
+
</template>
|
|
97
|
+
|
|
98
|
+
<script setup lang="ts">
|
|
99
|
+
import useInventory, { pickedDate } from "../composables/useInventory";
|
|
100
|
+
import useUtils from "../composables/useUtils";
|
|
101
|
+
|
|
102
|
+
const show = defineModel<boolean>({ default: false });
|
|
103
|
+
const props = defineProps({
|
|
104
|
+
store: { type: Object as PropType<TInventoryStore>, required: true },
|
|
105
|
+
siteId: { type: String, required: true },
|
|
106
|
+
holding: { type: Object as PropType<TInventoryHolding | null>, default: null },
|
|
107
|
+
sites: { type: Array as PropType<{ _id: string; name: string }[]>, default: () => [] },
|
|
108
|
+
});
|
|
109
|
+
const emit = defineEmits(["done"]);
|
|
110
|
+
|
|
111
|
+
const api = useInventory();
|
|
112
|
+
const { requiredRule, debounce } = useUtils();
|
|
113
|
+
const notify = inject<(text: string, color?: string) => void>("inventoryNotify", () => {});
|
|
114
|
+
|
|
115
|
+
const form = ref();
|
|
116
|
+
const saving = ref(false);
|
|
117
|
+
const today = new Date().toLocaleDateString("en-CA");
|
|
118
|
+
const qty = ref<number | null>(1);
|
|
119
|
+
const where = ref<"tenant_unit" | "common_area">("tenant_unit");
|
|
120
|
+
const site = ref(props.siteId);
|
|
121
|
+
const unit = ref("");
|
|
122
|
+
const area = ref("");
|
|
123
|
+
const reference = ref("");
|
|
124
|
+
const remarks = ref("");
|
|
125
|
+
const date = ref(today);
|
|
126
|
+
const photosBefore = ref<string[]>([]);
|
|
127
|
+
const photosAfter = ref<string[]>([]);
|
|
128
|
+
|
|
129
|
+
const siteChoices = computed(() =>
|
|
130
|
+
props.sites.length ? props.sites : props.store.sites.map((_id) => ({ _id, name: _id === props.siteId ? "This property" : "Other property" })),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const units = ref<{ _id: string; name: string; tenantName: string }[]>([]);
|
|
134
|
+
const unitsLoading = ref(false);
|
|
135
|
+
const searchUnits = debounce(async (q: string) => {
|
|
136
|
+
if (!site.value) return;
|
|
137
|
+
unitsLoading.value = true;
|
|
138
|
+
try {
|
|
139
|
+
units.value = await api.getUnits(props.store._id, site.value, q || "");
|
|
140
|
+
} catch {
|
|
141
|
+
units.value = [];
|
|
142
|
+
} finally {
|
|
143
|
+
unitsLoading.value = false;
|
|
144
|
+
}
|
|
145
|
+
}, 300);
|
|
146
|
+
|
|
147
|
+
const areas = ref<string[]>([]);
|
|
148
|
+
async function loadAreas() {
|
|
149
|
+
try {
|
|
150
|
+
areas.value = await api.getCommonAreas(props.store._id, site.value);
|
|
151
|
+
} catch {
|
|
152
|
+
areas.value = [];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function save() {
|
|
157
|
+
const { valid } = await form.value.validate();
|
|
158
|
+
if (!valid || !props.holding) return;
|
|
159
|
+
saving.value = true;
|
|
160
|
+
try {
|
|
161
|
+
await api.recordUsage(props.store._id, {
|
|
162
|
+
site: site.value,
|
|
163
|
+
item: props.holding.item,
|
|
164
|
+
qty: Number(qty.value),
|
|
165
|
+
locationType: where.value,
|
|
166
|
+
...(where.value === "tenant_unit" ? { unit: unit.value } : { area: area.value }),
|
|
167
|
+
reference: reference.value,
|
|
168
|
+
date: pickedDate(date.value),
|
|
169
|
+
photosBefore: photosBefore.value,
|
|
170
|
+
photosAfter: photosAfter.value,
|
|
171
|
+
remarks: remarks.value,
|
|
172
|
+
});
|
|
173
|
+
notify("Usage saved.");
|
|
174
|
+
show.value = false;
|
|
175
|
+
emit("done");
|
|
176
|
+
} catch (error: any) {
|
|
177
|
+
notify(error?.data?.message || "Could not save the usage.", "error");
|
|
178
|
+
} finally {
|
|
179
|
+
saving.value = false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
watch(site, () => {
|
|
184
|
+
unit.value = "";
|
|
185
|
+
searchUnits("");
|
|
186
|
+
loadAreas();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
watch(show, (open) => {
|
|
190
|
+
if (!open) return;
|
|
191
|
+
photosBefore.value = [];
|
|
192
|
+
photosAfter.value = [];
|
|
193
|
+
qty.value = 1;
|
|
194
|
+
unit.value = "";
|
|
195
|
+
area.value = "";
|
|
196
|
+
reference.value = "";
|
|
197
|
+
remarks.value = "";
|
|
198
|
+
date.value = today;
|
|
199
|
+
site.value = props.store.sites.includes(props.siteId) ? props.siteId : props.store.sites[0];
|
|
200
|
+
searchUnits("");
|
|
201
|
+
loadAreas();
|
|
202
|
+
});
|
|
203
|
+
</script>
|
|
@@ -12,8 +12,10 @@ export default function useCleaningPermission() {
|
|
|
12
12
|
invitationPermissions,
|
|
13
13
|
bulletinBoardPermissions,
|
|
14
14
|
|
|
15
|
+
inventoryPermissions,
|
|
15
16
|
} = useCommonPermissions();
|
|
16
17
|
const permissions: TPermissions = {
|
|
18
|
+
inventory: inventoryPermissions,
|
|
17
19
|
members: memberPermissions,
|
|
18
20
|
feedbacks: feedbackPermissions,
|
|
19
21
|
work_order: workOrderPermissions,
|
|
@@ -86,13 +88,6 @@ export default function useCleaningPermission() {
|
|
|
86
88
|
description: "Allows the user to create/add a toilet location.",
|
|
87
89
|
},
|
|
88
90
|
},
|
|
89
|
-
|
|
90
|
-
inventory: {
|
|
91
|
-
"view-inventory": {
|
|
92
|
-
check: true,
|
|
93
|
-
description: "Allows the user to view the inventory list.",
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
91
|
// area management permissions
|
|
97
92
|
"area-mgmt": {
|
|
98
93
|
"see-all-areas": {
|
|
@@ -296,7 +296,29 @@ export function useCommonPermissions() {
|
|
|
296
296
|
|
|
297
297
|
|
|
298
298
|
|
|
299
|
+
// One inventory for every app. What each string lets a person do is decided
|
|
300
|
+
// by the API per store (`/api/inventory`); these are what a role grants.
|
|
301
|
+
const inventoryPermissions: Record<string, TPermission> = {
|
|
302
|
+
"view-inventory": {
|
|
303
|
+
check: true,
|
|
304
|
+
description: "Allows the user to see the store's stock and reports.",
|
|
305
|
+
},
|
|
306
|
+
"request-stock": {
|
|
307
|
+
check: true,
|
|
308
|
+
description: "Allows the user to request stock from the store and record where they used it.",
|
|
309
|
+
},
|
|
310
|
+
"approve-requests": {
|
|
311
|
+
check: true,
|
|
312
|
+
description: "Allows the user to approve or reject stock requests, issue stock and take returns.",
|
|
313
|
+
},
|
|
314
|
+
"manage-inventory": {
|
|
315
|
+
check: true,
|
|
316
|
+
description: "Allows the user to set up the store, add items, receive deliveries, count stock and change store settings.",
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
|
|
299
320
|
return {
|
|
321
|
+
inventoryPermissions,
|
|
300
322
|
invitationPermissions,
|
|
301
323
|
memberPermissions,
|
|
302
324
|
rolePermissions,
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inventory API (`/api/inventory`). What a person may do in a store comes back
|
|
3
|
+
* on the store itself (`store.access`), decided by the server — screens show
|
|
4
|
+
* or hide actions from that, never from a guess on the client.
|
|
5
|
+
*/
|
|
6
|
+
export default function useInventory() {
|
|
7
|
+
const api = <T = any>(url: string, options: Record<string, any> = {}) =>
|
|
8
|
+
useNuxtApp().$api<T>(`/api/inventory${url}`, options);
|
|
9
|
+
|
|
10
|
+
const typeLabels: Record<string, string> = {
|
|
11
|
+
opening: "Opening stock",
|
|
12
|
+
receive: "Received",
|
|
13
|
+
issue: "Issued",
|
|
14
|
+
use: "Used",
|
|
15
|
+
return: "Returned",
|
|
16
|
+
adjust: "Stock count",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
typeLabels,
|
|
21
|
+
|
|
22
|
+
getStores: (site: string) => api<TInventoryStore[]>("/stores", { query: { site } }),
|
|
23
|
+
createStore: (body: { org: string; sites: string[]; name: string }) =>
|
|
24
|
+
api<TInventoryStore>("/stores", { method: "POST", body }),
|
|
25
|
+
updateStore: (id: string, body: Partial<Pick<TInventoryStore, "name" | "sites" | "showInResidentApp" | "showCostInResidentApp">>) =>
|
|
26
|
+
api<TInventoryStore>(`/stores/${id}`, { method: "PATCH", body }),
|
|
27
|
+
|
|
28
|
+
getItems: (store: string, query: { page?: number; limit?: number; search?: string; lowStock?: boolean; includeInactive?: boolean }) =>
|
|
29
|
+
api<{ items: TInventoryItem[]; total: number; lowCount: number; page: number; pages: number }>(`/stores/${store}/items`, { query }),
|
|
30
|
+
createItem: (store: string, body: Record<string, any>) => api(`/stores/${store}/items`, { method: "POST", body }),
|
|
31
|
+
updateItem: (id: string, body: Record<string, any>) => api(`/items/${id}`, { method: "PATCH", body }),
|
|
32
|
+
|
|
33
|
+
receive: (store: string, body: Record<string, any>) => api(`/stores/${store}/receive`, { method: "POST", body }),
|
|
34
|
+
count: (store: string, body: { item: string; countedQty: number; reason: string }) =>
|
|
35
|
+
api(`/stores/${store}/counts`, { method: "POST", body }),
|
|
36
|
+
issue: (store: string, body: Record<string, any>) => api(`/stores/${store}/issue`, { method: "POST", body }),
|
|
37
|
+
receiveReturn: (store: string, body: Record<string, any>) => api(`/stores/${store}/returns`, { method: "POST", body }),
|
|
38
|
+
recordUsage: (store: string, body: Record<string, any>) => api(`/stores/${store}/usage`, { method: "POST", body }),
|
|
39
|
+
|
|
40
|
+
getRequests: (store: string, query: { page?: number; limit?: number; status?: string; mine?: boolean }) =>
|
|
41
|
+
api<{ items: TInventoryRequest[]; total: number; pendingCount: number; page: number; pages: number }>(`/stores/${store}/requests`, { query }),
|
|
42
|
+
createRequest: (store: string, body: Record<string, any>) => api(`/stores/${store}/requests`, { method: "POST", body }),
|
|
43
|
+
approveRequest: (id: string, body: { lines?: TInventoryLine[]; remarks?: string }) =>
|
|
44
|
+
api(`/requests/${id}/approve`, { method: "POST", body }),
|
|
45
|
+
rejectRequest: (id: string, remarks: string) => api(`/requests/${id}/reject`, { method: "POST", body: { remarks } }),
|
|
46
|
+
cancelRequest: (id: string) => api(`/requests/${id}/cancel`, { method: "POST" }),
|
|
47
|
+
|
|
48
|
+
getHoldings: (store: string, holder: string = "me") => api<TInventoryHolding[]>(`/stores/${store}/holdings`, { query: { holder } }),
|
|
49
|
+
getTransactions: (store: string, query: Record<string, any>) =>
|
|
50
|
+
api<{ items: TInventoryTransaction[]; total: number; page: number; pages: number }>(`/stores/${store}/transactions`, { query }),
|
|
51
|
+
|
|
52
|
+
getUnits: (store: string, site: string, search = "") =>
|
|
53
|
+
api<{ _id: string; name: string; tenantName: string }[]>(`/stores/${store}/units`, { query: { site, search } }),
|
|
54
|
+
getCommonAreas: (store: string, site: string) => api<string[]>(`/stores/${store}/common-areas`, { query: { site } }),
|
|
55
|
+
getPeople: (store: string, search = "") => api<{ _id: string; name: string; orgName: string }[]>(`/stores/${store}/people`, { query: { search } }),
|
|
56
|
+
|
|
57
|
+
getReport: (store: string, report: "movement" | "usage" | "technicians", query: TInventoryPeriod) =>
|
|
58
|
+
api<{ rows: any[]; totalQty?: number; totalCost?: number }>(`/stores/${store}/reports/${report}`, { query }),
|
|
59
|
+
exportReport: (store: string, report: string, query: TInventoryPeriod) =>
|
|
60
|
+
api<Blob>(`/stores/${store}/reports/${report}/export`, { query, responseType: "blob" }),
|
|
61
|
+
importTemplate: () => api<Blob>("/import-template", { responseType: "blob" }),
|
|
62
|
+
importItems: (store: string, file: File, commit: boolean) => {
|
|
63
|
+
const body = new FormData();
|
|
64
|
+
body.append("file", file);
|
|
65
|
+
return api<{ committed: boolean; ready: number; skipped: number; errors: number; rows: { row: number; name: string; status: string; message: string }[] }>(
|
|
66
|
+
`/stores/${store}/import`,
|
|
67
|
+
{ method: "POST", body, query: { commit } },
|
|
68
|
+
);
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Save a Blob as a file download in the browser. */
|
|
74
|
+
export function saveBlob(blob: Blob, filename: string) {
|
|
75
|
+
const url = URL.createObjectURL(blob);
|
|
76
|
+
const a = document.createElement("a");
|
|
77
|
+
a.href = url;
|
|
78
|
+
a.download = filename;
|
|
79
|
+
a.click();
|
|
80
|
+
URL.revokeObjectURL(url);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A date picked in a form, as the API wants it: omitted for today (the server
|
|
85
|
+
* stamps the current time), noon local time for an earlier day.
|
|
86
|
+
*/
|
|
87
|
+
export function pickedDate(value: string) {
|
|
88
|
+
if (!value || value >= new Date().toLocaleDateString("en-CA")) return undefined;
|
|
89
|
+
return new Date(`${value}T12:00:00`).toISOString();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Start and end of a local calendar month, as ISO strings the API accepts. */
|
|
93
|
+
export function monthPeriod(date = new Date()) {
|
|
94
|
+
const from = new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0, 0);
|
|
95
|
+
const to = new Date(date.getFullYear(), date.getMonth() + 1, 0, 23, 59, 59, 999);
|
|
96
|
+
return { from: from.toISOString(), to: to.toISOString() };
|
|
97
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useCommonPermissions } from "./useCommonPermission";
|
|
2
|
+
import { useLocalSetup } from "./useLocalSetup";
|
|
3
|
+
import usePermission from "./usePermission";
|
|
4
|
+
import { permissionsDenied } from "../utils/module-routes";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whether to show the Inventory menu. Any one of the four inventory
|
|
8
|
+
* permissions is enough (an empty list or `*` grants all, the estate rule);
|
|
9
|
+
* which buttons appear inside the screen is decided by the API per store.
|
|
10
|
+
*/
|
|
11
|
+
export default function useInventoryPermission() {
|
|
12
|
+
const { hasPermission } = usePermission();
|
|
13
|
+
const { inventoryPermissions } = useCommonPermissions();
|
|
14
|
+
const { userAppRole, userAppModulesDenied } = useLocalSetup();
|
|
15
|
+
const permissions = { inventory: inventoryPermissions };
|
|
16
|
+
|
|
17
|
+
const canSeeInventory = computed(() => {
|
|
18
|
+
const role = userAppRole.value;
|
|
19
|
+
if (!role) return false;
|
|
20
|
+
if (permissionsDenied(["inventory"], userAppModulesDenied?.value)) return false;
|
|
21
|
+
if (role.permissions.includes("*")) return true;
|
|
22
|
+
return (
|
|
23
|
+
hasPermission(role, permissions, "inventory", "view-inventory") ||
|
|
24
|
+
hasPermission(role, permissions, "inventory", "request-stock") ||
|
|
25
|
+
hasPermission(role, permissions, "inventory", "approve-requests") ||
|
|
26
|
+
hasPermission(role, permissions, "inventory", "manage-inventory")
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return { canSeeInventory };
|
|
31
|
+
}
|
|
@@ -30,8 +30,10 @@ export default function useLandscapingPermission() {
|
|
|
30
30
|
bulletinBoardPermissions,
|
|
31
31
|
serviceProviderPermissions,
|
|
32
32
|
|
|
33
|
+
inventoryPermissions,
|
|
33
34
|
} = useCommonPermissions();
|
|
34
35
|
const permissions: TPermissions = {
|
|
36
|
+
inventory: inventoryPermissions,
|
|
35
37
|
members: memberPermissions,
|
|
36
38
|
roles: rolePermissions,
|
|
37
39
|
invitations: invitationPermissions,
|
|
@@ -74,12 +76,6 @@ export default function useLandscapingPermission() {
|
|
|
74
76
|
description: "Allows the user to delete an emergency contact category from the system.",
|
|
75
77
|
},
|
|
76
78
|
},
|
|
77
|
-
inventory: {
|
|
78
|
-
"view-inventory": {
|
|
79
|
-
check: true,
|
|
80
|
-
description: "Allows the user to view the inventory list.",
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
79
|
// area management permissions
|
|
84
80
|
"area-mgmt": {
|
|
85
81
|
"see-all-areas": {
|