@7365admin1/layer-common 4.97.1-staging.653 → 4.97.1-staging.655
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/InventoryHistoryDialog.vue +10 -2
- package/components/InventoryItemDetail.vue +39 -3
- package/components/InventoryLinesDialog.vue +19 -2
- package/components/InventorySettingsTab.vue +13 -1
- package/components/WorkOrder/MaterialsDialog.vue +756 -0
- package/components/WorkOrder/MaterialsGroups.vue +128 -0
- package/composables/useCommonPermission.ts +15 -1
- package/composables/useInventory.ts +10 -1
- package/composables/useSecurityPermission.ts +6 -0
- package/package.json +1 -1
- package/types/inventory.d.ts +9 -0
- package/types/work-order-material.d.ts +15 -0
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
<v-text-field v-model="from" type="date" label="From" density="compact" hide-details style="max-width: 170px" />
|
|
40
40
|
<v-text-field v-model="to" type="date" label="To" density="compact" hide-details style="max-width: 170px" />
|
|
41
41
|
<v-select v-model="type" :items="typeChoices" label="What" density="compact" hide-details style="max-width: 200px" />
|
|
42
|
-
<v-
|
|
42
|
+
<v-autocomplete v-if="!item" v-model="itemPick" :items="[{ value: '', title: 'All items' }, ...itemChoices]" label="Item" density="compact" hide-details style="max-width: 240px" />
|
|
43
43
|
<v-text-field v-model="location" label="Where (unit, tenant or area)" density="compact" hide-details clearable style="max-width: 240px" />
|
|
44
44
|
</div>
|
|
45
45
|
|
|
@@ -203,7 +203,15 @@ watch(show, async (open) => {
|
|
|
203
203
|
loadHoldings();
|
|
204
204
|
if (!props.item) {
|
|
205
205
|
try {
|
|
206
|
-
|
|
206
|
+
// The API pages at 200: read every page so a big store can filter by any item.
|
|
207
|
+
// ponytail: capped at 25 pages (5,000 items); switch to a server-side search if a store outgrows it.
|
|
208
|
+
const all: { value: string; title: string }[] = [];
|
|
209
|
+
for (let page = 1, pages = 1; page <= Math.min(pages, 25); page++) {
|
|
210
|
+
const res = await api.getItems(props.store._id, { page, limit: 200 });
|
|
211
|
+
all.push(...res.items.map((i) => ({ value: i._id, title: i.name })));
|
|
212
|
+
pages = res.pages;
|
|
213
|
+
}
|
|
214
|
+
itemChoices.value = all;
|
|
207
215
|
} catch {
|
|
208
216
|
itemChoices.value = [];
|
|
209
217
|
}
|
|
@@ -65,11 +65,22 @@
|
|
|
65
65
|
<tbody>
|
|
66
66
|
<tr v-for="t in history" :key="t._id">
|
|
67
67
|
<td class="text-no-wrap">{{ formatDate(t.date) }}</td>
|
|
68
|
-
<td>
|
|
68
|
+
<td>
|
|
69
|
+
{{ typeLabels[t.type] }}
|
|
70
|
+
<template v-if="t.workOrder">
|
|
71
|
+
·
|
|
72
|
+
<NuxtLink v-if="workOrderRoute(t)" :to="workOrderRoute(t)!" class="history-wo-link" @click="show = false">
|
|
73
|
+
{{ t.workOrderNumber || t.reference }}
|
|
74
|
+
</NuxtLink>
|
|
75
|
+
<span v-else>{{ t.workOrderNumber || t.reference }}</span>
|
|
76
|
+
</template>
|
|
77
|
+
</td>
|
|
69
78
|
<td class="text-right" :class="t.storeChange > 0 ? 'text-success' : t.storeChange < 0 ? 'text-error' : ''">
|
|
70
79
|
{{ t.storeChange > 0 ? "+" : "" }}{{ t.storeChange || (t.type === "use" ? "" : 0) }}
|
|
71
80
|
</td>
|
|
72
|
-
|
|
81
|
+
<!-- Usage from a person's stock leaves the store as it was (no balance); a work order's
|
|
82
|
+
materials come off the shelf, so the store's balance shows. -->
|
|
83
|
+
<td class="text-right">{{ t.type === "use" && !t.storeChange ? "" : t.storeBalance }}</td>
|
|
73
84
|
<td class="text-caption">{{ describe(t) }}</td>
|
|
74
85
|
<td class="text-caption">{{ (t as any).createdByLabel || t.createdByName }}</td>
|
|
75
86
|
</tr>
|
|
@@ -122,6 +133,19 @@ const stepsLive = computed(() => inventoryStepsLive(props.store));
|
|
|
122
133
|
|
|
123
134
|
const formatDate = (d: string) => standardFormatDate(d);
|
|
124
135
|
|
|
136
|
+
/**
|
|
137
|
+
* The work order a "Used" row came from, in this app's Work Order Details
|
|
138
|
+
* (same organisation and site as the page). None when the work order no longer
|
|
139
|
+
* exists or the app has no work order page: the number then shows as text.
|
|
140
|
+
*/
|
|
141
|
+
const route = useRoute();
|
|
142
|
+
const router = useRouter();
|
|
143
|
+
function workOrderRoute(t: TInventoryTransaction) {
|
|
144
|
+
if (!t.workOrder || t.workOrderExists === false) return null;
|
|
145
|
+
if (!router.hasRoute("org-site-work-orders-id") || !route.params.org || !route.params.site) return null;
|
|
146
|
+
return { name: "org-site-work-orders-id", params: { org: route.params.org, site: route.params.site, id: t.workOrder } };
|
|
147
|
+
}
|
|
148
|
+
|
|
125
149
|
function describe(t: TInventoryTransaction) {
|
|
126
150
|
const parts: string[] = [];
|
|
127
151
|
if (t.type === "receive") parts.push(t.supplier || "", receiptRefText(t));
|
|
@@ -134,7 +158,8 @@ function describe(t: TInventoryTransaction) {
|
|
|
134
158
|
parts.push(
|
|
135
159
|
`${who} used ${t.qty}`,
|
|
136
160
|
t.location?.type === "tenant_unit" ? `${t.location.unitName} ${t.location.tenantName || ""}` : t.location?.area || "",
|
|
137
|
-
|
|
161
|
+
// A work order's number is shown (as a link) after "Used" instead.
|
|
162
|
+
t.workOrder ? "" : t.reference || "",
|
|
138
163
|
);
|
|
139
164
|
if (t.type === "adjust") parts.push(t.remarks || "");
|
|
140
165
|
if (t.type === "write_off") parts.push(`${t.qty} ${writeOffLabel(t.writeOffReason).toLowerCase()}`, (t.holderChange ?? 0) < 0 ? `by ${who}` : "from the shelf", t.remarks || "");
|
|
@@ -182,3 +207,14 @@ watch(show, (open) => {
|
|
|
182
207
|
load(1);
|
|
183
208
|
});
|
|
184
209
|
</script>
|
|
210
|
+
|
|
211
|
+
<style scoped>
|
|
212
|
+
.history-wo-link {
|
|
213
|
+
color: var(--accent);
|
|
214
|
+
font-weight: 600;
|
|
215
|
+
text-decoration: none;
|
|
216
|
+
}
|
|
217
|
+
.history-wo-link:hover {
|
|
218
|
+
text-decoration: underline;
|
|
219
|
+
}
|
|
220
|
+
</style>
|
|
@@ -78,6 +78,8 @@
|
|
|
78
78
|
maxlength="80"
|
|
79
79
|
style="max-width: 180px"
|
|
80
80
|
/>
|
|
81
|
+
<!-- A delivery's new item has six fields: put qty / ordered / price on their own line so none gets squashed. -->
|
|
82
|
+
<div v-if="mode === 'receive'" class="w-100" aria-hidden="true" />
|
|
81
83
|
</template>
|
|
82
84
|
<v-autocomplete
|
|
83
85
|
v-else
|
|
@@ -90,7 +92,7 @@
|
|
|
90
92
|
density="comfortable"
|
|
91
93
|
:rules="[requiredRule]"
|
|
92
94
|
class="flex-grow-1"
|
|
93
|
-
style="min-width:
|
|
95
|
+
style="min-width: 220px"
|
|
94
96
|
@update:search="(q: string) => typedSearch(line, q)"
|
|
95
97
|
>
|
|
96
98
|
<template #item="{ props: p, item }">
|
|
@@ -140,7 +142,8 @@
|
|
|
140
142
|
label="Unit price"
|
|
141
143
|
prefix="$"
|
|
142
144
|
density="comfortable"
|
|
143
|
-
|
|
145
|
+
class="line-price"
|
|
146
|
+
:class="{ 'line-price--wide': line.newItem }"
|
|
144
147
|
hint="Leave blank to keep the last price"
|
|
145
148
|
persistent-hint
|
|
146
149
|
/>
|
|
@@ -496,4 +499,18 @@ watch(show, (open) => {
|
|
|
496
499
|
height: auto !important;
|
|
497
500
|
flex-wrap: wrap;
|
|
498
501
|
}
|
|
502
|
+
/* Unit price: compact beside an existing item; wide enough for its hint on a new item's second line or a phone. */
|
|
503
|
+
.line-price {
|
|
504
|
+
flex: 1 1 140px;
|
|
505
|
+
max-width: 140px;
|
|
506
|
+
}
|
|
507
|
+
.line-price--wide {
|
|
508
|
+
flex-basis: 240px;
|
|
509
|
+
max-width: 320px;
|
|
510
|
+
}
|
|
511
|
+
@media (max-width: 599px) {
|
|
512
|
+
.line-price {
|
|
513
|
+
max-width: none;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
499
516
|
</style>
|
|
@@ -41,6 +41,13 @@
|
|
|
41
41
|
/>
|
|
42
42
|
</template>
|
|
43
43
|
|
|
44
|
+
<v-divider class="my-4" />
|
|
45
|
+
<div class="text-subtitle-1 mb-1">Work orders</div>
|
|
46
|
+
<v-switch v-model="workOrderMaterials" color="primary" hide-details label="Use for work order materials" />
|
|
47
|
+
<p class="text-body-2 text-medium-emphasis mt-1 mb-2">
|
|
48
|
+
Technicians at the properties this store supplies can pick parts from it on a work order. They're taken from stock when the work order is submitted.
|
|
49
|
+
</p>
|
|
50
|
+
|
|
44
51
|
<v-divider class="my-4" />
|
|
45
52
|
<div class="text-subtitle-1 mb-1">Service365 app</div>
|
|
46
53
|
<p class="text-body-2 text-medium-emphasis mb-2">
|
|
@@ -79,6 +86,8 @@ const sites = ref<string[]>([]);
|
|
|
79
86
|
const showInResidentApp = ref(false);
|
|
80
87
|
const showCostInResidentApp = ref(false);
|
|
81
88
|
const reminderDays = ref<number>(1);
|
|
89
|
+
/** "Use for work order materials" (2026-11); missing = off. */
|
|
90
|
+
const workOrderMaterials = ref(false);
|
|
82
91
|
const stepsLive = computed(() => inventoryStepsLive(props.store));
|
|
83
92
|
|
|
84
93
|
const siteItems = computed(() => inventorySiteOptions(props.orgSites, props.store));
|
|
@@ -89,6 +98,7 @@ function reset() {
|
|
|
89
98
|
showInResidentApp.value = props.store.showInResidentApp;
|
|
90
99
|
showCostInResidentApp.value = props.store.showCostInResidentApp;
|
|
91
100
|
reminderDays.value = props.store.lowStockReminderDays ?? 1;
|
|
101
|
+
workOrderMaterials.value = !!props.store.workOrderMaterials;
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
async function save() {
|
|
@@ -103,6 +113,8 @@ async function save() {
|
|
|
103
113
|
showCostInResidentApp: showInResidentApp.value && showCostInResidentApp.value,
|
|
104
114
|
// Only to an API that has reminders (an older one refuses the unknown field).
|
|
105
115
|
...(stepsLive.value ? { lowStockReminderDays: Number(reminderDays.value) } : {}),
|
|
116
|
+
// Only when changed: an API without the setting refuses the unknown field.
|
|
117
|
+
...(workOrderMaterials.value !== !!props.store.workOrderMaterials ? { workOrderMaterials: workOrderMaterials.value } : {}),
|
|
106
118
|
});
|
|
107
119
|
notify("Settings saved.");
|
|
108
120
|
emit("saved");
|
|
@@ -113,5 +125,5 @@ async function save() {
|
|
|
113
125
|
}
|
|
114
126
|
}
|
|
115
127
|
|
|
116
|
-
watch(() => [props.store, props.store.lowStockReminderDays], reset, { immediate: true });
|
|
128
|
+
watch(() => [props.store, props.store.lowStockReminderDays, props.store.workOrderMaterials], reset, { immediate: true });
|
|
117
129
|
</script>
|
|
@@ -0,0 +1,756 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-dialog
|
|
3
|
+
:model-value="modelValue"
|
|
4
|
+
max-width="480"
|
|
5
|
+
scrollable
|
|
6
|
+
@update:model-value="emit('update:modelValue', $event)"
|
|
7
|
+
>
|
|
8
|
+
<v-card class="mat">
|
|
9
|
+
<!-- header -->
|
|
10
|
+
<div class="mat__head">
|
|
11
|
+
<div class="mat__head-icon">
|
|
12
|
+
<v-icon icon="mdi-package-variant-closed" size="20" />
|
|
13
|
+
</div>
|
|
14
|
+
<div class="mat__head-text">
|
|
15
|
+
<div class="mat__title">Materials</div>
|
|
16
|
+
<div class="mat__subtitle">Parts taken from inventory for this job</div>
|
|
17
|
+
</div>
|
|
18
|
+
<v-btn icon="mdi-close" variant="text" size="small" aria-label="Close" @click="close" />
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<!-- search: opens the item list -->
|
|
22
|
+
<div class="mat__search">
|
|
23
|
+
<v-text-field
|
|
24
|
+
v-model="search"
|
|
25
|
+
placeholder="Search item, code or category"
|
|
26
|
+
prepend-inner-icon="mdi-magnify"
|
|
27
|
+
density="comfortable"
|
|
28
|
+
variant="outlined"
|
|
29
|
+
rounded="lg"
|
|
30
|
+
hide-details
|
|
31
|
+
clearable
|
|
32
|
+
@focus="listOpen = true"
|
|
33
|
+
@click="listOpen = true"
|
|
34
|
+
/>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<!-- the item list, like a multiple select -->
|
|
38
|
+
<template v-if="listOpen">
|
|
39
|
+
<div v-if="!noStore" class="mat__bar">
|
|
40
|
+
<span>{{ loading ? "Loading..." : `${items.length} item${items.length === 1 ? "" : "s"}` }}</span>
|
|
41
|
+
<span v-if="pickedList.length" class="mat__bar-picked">{{ pickedList.length }} selected</span>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<v-card-text class="mat__body pa-0">
|
|
45
|
+
<div v-if="loading && !items.length" class="mat__state">
|
|
46
|
+
<v-progress-circular indeterminate size="24" color="primary" />
|
|
47
|
+
</div>
|
|
48
|
+
<!-- no store here is set up for work orders: a setup gap, not a failure - say how to fix it -->
|
|
49
|
+
<div v-else-if="noStore" class="mat__state mat__state--empty">
|
|
50
|
+
<div class="mat__empty-icon">
|
|
51
|
+
<v-icon icon="mdi-store-off-outline" size="26" />
|
|
52
|
+
</div>
|
|
53
|
+
<div class="mat__empty-title">No store is set up for work orders here</div>
|
|
54
|
+
<div>
|
|
55
|
+
A store's manager can turn on "Use for work order materials" in Inventory, Settings. The store
|
|
56
|
+
must also supply this property.
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
<div v-else-if="loadError" class="mat__state">
|
|
60
|
+
<v-icon icon="mdi-alert-circle-outline" size="28" color="error" />
|
|
61
|
+
<span class="text-error">{{ loadError }}</span>
|
|
62
|
+
</div>
|
|
63
|
+
<div v-else-if="!items.length" class="mat__state">
|
|
64
|
+
<v-icon icon="mdi-magnify-close" size="28" />
|
|
65
|
+
<span>No items match "{{ search }}"</span>
|
|
66
|
+
</div>
|
|
67
|
+
|
|
68
|
+
<div
|
|
69
|
+
v-for="item in items"
|
|
70
|
+
:key="item._id"
|
|
71
|
+
class="mat__opt"
|
|
72
|
+
:class="{ 'mat__opt--on': isPicked(item), 'mat__opt--out': !canPick(item) && !isPicked(item) }"
|
|
73
|
+
role="checkbox"
|
|
74
|
+
:aria-checked="isPicked(item)"
|
|
75
|
+
:aria-disabled="!canPick(item)"
|
|
76
|
+
@click="toggle(item)"
|
|
77
|
+
>
|
|
78
|
+
<v-checkbox-btn
|
|
79
|
+
:model-value="isPicked(item)"
|
|
80
|
+
color="primary"
|
|
81
|
+
density="compact"
|
|
82
|
+
class="flex-grow-0"
|
|
83
|
+
@update:model-value="toggle(item)"
|
|
84
|
+
@click.stop
|
|
85
|
+
/>
|
|
86
|
+
<div class="mat__main">
|
|
87
|
+
<div class="mat__name">{{ item.name }}</div>
|
|
88
|
+
<div class="mat__meta">{{ metaOf(item) }}</div>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="mat__side">
|
|
91
|
+
<div class="mat__price">{{ money(item.unitCost) }}</div>
|
|
92
|
+
<span class="mat__pill" :class="`mat__pill--${stockTone(item)}`">{{ stockText(item) }}</span>
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
</v-card-text>
|
|
96
|
+
|
|
97
|
+
<div class="mat__foot">
|
|
98
|
+
<v-btn
|
|
99
|
+
block
|
|
100
|
+
color="primary"
|
|
101
|
+
elevation="0"
|
|
102
|
+
height="44"
|
|
103
|
+
rounded="lg"
|
|
104
|
+
class="text-none"
|
|
105
|
+
:text="pickedList.length ? `Done · ${pickedList.length} selected` : 'Done'"
|
|
106
|
+
@click="closeList"
|
|
107
|
+
/>
|
|
108
|
+
</div>
|
|
109
|
+
</template>
|
|
110
|
+
|
|
111
|
+
<!-- the selected items, with their quantities -->
|
|
112
|
+
<template v-else>
|
|
113
|
+
<v-card-text class="mat__body pa-0">
|
|
114
|
+
<div v-if="!pickedList.length" class="mat__state mat__state--empty">
|
|
115
|
+
<div class="mat__empty-icon">
|
|
116
|
+
<v-icon icon="mdi-package-variant" size="26" />
|
|
117
|
+
</div>
|
|
118
|
+
<div class="mat__empty-title">No materials yet</div>
|
|
119
|
+
<div>Search to pick parts from inventory.</div>
|
|
120
|
+
<v-btn
|
|
121
|
+
variant="tonal"
|
|
122
|
+
color="primary"
|
|
123
|
+
rounded="lg"
|
|
124
|
+
class="text-none mt-3"
|
|
125
|
+
prepend-icon="mdi-format-list-checks"
|
|
126
|
+
text="Browse items"
|
|
127
|
+
@click="listOpen = true"
|
|
128
|
+
/>
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
<div
|
|
132
|
+
v-for="line in pickedList"
|
|
133
|
+
:key="line.item"
|
|
134
|
+
class="mat__line"
|
|
135
|
+
:class="{ 'mat__line--out': line.stock <= 0 }"
|
|
136
|
+
>
|
|
137
|
+
<div class="mat__line-top">
|
|
138
|
+
<div class="mat__main">
|
|
139
|
+
<div class="mat__name">{{ line.name }}</div>
|
|
140
|
+
<div class="mat__meta">{{ money(line.unitCost) }} each<template v-if="stores.length > 1 && line.storeName"> · {{ line.storeName }}</template></div>
|
|
141
|
+
</div>
|
|
142
|
+
<div class="mat__subtotal">{{ money(line.qty * line.unitCost) }}</div>
|
|
143
|
+
</div>
|
|
144
|
+
<div class="mat__line-bottom">
|
|
145
|
+
<div class="mat__stepper" :class="{ 'mat__stepper--off': line.stock <= 0 }">
|
|
146
|
+
<button
|
|
147
|
+
type="button"
|
|
148
|
+
class="mat__step"
|
|
149
|
+
aria-label="Less"
|
|
150
|
+
:disabled="line.qty <= 1"
|
|
151
|
+
@click="setQty(lineItem(line), line.qty - 1)"
|
|
152
|
+
>
|
|
153
|
+
<v-icon icon="mdi-minus" size="16" />
|
|
154
|
+
</button>
|
|
155
|
+
<input
|
|
156
|
+
:value="line.qty"
|
|
157
|
+
type="number"
|
|
158
|
+
min="1"
|
|
159
|
+
:max="line.stock"
|
|
160
|
+
:disabled="line.stock <= 0"
|
|
161
|
+
class="mat__qty"
|
|
162
|
+
aria-label="Quantity"
|
|
163
|
+
@change="setQty(lineItem(line), Number(($event.target as HTMLInputElement).value))"
|
|
164
|
+
/>
|
|
165
|
+
<button
|
|
166
|
+
type="button"
|
|
167
|
+
class="mat__step"
|
|
168
|
+
aria-label="More"
|
|
169
|
+
:disabled="line.qty >= line.stock"
|
|
170
|
+
@click="setQty(lineItem(line), line.qty + 1)"
|
|
171
|
+
>
|
|
172
|
+
<v-icon icon="mdi-plus" size="16" />
|
|
173
|
+
</button>
|
|
174
|
+
</div>
|
|
175
|
+
<span v-if="line.stock <= 0" class="mat__pill mat__pill--err">Out of stock · remove it</span>
|
|
176
|
+
<span v-else class="mat__of">of {{ line.stock }} in stock</span>
|
|
177
|
+
<v-spacer />
|
|
178
|
+
<v-btn
|
|
179
|
+
icon="mdi-trash-can-outline"
|
|
180
|
+
variant="text"
|
|
181
|
+
size="small"
|
|
182
|
+
color="error"
|
|
183
|
+
aria-label="Remove"
|
|
184
|
+
@click="toggle(lineItem(line))"
|
|
185
|
+
/>
|
|
186
|
+
</div>
|
|
187
|
+
</div>
|
|
188
|
+
</v-card-text>
|
|
189
|
+
|
|
190
|
+
<div class="mat__foot">
|
|
191
|
+
<div class="mat__total">
|
|
192
|
+
<div>
|
|
193
|
+
<div class="mat__total-label">Grand Total</div>
|
|
194
|
+
<div v-if="pickedList.length" class="mat__total-sub">
|
|
195
|
+
{{ pickedList.length }} item{{ pickedList.length === 1 ? "" : "s" }} · {{ totalQty }} pcs
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
198
|
+
<div class="mat__total-value">{{ money(grandTotal) }}</div>
|
|
199
|
+
</div>
|
|
200
|
+
<div v-if="outOfStockLines.length" class="mat__blocked">
|
|
201
|
+
<v-icon icon="mdi-alert-circle-outline" size="16" />
|
|
202
|
+
Remove {{ outOfStockLines.length === 1 ? "the out-of-stock item" : `the ${outOfStockLines.length} out-of-stock items` }} to continue.
|
|
203
|
+
</div>
|
|
204
|
+
<v-btn
|
|
205
|
+
block
|
|
206
|
+
color="primary"
|
|
207
|
+
elevation="0"
|
|
208
|
+
height="44"
|
|
209
|
+
rounded="lg"
|
|
210
|
+
class="text-none"
|
|
211
|
+
:text="value.length ? 'Update Materials' : 'Add Materials'"
|
|
212
|
+
:disabled="(!value.length && !pickedList.length) || outOfStockLines.length > 0"
|
|
213
|
+
@click="save"
|
|
214
|
+
/>
|
|
215
|
+
</div>
|
|
216
|
+
</template>
|
|
217
|
+
</v-card>
|
|
218
|
+
|
|
219
|
+
<Snackbar v-model="snackbar" :text="snackText" color="error" />
|
|
220
|
+
</v-dialog>
|
|
221
|
+
</template>
|
|
222
|
+
|
|
223
|
+
<script setup lang="ts">
|
|
224
|
+
/**
|
|
225
|
+
* Pick materials (parts) for a work order from the inventory stores this
|
|
226
|
+
* account can see at the site. An item with no stock cannot be picked; the
|
|
227
|
+
* quantity cannot go above what is in stock, and each load re-reads the stock.
|
|
228
|
+
* The picks are taken from stock by the work order / feedback submit
|
|
229
|
+
* (API-core), all or nothing. Shared by the service apps (2026-11).
|
|
230
|
+
*/
|
|
231
|
+
import useInventory from "../../composables/useInventory";
|
|
232
|
+
import { errorConverter } from "../../utils/data";
|
|
233
|
+
const props = defineProps<{
|
|
234
|
+
modelValue: boolean;
|
|
235
|
+
site: string;
|
|
236
|
+
/** The materials already on the work order. */
|
|
237
|
+
value: TWorkOrderMaterial[];
|
|
238
|
+
}>();
|
|
239
|
+
const emit = defineEmits<{
|
|
240
|
+
(e: "update:modelValue", open: boolean): void;
|
|
241
|
+
(e: "save", lines: TWorkOrderMaterial[]): void;
|
|
242
|
+
}>();
|
|
243
|
+
|
|
244
|
+
const { getWorkOrderItems } = useInventory();
|
|
245
|
+
|
|
246
|
+
/** The stores the items come from (to name the store when there is more than one). */
|
|
247
|
+
const stores = ref<{ _id: string; name: string; orgName: string; ownerType: string }[]>([]);
|
|
248
|
+
type TPickItem = TInventoryItem & { storeName?: string };
|
|
249
|
+
const items = ref<TPickItem[]>([]);
|
|
250
|
+
const loading = ref(false);
|
|
251
|
+
const loadError = ref("");
|
|
252
|
+
const search = ref("");
|
|
253
|
+
|
|
254
|
+
/** Picked items by id, kept across searches. */
|
|
255
|
+
const picked = ref<Record<string, TWorkOrderMaterial>>({});
|
|
256
|
+
const pickedList = computed(() => Object.values(picked.value));
|
|
257
|
+
|
|
258
|
+
const snackbar = ref(false);
|
|
259
|
+
const snackText = ref("");
|
|
260
|
+
function warn(text: string) {
|
|
261
|
+
snackText.value = text;
|
|
262
|
+
snackbar.value = true;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const stockOf = (item: { available?: number; onHand?: number }) =>
|
|
266
|
+
Math.max(0, Number(item.available ?? item.onHand ?? 0));
|
|
267
|
+
const money = (n?: number) => `S$${Number(n ?? 0).toFixed(2)}`;
|
|
268
|
+
const isPicked = (item: TInventoryItem) => Boolean(picked.value[item._id]);
|
|
269
|
+
const canPick = (item: TInventoryItem) => stockOf(item) > 0;
|
|
270
|
+
|
|
271
|
+
/** Code · category · store, whichever are set. */
|
|
272
|
+
function metaOf(item: TPickItem) {
|
|
273
|
+
return [item.code, item.category, stores.value.length > 1 ? item.storeName : ""]
|
|
274
|
+
.filter(Boolean)
|
|
275
|
+
.join(" · ");
|
|
276
|
+
}
|
|
277
|
+
/** Stock pill: out of stock, low (at or below the alert level), or in stock. */
|
|
278
|
+
function stockTone(item: TInventoryItem) {
|
|
279
|
+
const n = stockOf(item);
|
|
280
|
+
if (n <= 0) return "err";
|
|
281
|
+
return item.lowStock || (item.reorderLevel > 0 && n <= item.reorderLevel) ? "warn" : "ok";
|
|
282
|
+
}
|
|
283
|
+
function stockText(item: TInventoryItem) {
|
|
284
|
+
const n = stockOf(item);
|
|
285
|
+
if (n <= 0) return "Out of stock";
|
|
286
|
+
return stockTone(item) === "warn" ? `Low · ${n} left` : `${n} in stock`;
|
|
287
|
+
}
|
|
288
|
+
const totalQty = computed(() => pickedList.value.reduce((sum, p) => sum + p.qty, 0));
|
|
289
|
+
|
|
290
|
+
/** The item list (checkboxes) is open: from the search box, closed with Done. */
|
|
291
|
+
const listOpen = ref(false);
|
|
292
|
+
function closeList() {
|
|
293
|
+
listOpen.value = false;
|
|
294
|
+
search.value = "";
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** A selected line as an item, for toggle / setQty. */
|
|
298
|
+
function lineItem(p: TWorkOrderMaterial): TInventoryItem {
|
|
299
|
+
return {
|
|
300
|
+
_id: p.item,
|
|
301
|
+
store: p.store,
|
|
302
|
+
storeName: p.storeName,
|
|
303
|
+
name: p.name,
|
|
304
|
+
unitCost: p.unitCost,
|
|
305
|
+
available: p.stock,
|
|
306
|
+
onHand: p.stock,
|
|
307
|
+
} as TInventoryItem;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const grandTotal = computed(() =>
|
|
311
|
+
pickedList.value.reduce((sum, p) => sum + p.qty * Number(p.unitCost ?? 0), 0),
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
function toggle(item: TInventoryItem) {
|
|
315
|
+
if (picked.value[item._id]) {
|
|
316
|
+
const { [item._id]: _gone, ...rest } = picked.value;
|
|
317
|
+
picked.value = rest;
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (stockOf(item) <= 0) {
|
|
321
|
+
warn(`${item.name} is out of stock.`);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
picked.value = {
|
|
325
|
+
...picked.value,
|
|
326
|
+
[item._id]: {
|
|
327
|
+
item: item._id,
|
|
328
|
+
store: item.store,
|
|
329
|
+
storeName: (item as TPickItem).storeName,
|
|
330
|
+
name: item.name,
|
|
331
|
+
code: item.code,
|
|
332
|
+
unit: item.unit,
|
|
333
|
+
unitCost: Number(item.unitCost ?? 0),
|
|
334
|
+
stock: stockOf(item),
|
|
335
|
+
qty: 1,
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function setQty(item: TInventoryItem, qty: number) {
|
|
341
|
+
const line = picked.value[item._id];
|
|
342
|
+
if (!line) return;
|
|
343
|
+
const max = stockOf(item);
|
|
344
|
+
let next = Math.floor(Number.isFinite(qty) ? qty : 1);
|
|
345
|
+
if (next > max) {
|
|
346
|
+
warn(`Only ${max} in stock for ${item.name}.`);
|
|
347
|
+
next = max;
|
|
348
|
+
}
|
|
349
|
+
if (next < 1) next = max > 0 ? 1 : 0;
|
|
350
|
+
picked.value = { ...picked.value, [item._id]: { ...line, qty: next } };
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** Selected lines whose item has run out since they were picked. */
|
|
354
|
+
const outOfStockLines = computed(() => pickedList.value.filter((p) => p.stock <= 0));
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Bring the selected lines up to date with fresh stock (someone else may have
|
|
358
|
+
* used it): the stock and price follow the store, and a quantity above what
|
|
359
|
+
* is left drops to what is left - the most that can be taken. Returns what
|
|
360
|
+
* changed, to tell the person.
|
|
361
|
+
*/
|
|
362
|
+
function syncPicked(fresh: TPickItem[]): string[] {
|
|
363
|
+
const byId = new Map(fresh.map((i) => [i._id, i]));
|
|
364
|
+
const changes: string[] = [];
|
|
365
|
+
const next = { ...picked.value };
|
|
366
|
+
for (const line of pickedList.value) {
|
|
367
|
+
const item = byId.get(line.item);
|
|
368
|
+
if (!item) continue;
|
|
369
|
+
const stock = stockOf(item);
|
|
370
|
+
const qty = Math.min(line.qty, stock);
|
|
371
|
+
if (stock === line.stock && qty === line.qty && Number(item.unitCost ?? 0) === line.unitCost) continue;
|
|
372
|
+
if (stock <= 0) changes.push(`${line.name} is now out of stock`);
|
|
373
|
+
else if (qty < line.qty) changes.push(`${line.name}: only ${stock} left, quantity set to ${qty}`);
|
|
374
|
+
next[line.item] = { ...line, stock, qty, unitCost: Number(item.unitCost ?? 0) };
|
|
375
|
+
}
|
|
376
|
+
picked.value = next;
|
|
377
|
+
return changes;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** No store at this property is switched on for work orders (asked again on each load). */
|
|
381
|
+
const noStore = ref(false);
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Items from the stores at the site that are switched on for work orders ("Use for work order
|
|
385
|
+
* materials") and this person may use - the company's own store, the property's store - in one
|
|
386
|
+
* call (API-core GET /inventory/work-order-items). Active items only ("Not in use" are hidden).
|
|
387
|
+
*/
|
|
388
|
+
let seq = 0;
|
|
389
|
+
/** `notice`: said first when the stock was re-read because a submit was refused. */
|
|
390
|
+
async function load(notice = "") {
|
|
391
|
+
const mine = ++seq;
|
|
392
|
+
loading.value = true;
|
|
393
|
+
loadError.value = "";
|
|
394
|
+
try {
|
|
395
|
+
const res = await getWorkOrderItems(props.site, search.value?.trim() || "");
|
|
396
|
+
if (mine !== seq) return;
|
|
397
|
+
stores.value = res?.stores ?? [];
|
|
398
|
+
noStore.value = !stores.value.length;
|
|
399
|
+
const merged: TPickItem[] = (res?.items ?? []).filter((item) => item.status !== "inactive");
|
|
400
|
+
if (mine === seq) {
|
|
401
|
+
items.value = merged;
|
|
402
|
+
const changes = syncPicked(merged);
|
|
403
|
+
const text = [notice, changes.join(". ")].filter(Boolean).join(" ");
|
|
404
|
+
if (text) warn(changes.length ? `${text}.` : text);
|
|
405
|
+
}
|
|
406
|
+
} catch (error) {
|
|
407
|
+
if (mine === seq) loadError.value = errorConverter(error);
|
|
408
|
+
} finally {
|
|
409
|
+
if (mine === seq) loading.value = false;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
414
|
+
watch(search, (text) => {
|
|
415
|
+
if (text) listOpen.value = true;
|
|
416
|
+
clearTimeout(timer);
|
|
417
|
+
timer = setTimeout(() => load(), 300);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* After a submit is refused for stock (another technician used it first): the
|
|
422
|
+
* page opens this dialog and calls refresh with the server's message; the
|
|
423
|
+
* stock is read again and the quantities brought down to what is left.
|
|
424
|
+
*/
|
|
425
|
+
async function refresh(notice = "") {
|
|
426
|
+
listOpen.value = false;
|
|
427
|
+
search.value = "";
|
|
428
|
+
clearTimeout(timer);
|
|
429
|
+
await load(notice);
|
|
430
|
+
}
|
|
431
|
+
defineExpose({ refresh });
|
|
432
|
+
|
|
433
|
+
watch(
|
|
434
|
+
() => props.modelValue,
|
|
435
|
+
(open) => {
|
|
436
|
+
if (!open) return;
|
|
437
|
+
picked.value = Object.fromEntries(props.value.map((m) => [m.item, { ...m }]));
|
|
438
|
+
listOpen.value = false;
|
|
439
|
+
if (search.value) search.value = ""; // its watcher reloads
|
|
440
|
+
else load();
|
|
441
|
+
},
|
|
442
|
+
{ immediate: true },
|
|
443
|
+
);
|
|
444
|
+
|
|
445
|
+
function close() {
|
|
446
|
+
emit("update:modelValue", false);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function save() {
|
|
450
|
+
if (outOfStockLines.value.length) {
|
|
451
|
+
warn("Remove the out-of-stock items first.");
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
emit("save", pickedList.value.map((p) => ({ ...p })));
|
|
455
|
+
close();
|
|
456
|
+
}
|
|
457
|
+
</script>
|
|
458
|
+
|
|
459
|
+
<style scoped>
|
|
460
|
+
.mat {
|
|
461
|
+
border-radius: 16px !important;
|
|
462
|
+
background: var(--card);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/* header */
|
|
466
|
+
.mat__head {
|
|
467
|
+
display: flex;
|
|
468
|
+
align-items: center;
|
|
469
|
+
gap: 12px;
|
|
470
|
+
padding: 16px 12px 12px 20px;
|
|
471
|
+
}
|
|
472
|
+
.mat__head-icon {
|
|
473
|
+
display: flex;
|
|
474
|
+
align-items: center;
|
|
475
|
+
justify-content: center;
|
|
476
|
+
width: 38px;
|
|
477
|
+
height: 38px;
|
|
478
|
+
border-radius: 10px;
|
|
479
|
+
background: var(--accent-soft);
|
|
480
|
+
color: var(--accent);
|
|
481
|
+
flex: 0 0 auto;
|
|
482
|
+
}
|
|
483
|
+
.mat__head-text {
|
|
484
|
+
flex: 1;
|
|
485
|
+
min-width: 0;
|
|
486
|
+
}
|
|
487
|
+
.mat__title {
|
|
488
|
+
font-size: 16px;
|
|
489
|
+
font-weight: 800;
|
|
490
|
+
line-height: 1.2;
|
|
491
|
+
}
|
|
492
|
+
.mat__subtitle {
|
|
493
|
+
font-size: 12.5px;
|
|
494
|
+
color: var(--muted);
|
|
495
|
+
margin-top: 2px;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
.mat__search {
|
|
499
|
+
padding: 0 20px 14px;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/* list header strip */
|
|
503
|
+
.mat__bar {
|
|
504
|
+
display: flex;
|
|
505
|
+
justify-content: space-between;
|
|
506
|
+
padding: 8px 20px;
|
|
507
|
+
font-size: 11.5px;
|
|
508
|
+
font-weight: 700;
|
|
509
|
+
letter-spacing: 0.04em;
|
|
510
|
+
text-transform: uppercase;
|
|
511
|
+
color: var(--muted);
|
|
512
|
+
background: var(--thead);
|
|
513
|
+
border-top: 1px solid var(--border);
|
|
514
|
+
border-bottom: 1px solid var(--border);
|
|
515
|
+
}
|
|
516
|
+
.mat__bar-picked {
|
|
517
|
+
color: var(--accent);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
.mat__body {
|
|
521
|
+
max-height: 56vh;
|
|
522
|
+
border-top: 1px solid var(--border);
|
|
523
|
+
}
|
|
524
|
+
.mat__bar + .mat__body {
|
|
525
|
+
border-top: 0;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/* empty / loading / error */
|
|
529
|
+
.mat__state {
|
|
530
|
+
display: flex;
|
|
531
|
+
flex-direction: column;
|
|
532
|
+
align-items: center;
|
|
533
|
+
gap: 8px;
|
|
534
|
+
padding: 36px 20px;
|
|
535
|
+
font-size: 13px;
|
|
536
|
+
color: var(--muted);
|
|
537
|
+
text-align: center;
|
|
538
|
+
}
|
|
539
|
+
.mat__empty-icon {
|
|
540
|
+
display: flex;
|
|
541
|
+
align-items: center;
|
|
542
|
+
justify-content: center;
|
|
543
|
+
width: 52px;
|
|
544
|
+
height: 52px;
|
|
545
|
+
border-radius: 50%;
|
|
546
|
+
background: var(--accent-soft);
|
|
547
|
+
color: var(--accent);
|
|
548
|
+
margin-bottom: 4px;
|
|
549
|
+
}
|
|
550
|
+
.mat__empty-title {
|
|
551
|
+
font-size: 14px;
|
|
552
|
+
font-weight: 700;
|
|
553
|
+
color: var(--text);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/* an option in the item list */
|
|
557
|
+
.mat__opt {
|
|
558
|
+
display: flex;
|
|
559
|
+
align-items: center;
|
|
560
|
+
gap: 10px;
|
|
561
|
+
padding: 10px 20px 10px 12px;
|
|
562
|
+
border-bottom: 1px solid var(--border);
|
|
563
|
+
cursor: pointer;
|
|
564
|
+
transition: background 0.12s ease;
|
|
565
|
+
}
|
|
566
|
+
.mat__opt:hover {
|
|
567
|
+
background: var(--hover);
|
|
568
|
+
}
|
|
569
|
+
.mat__opt--on {
|
|
570
|
+
background: var(--accent-soft);
|
|
571
|
+
}
|
|
572
|
+
.mat__opt--on:hover {
|
|
573
|
+
background: var(--accent-soft);
|
|
574
|
+
}
|
|
575
|
+
.mat__opt--out {
|
|
576
|
+
cursor: not-allowed;
|
|
577
|
+
}
|
|
578
|
+
.mat__opt--out .mat__main,
|
|
579
|
+
.mat__opt--out .mat__price,
|
|
580
|
+
.mat__opt--out :deep(.v-selection-control) {
|
|
581
|
+
opacity: 0.45;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
.mat__main {
|
|
585
|
+
flex: 1;
|
|
586
|
+
min-width: 0;
|
|
587
|
+
}
|
|
588
|
+
.mat__name {
|
|
589
|
+
font-size: 13.5px;
|
|
590
|
+
font-weight: 600;
|
|
591
|
+
line-height: 1.35;
|
|
592
|
+
color: var(--text);
|
|
593
|
+
}
|
|
594
|
+
.mat__meta {
|
|
595
|
+
font-size: 12px;
|
|
596
|
+
color: var(--muted);
|
|
597
|
+
margin-top: 2px;
|
|
598
|
+
white-space: nowrap;
|
|
599
|
+
overflow: hidden;
|
|
600
|
+
text-overflow: ellipsis;
|
|
601
|
+
}
|
|
602
|
+
.mat__side {
|
|
603
|
+
display: flex;
|
|
604
|
+
flex-direction: column;
|
|
605
|
+
align-items: flex-end;
|
|
606
|
+
gap: 4px;
|
|
607
|
+
flex: 0 0 auto;
|
|
608
|
+
}
|
|
609
|
+
.mat__price {
|
|
610
|
+
font-size: 13.5px;
|
|
611
|
+
font-weight: 700;
|
|
612
|
+
font-variant-numeric: tabular-nums;
|
|
613
|
+
}
|
|
614
|
+
.mat__pill {
|
|
615
|
+
display: inline-flex;
|
|
616
|
+
padding: 2px 8px;
|
|
617
|
+
border-radius: 999px;
|
|
618
|
+
font-size: 11px;
|
|
619
|
+
font-weight: 700;
|
|
620
|
+
white-space: nowrap;
|
|
621
|
+
}
|
|
622
|
+
.mat__pill--ok {
|
|
623
|
+
color: var(--ok);
|
|
624
|
+
background: var(--ok-bg);
|
|
625
|
+
}
|
|
626
|
+
.mat__pill--warn {
|
|
627
|
+
color: var(--warn);
|
|
628
|
+
background: var(--warn-bg);
|
|
629
|
+
}
|
|
630
|
+
.mat__pill--err {
|
|
631
|
+
color: var(--err);
|
|
632
|
+
background: var(--err-bg);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/* a selected line */
|
|
636
|
+
.mat__line {
|
|
637
|
+
padding: 14px 20px 10px;
|
|
638
|
+
border-bottom: 1px solid var(--border);
|
|
639
|
+
}
|
|
640
|
+
.mat__line-top {
|
|
641
|
+
display: flex;
|
|
642
|
+
align-items: flex-start;
|
|
643
|
+
gap: 12px;
|
|
644
|
+
}
|
|
645
|
+
.mat__subtotal {
|
|
646
|
+
font-size: 14px;
|
|
647
|
+
font-weight: 800;
|
|
648
|
+
font-variant-numeric: tabular-nums;
|
|
649
|
+
flex: 0 0 auto;
|
|
650
|
+
}
|
|
651
|
+
.mat__line-bottom {
|
|
652
|
+
display: flex;
|
|
653
|
+
align-items: center;
|
|
654
|
+
gap: 10px;
|
|
655
|
+
margin-top: 10px;
|
|
656
|
+
}
|
|
657
|
+
.mat__stepper {
|
|
658
|
+
display: inline-flex;
|
|
659
|
+
align-items: center;
|
|
660
|
+
border: 1px solid var(--border);
|
|
661
|
+
border-radius: 10px;
|
|
662
|
+
overflow: hidden;
|
|
663
|
+
}
|
|
664
|
+
.mat__step {
|
|
665
|
+
display: flex;
|
|
666
|
+
align-items: center;
|
|
667
|
+
justify-content: center;
|
|
668
|
+
width: 34px;
|
|
669
|
+
height: 34px;
|
|
670
|
+
color: var(--text2);
|
|
671
|
+
background: transparent;
|
|
672
|
+
border: 0;
|
|
673
|
+
cursor: pointer;
|
|
674
|
+
}
|
|
675
|
+
.mat__step:hover:not(:disabled) {
|
|
676
|
+
background: var(--hover);
|
|
677
|
+
}
|
|
678
|
+
.mat__step:disabled {
|
|
679
|
+
opacity: 0.35;
|
|
680
|
+
cursor: not-allowed;
|
|
681
|
+
}
|
|
682
|
+
.mat__qty {
|
|
683
|
+
width: 48px;
|
|
684
|
+
height: 34px;
|
|
685
|
+
border: 0;
|
|
686
|
+
border-left: 1px solid var(--border);
|
|
687
|
+
border-right: 1px solid var(--border);
|
|
688
|
+
outline: none;
|
|
689
|
+
background: transparent;
|
|
690
|
+
color: var(--text);
|
|
691
|
+
font: inherit;
|
|
692
|
+
font-size: 14px;
|
|
693
|
+
font-weight: 700;
|
|
694
|
+
text-align: center;
|
|
695
|
+
font-variant-numeric: tabular-nums;
|
|
696
|
+
-moz-appearance: textfield;
|
|
697
|
+
}
|
|
698
|
+
.mat__qty::-webkit-outer-spin-button,
|
|
699
|
+
.mat__qty::-webkit-inner-spin-button {
|
|
700
|
+
-webkit-appearance: none;
|
|
701
|
+
margin: 0;
|
|
702
|
+
}
|
|
703
|
+
.mat__qty:focus {
|
|
704
|
+
background: var(--hover);
|
|
705
|
+
}
|
|
706
|
+
.mat__line--out {
|
|
707
|
+
background: var(--err-bg);
|
|
708
|
+
}
|
|
709
|
+
.mat__line--out .mat__main,
|
|
710
|
+
.mat__line--out .mat__subtotal {
|
|
711
|
+
opacity: 0.55;
|
|
712
|
+
}
|
|
713
|
+
.mat__stepper--off {
|
|
714
|
+
opacity: 0.4;
|
|
715
|
+
pointer-events: none;
|
|
716
|
+
}
|
|
717
|
+
.mat__blocked {
|
|
718
|
+
display: flex;
|
|
719
|
+
align-items: center;
|
|
720
|
+
gap: 6px;
|
|
721
|
+
margin: -4px 0 12px;
|
|
722
|
+
font-size: 12.5px;
|
|
723
|
+
font-weight: 600;
|
|
724
|
+
color: var(--err);
|
|
725
|
+
}
|
|
726
|
+
.mat__of {
|
|
727
|
+
font-size: 12px;
|
|
728
|
+
color: var(--muted);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/* footer */
|
|
732
|
+
.mat__foot {
|
|
733
|
+
padding: 14px 20px 18px;
|
|
734
|
+
border-top: 1px solid var(--border);
|
|
735
|
+
}
|
|
736
|
+
.mat__total {
|
|
737
|
+
display: flex;
|
|
738
|
+
align-items: flex-end;
|
|
739
|
+
justify-content: space-between;
|
|
740
|
+
margin-bottom: 14px;
|
|
741
|
+
}
|
|
742
|
+
.mat__total-label {
|
|
743
|
+
font-size: 14px;
|
|
744
|
+
font-weight: 700;
|
|
745
|
+
}
|
|
746
|
+
.mat__total-sub {
|
|
747
|
+
font-size: 12px;
|
|
748
|
+
color: var(--muted);
|
|
749
|
+
margin-top: 2px;
|
|
750
|
+
}
|
|
751
|
+
.mat__total-value {
|
|
752
|
+
font-size: 20px;
|
|
753
|
+
font-weight: 800;
|
|
754
|
+
font-variant-numeric: tabular-nums;
|
|
755
|
+
}
|
|
756
|
+
</style>
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div v-if="groups.length" class="mat-groups">
|
|
3
|
+
<div v-for="group in groups" :key="group.key" class="mat-group">
|
|
4
|
+
<div v-if="!hideHead" class="mat-group__head">
|
|
5
|
+
<span class="mat-group__title">{{ group.title }}</span>
|
|
6
|
+
<span v-if="group.note" class="mat-group__note">{{ group.note }}</span>
|
|
7
|
+
</div>
|
|
8
|
+
<div v-for="line in group.lines" :key="line.key" class="mat-group__row">
|
|
9
|
+
<div class="mat-group__main">
|
|
10
|
+
<div class="mat-group__name">{{ line.name }}</div>
|
|
11
|
+
<div class="mat-group__meta">{{ line.qty }} × {{ money(line.unitCost) }}</div>
|
|
12
|
+
</div>
|
|
13
|
+
<span class="mat-group__amount">{{ money(line.total) }}</span>
|
|
14
|
+
</div>
|
|
15
|
+
<div class="mat-group__total">
|
|
16
|
+
<span>Total</span>
|
|
17
|
+
<span>{{ money(group.total) }}</span>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
<div v-if="showGrandTotal && groups.length > 1" class="mat-groups__grand">
|
|
21
|
+
<span>Grand Total</span>
|
|
22
|
+
<span>{{ money(groups.reduce((sum, g) => sum + g.total, 0)) }}</span>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
</template>
|
|
26
|
+
|
|
27
|
+
<script setup lang="ts">
|
|
28
|
+
/**
|
|
29
|
+
* Materials listed per work order (or per "to use on submit" group), each
|
|
30
|
+
* with its total, and - when there are several - a grand total.
|
|
31
|
+
*/
|
|
32
|
+
type TMaterialsGroup = {
|
|
33
|
+
key: string;
|
|
34
|
+
title: string;
|
|
35
|
+
/** Beside the title, e.g. the work order's status. */
|
|
36
|
+
note?: string;
|
|
37
|
+
lines: { key: string; name: string; qty: number; unitCost: number; total: number }[];
|
|
38
|
+
total: number;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
defineProps<{
|
|
42
|
+
groups: TMaterialsGroup[];
|
|
43
|
+
/** Add a Grand Total row when there is more than one group. */
|
|
44
|
+
showGrandTotal?: boolean;
|
|
45
|
+
/** No title row per group - where the work order is named already (its own dialog). */
|
|
46
|
+
hideHead?: boolean;
|
|
47
|
+
}>();
|
|
48
|
+
|
|
49
|
+
const money = (n?: number) => `S$${Number(n ?? 0).toFixed(2)}`;
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<style scoped>
|
|
53
|
+
.mat-groups {
|
|
54
|
+
display: flex;
|
|
55
|
+
flex-direction: column;
|
|
56
|
+
gap: 10px;
|
|
57
|
+
margin-top: 10px;
|
|
58
|
+
font-size: 13px;
|
|
59
|
+
}
|
|
60
|
+
.mat-group {
|
|
61
|
+
border: 1px solid var(--border);
|
|
62
|
+
border-radius: 10px;
|
|
63
|
+
overflow: hidden;
|
|
64
|
+
}
|
|
65
|
+
.mat-group__head {
|
|
66
|
+
display: flex;
|
|
67
|
+
justify-content: space-between;
|
|
68
|
+
gap: 8px;
|
|
69
|
+
padding: 7px 12px;
|
|
70
|
+
background: var(--thead);
|
|
71
|
+
border-bottom: 1px solid var(--border);
|
|
72
|
+
}
|
|
73
|
+
.mat-group__title {
|
|
74
|
+
font-size: 11.5px;
|
|
75
|
+
font-weight: 800;
|
|
76
|
+
letter-spacing: 0.03em;
|
|
77
|
+
text-transform: uppercase;
|
|
78
|
+
color: var(--text2);
|
|
79
|
+
}
|
|
80
|
+
.mat-group__note {
|
|
81
|
+
font-size: 11.5px;
|
|
82
|
+
color: var(--muted);
|
|
83
|
+
}
|
|
84
|
+
.mat-group__row {
|
|
85
|
+
display: flex;
|
|
86
|
+
align-items: center;
|
|
87
|
+
justify-content: space-between;
|
|
88
|
+
gap: 12px;
|
|
89
|
+
padding: 9px 12px;
|
|
90
|
+
border-bottom: 1px solid var(--border);
|
|
91
|
+
}
|
|
92
|
+
.mat-group__main {
|
|
93
|
+
min-width: 0;
|
|
94
|
+
}
|
|
95
|
+
.mat-group__name {
|
|
96
|
+
font-weight: 600;
|
|
97
|
+
color: var(--text);
|
|
98
|
+
}
|
|
99
|
+
.mat-group__meta {
|
|
100
|
+
font-size: 12px;
|
|
101
|
+
color: var(--muted);
|
|
102
|
+
margin-top: 1px;
|
|
103
|
+
font-variant-numeric: tabular-nums;
|
|
104
|
+
}
|
|
105
|
+
.mat-group__amount {
|
|
106
|
+
font-weight: 700;
|
|
107
|
+
flex: 0 0 auto;
|
|
108
|
+
font-variant-numeric: tabular-nums;
|
|
109
|
+
}
|
|
110
|
+
.mat-group__total {
|
|
111
|
+
display: flex;
|
|
112
|
+
justify-content: space-between;
|
|
113
|
+
padding: 9px 12px;
|
|
114
|
+
font-weight: 800;
|
|
115
|
+
font-variant-numeric: tabular-nums;
|
|
116
|
+
}
|
|
117
|
+
.mat-groups__grand {
|
|
118
|
+
display: flex;
|
|
119
|
+
justify-content: space-between;
|
|
120
|
+
padding: 10px 12px;
|
|
121
|
+
border-radius: 10px;
|
|
122
|
+
background: var(--accent-soft);
|
|
123
|
+
color: var(--accent);
|
|
124
|
+
font-size: 14px;
|
|
125
|
+
font-weight: 800;
|
|
126
|
+
font-variant-numeric: tabular-nums;
|
|
127
|
+
}
|
|
128
|
+
</style>
|
|
@@ -127,8 +127,22 @@ export function useCommonPermissions() {
|
|
|
127
127
|
* providers' role editors no longer offer the box. Property keeps
|
|
128
128
|
* `workOrderPermissions` as it is.
|
|
129
129
|
*/
|
|
130
|
-
const { "delete-work-order": _propertyOnly, ...
|
|
130
|
+
const { "delete-work-order": _propertyOnly, ...tradeWorkOrderBase } =
|
|
131
131
|
workOrderPermissions;
|
|
132
|
+
/*
|
|
133
|
+
* ...plus "Add Work Order Materials" (2026-11): the service providers pick
|
|
134
|
+
* parts from inventory on a work order, taken from stock when it is
|
|
135
|
+
* submitted. Its own right, separate from the Inventory module's. Property
|
|
136
|
+
* Management does not submit, so its editor does not offer it.
|
|
137
|
+
*/
|
|
138
|
+
const tradeWorkOrderPermissions: Record<string, TPermission> = {
|
|
139
|
+
...tradeWorkOrderBase,
|
|
140
|
+
"add-work-order-materials": {
|
|
141
|
+
check: true,
|
|
142
|
+
description:
|
|
143
|
+
"Allows the user to add materials (parts) from inventory to a work order; they are taken from stock when it is submitted.",
|
|
144
|
+
},
|
|
145
|
+
};
|
|
132
146
|
|
|
133
147
|
/** Feedback the same way: "delete-feedback" is Property Management's only. */
|
|
134
148
|
const { "delete-feedback": _propertyOnlyFeedback, ...tradeFeedbackPermissions } =
|
|
@@ -31,8 +31,17 @@ export default function useInventory() {
|
|
|
31
31
|
((await api<TInventoryStore[]>("/stores", { query: { site } })) ?? []).map((s) => ({ ...s, access: inventoryCaps(s.access) })),
|
|
32
32
|
createStore: (body: { org: string; sites: string[]; name: string }) =>
|
|
33
33
|
api<TInventoryStore>("/stores", { method: "POST", body }),
|
|
34
|
-
updateStore: (id: string, body: Partial<Pick<TInventoryStore, "name" | "sites" | "showInResidentApp" | "showCostInResidentApp" | "lowStockReminderDays">>) =>
|
|
34
|
+
updateStore: (id: string, body: Partial<Pick<TInventoryStore, "name" | "sites" | "showInResidentApp" | "showCostInResidentApp" | "lowStockReminderDays" | "workOrderMaterials">>) =>
|
|
35
35
|
api<TInventoryStore>(`/stores/${id}`, { method: "PATCH", body }),
|
|
36
|
+
/**
|
|
37
|
+
* The work order materials picker (2026-11): items from the stores at `site` that are switched
|
|
38
|
+
* on for work orders and this person may use; needs "Add Work Order Materials", not an Inventory right.
|
|
39
|
+
*/
|
|
40
|
+
getWorkOrderItems: (site: string, search = "") =>
|
|
41
|
+
api<{ stores: { _id: string; name: string; orgName: string; ownerType: string }[]; items: (TInventoryItem & { storeName: string })[] }>(
|
|
42
|
+
"/work-order-items",
|
|
43
|
+
{ query: { site, ...(search ? { search } : {}) } },
|
|
44
|
+
),
|
|
36
45
|
/** One store with its settings (`lowStockReminderDays` only from an API that sends reminders). */
|
|
37
46
|
getStore: (id: string) => api<TInventoryStore>(`/stores/${id}`),
|
|
38
47
|
|
|
@@ -87,6 +87,12 @@ export default function useSecurityPermission() {
|
|
|
87
87
|
check: true,
|
|
88
88
|
description: "Allows the user to update work-order details.",
|
|
89
89
|
},
|
|
90
|
+
// 2026-11: parts from inventory on a work order, taken from stock on submit.
|
|
91
|
+
"add-work-order-materials": {
|
|
92
|
+
check: true,
|
|
93
|
+
description:
|
|
94
|
+
"Allows the user to add materials (parts) from inventory to a work order; they are taken from stock when it is submitted.",
|
|
95
|
+
},
|
|
90
96
|
// No "delete-work-order": deleting a work order is for Property
|
|
91
97
|
// Management and the work order's creator only (Harris, 2026-09-23).
|
|
92
98
|
},
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "4.97.1-staging.
|
|
5
|
+
"version": "4.97.1-staging.655",
|
|
6
6
|
"author": "7365admin1",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
8
8
|
"//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
|
package/types/inventory.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ declare type TInventoryStore = {
|
|
|
32
32
|
ownerServiceLabel?: string;
|
|
33
33
|
/** Low-stock reminders every N days until a PO is recorded (0 = off). Only from GET /stores/:id of an API that sends them. */
|
|
34
34
|
lowStockReminderDays?: number;
|
|
35
|
+
/** "Use for work order materials" (2026-11): technicians may pick its items on a work order. Missing = off. */
|
|
36
|
+
workOrderMaterials?: boolean;
|
|
35
37
|
};
|
|
36
38
|
|
|
37
39
|
declare type TInventoryItem = {
|
|
@@ -134,6 +136,13 @@ declare type TInventoryTransaction = {
|
|
|
134
136
|
site?: string;
|
|
135
137
|
location?: { type: "common_area" | "tenant_unit"; area?: string; unit?: string; unitName?: string; tenantName?: string };
|
|
136
138
|
reference?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Used by a work order's submit (2026-11): its id, its number as it is now ("#ME0209"; the saved
|
|
141
|
+
* `reference` when it no longer exists) and whether it still exists, for History to link to it.
|
|
142
|
+
*/
|
|
143
|
+
workOrder?: string;
|
|
144
|
+
workOrderNumber?: string;
|
|
145
|
+
workOrderExists?: boolean;
|
|
137
146
|
supplier?: string;
|
|
138
147
|
/** Receiving (2026-10): missing on older rows = PO. */
|
|
139
148
|
receivingType?: "PO" | "DO" | "CASH";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** A material (part) taken from the site's inventory store for a work order. */
|
|
2
|
+
declare type TWorkOrderMaterial = {
|
|
3
|
+
/** Inventory item id. */
|
|
4
|
+
item: string;
|
|
5
|
+
/** The inventory store it comes from, and that store's owner name. */
|
|
6
|
+
store: string;
|
|
7
|
+
storeName?: string;
|
|
8
|
+
name: string;
|
|
9
|
+
code?: string;
|
|
10
|
+
unit?: string;
|
|
11
|
+
unitCost: number;
|
|
12
|
+
/** Stock when it was picked (the most that can be taken). */
|
|
13
|
+
stock: number;
|
|
14
|
+
qty: number;
|
|
15
|
+
};
|