@7365admin1/layer-common 4.97.1-staging.654 → 4.97.1-staging.656

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.
@@ -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>{{ typeLabels[t.type] }}</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
- <td class="text-right">{{ t.type === "use" ? "" : t.storeBalance }}</td>
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
- t.reference || "",
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>
@@ -45,7 +45,11 @@
45
45
  <v-text-field v-if="mode !== 'issue'" :model-value="holderName" density="comfortable" readonly />
46
46
  </template>
47
47
 
48
- <div class="text-subtitle-2 mb-2">Items</div>
48
+ <div class="text-subtitle-2 mb-2">
49
+ Items
50
+ <!-- Same count as the mobile request sheet: what this request holds so far. -->
51
+ <span v-if="mode === 'request' && chosenCount > 0" class="text-primary">· {{ chosenCount === 1 ? "1 item in this request" : `${chosenCount} items in this request` }}</span>
52
+ </div>
49
53
  <div v-for="(line, i) in rows" :key="i" class="d-flex flex-wrap ga-2 align-start mb-1">
50
54
  <!-- An item not in the stock list (client 2026-11): a delivery adds it, a request asks for it. -->
51
55
  <template v-if="line.newItem">
@@ -320,6 +324,7 @@ function addNew(line: TRow) {
320
324
  line.item = "";
321
325
  }
322
326
  const rows = ref<TRow[]>([blank()]);
327
+ const chosenCount = computed(() => rows.value.filter((r) => r.item || r.newItem?.name?.trim()).length);
323
328
  const supplier = ref("");
324
329
  const reference = ref("");
325
330
  const remarks = ref("");
@@ -2,6 +2,9 @@
2
2
  <div class="inventory">
3
3
  <PageHeader :title="store ? store.name : 'Inventory'" :subtitle="subtitle">
4
4
  <template #actions>
5
+ <v-btn variant="text" size="small" class="text-none" prepend-icon="mdi-help-circle-outline" @click="showHowItWorks = true">
6
+ {{ HOW.title }}
7
+ </v-btn>
5
8
  <!-- Many stores (staff of several organisations at one property): a list, not a row of buttons. -->
6
9
  <v-select
7
10
  v-if="stores.length > 3"
@@ -50,6 +53,25 @@
50
53
  </div>
51
54
  </v-alert>
52
55
 
56
+ <!-- Owner 2026-11-05: the three set-ups, in plain words, one tap away on every inventory screen. -->
57
+ <v-dialog v-model="showHowItWorks" max-width="640">
58
+ <v-card>
59
+ <v-card-title class="text-h6">{{ HOW.title }}</v-card-title>
60
+ <v-card-text>
61
+ <p class="text-body-2 mb-4">{{ HOW.intro }}</p>
62
+ <div v-for="s in HOW.setups" :key="s.title" class="mb-3">
63
+ <div class="font-weight-medium">{{ s.title }}</div>
64
+ <div class="text-body-2">{{ s.text }}</div>
65
+ </div>
66
+ <p class="text-caption mt-2">{{ HOW.where }}</p>
67
+ </v-card-text>
68
+ <v-card-actions>
69
+ <v-spacer />
70
+ <v-btn class="text-none" variant="text" @click="showHowItWorks = false">Close</v-btn>
71
+ </v-card-actions>
72
+ </v-card>
73
+ </v-dialog>
74
+
53
75
  <v-progress-linear v-if="loading" indeterminate color="primary" class="mb-4" />
54
76
 
55
77
  <AppCard v-else-if="loadError" class="pa-6">
@@ -59,7 +81,8 @@
59
81
  </AppCard>
60
82
 
61
83
  <!-- No store yet: one clear next step, or one clear explanation. -->
62
- <AppCard v-else-if="!store" class="pa-6">
84
+ <!-- Also open when a provider sets up its own store beside the main store (scenario 3). -->
85
+ <AppCard v-else-if="!store || showSetup" class="pa-6">
63
86
  <template v-if="!showSetup">
64
87
  <div class="text-h6 mb-2">Inventory is not set up for this property yet</div>
65
88
  <p class="text-body-2 mb-4">
@@ -67,6 +90,8 @@
67
90
  </p>
68
91
  <p class="text-body-2 mb-4">
69
92
  One store can supply several properties (for example a company's central store): choose them all when you set it up, or later under Settings.
93
+ If each property keeps its own separate stock, set up a store at each property instead.
94
+ <a href="#" class="text-primary" @click.prevent="showHowItWorks = true">How inventory works</a>
70
95
  </p>
71
96
  <v-btn class="text-none screen-btn-primary" variant="flat" @click="showSetup = true">Set up inventory</v-btn>
72
97
  <p class="text-caption mt-3">
@@ -88,7 +113,7 @@
88
113
  chips
89
114
  density="comfortable"
90
115
  :rules="[(v: string[]) => v.length > 0 || 'Choose at least one property']"
91
- hint="Choose more than one if one store supplies them all, e.g. a company's central store for all its sites."
116
+ hint="Choose more than one only if one store supplies them all (e.g. a company's central store). If a property keeps its own separate stock, leave it out and set up its own store there."
92
117
  persistent-hint
93
118
  class="mb-4"
94
119
  />
@@ -105,6 +130,10 @@
105
130
  <v-alert v-if="requestOnly" type="info" variant="tonal" density="compact" class="mb-4" icon="mdi-cart-arrow-down">
106
131
  <div class="font-weight-medium">Request items from the main store</div>
107
132
  <div class="text-body-2">Pick the items you need and press Request Stock. You are told when the store keeper approves it.</div>
133
+ <div v-if="canSetUpOwnStore" class="d-flex align-center flex-wrap ga-2 mt-2">
134
+ <span class="text-body-2">Your company can also keep its own store here for stock it buys itself.</span>
135
+ <v-btn size="small" variant="outlined" class="text-none" @click="openOwnStoreSetup">Set up our own store</v-btn>
136
+ </div>
108
137
  </v-alert>
109
138
  <v-alert
110
139
  v-else-if="store.access.canApprove && pendingCount > 0 && tab !== 'requests'"
@@ -124,6 +153,9 @@
124
153
  <v-btn size="small" variant="flat" color="warning" class="text-none" @click="tab = 'mine'">Open My Stock</v-btn>
125
154
  </div>
126
155
  </v-alert>
156
+ <v-alert v-if="twoStoresText" type="info" variant="tonal" density="compact" class="mb-4" icon="mdi-store-outline">
157
+ {{ twoStoresText }}
158
+ </v-alert>
127
159
  <v-tabs v-model="tab" color="primary" class="mb-4" show-arrows>
128
160
  <v-tab v-for="t in tabs" :key="t.value" :value="t.value" class="text-none">
129
161
  {{ t.label }}
@@ -166,7 +198,16 @@ import useWorkerTerm from "../composables/useWorkerTerm";
166
198
  import useSite from "../composables/useSite";
167
199
  import useCustomerSite from "../composables/useCustomerSite";
168
200
  import useUtils from "../composables/useUtils";
169
- import { inventoryManagedBy, inventorySiteOptions, inventoryStoreLabel, inventorySuppliesText, inventorySupplySites } from "../utils/inventory-store-label";
201
+ import {
202
+ INVENTORY_HOW_IT_WORKS as HOW,
203
+ inventoryManagedBy,
204
+ inventorySiteOptions,
205
+ inventoryStoreLabel,
206
+ inventorySuppliesText,
207
+ inventorySupplySites,
208
+ inventoryTwoStoresText,
209
+ } from "../utils/inventory-store-label";
210
+ import useInventoryPermission from "../composables/useInventoryPermission";
170
211
  import { inventoryControls } from "../utils/inventory-presets";
171
212
  import { inventoryStepsLive } from "../utils/inventory-ack";
172
213
  import useLocalAuth from "../composables/useLocalAuth";
@@ -198,6 +239,16 @@ const pendingCount = ref(0);
198
239
  const orgSites = ref<{ _id: string; name: string }[]>([]);
199
240
 
200
241
  const showSetup = ref(false);
242
+ const showHowItWorks = ref(false);
243
+ const { canManageInventory } = useInventoryPermission();
244
+ const twoStoresText = computed(() => inventoryTwoStoresText(stores.value));
245
+ // Scenario 3: a provider at a property with a main store may add its own store; offered only when it has none here.
246
+ const canSetUpOwnStore = computed(() => canManageInventory.value && !stores.value.some((s) => s.owner === true));
247
+ function openOwnStoreSetup() {
248
+ // Never "Main Store": that is the property manager's store in every label.
249
+ Object.assign(setup, { name: "Our Store", sites: [props.siteId] });
250
+ showSetup.value = true;
251
+ }
201
252
  const setupForm = ref();
202
253
  const setup = reactive({ name: "Main Store", sites: [props.siteId] as string[] });
203
254
 
@@ -15,7 +15,7 @@
15
15
  chips
16
16
  density="comfortable"
17
17
  :rules="[(v: string[]) => v.length > 0 || 'Choose at least one property']"
18
- hint="Choose more than one if this store supplies them all, e.g. a company's central store for all its sites."
18
+ hint="Choose more than one only if this store supplies them all (e.g. a company's central store). A property that keeps its own separate stock needs its own store instead."
19
19
  persistent-hint
20
20
  class="mb-4"
21
21
  />
@@ -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, ...tradeWorkOrderPermissions } =
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
 
@@ -31,5 +31,12 @@ export default function useInventoryPermission() {
31
31
  );
32
32
  });
33
33
 
34
- return { canSeeInventory };
34
+ /** May set up a store for this organisation (the API checks again; this only decides whether to offer the button). */
35
+ const canManageInventory = computed(() => {
36
+ const role = userAppRole.value;
37
+ if (!role || permissionsDenied(["inventory"], userAppModulesDenied?.value)) return false;
38
+ return role.permissions.includes("*") || hasPermission(role, permissions, "inventory", "manage-inventory");
39
+ });
40
+
41
+ return { canSeeInventory, canManageInventory };
35
42
  }
@@ -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.654",
5
+ "version": "4.97.1-staging.656",
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.",
@@ -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
+ };
@@ -68,3 +68,39 @@ export function inventoryItemMeta(item: TItemLike) {
68
68
  .filter(Boolean)
69
69
  .join(" · ");
70
70
  }
71
+
72
+ /**
73
+ * "How inventory works" (owner 2026-11-05): the three ways clients run stock, in the words the screens use.
74
+ * The mobile apps carry the same sentences; change both together.
75
+ */
76
+ export const INVENTORY_HOW_IT_WORKS = {
77
+ title: "How inventory works",
78
+ intro:
79
+ "A store is the stock one company keeps. The company that owns a store runs it: adds items, receives deliveries, approves requests and issues stock. Everyone else can only request from it.",
80
+ setups: [
81
+ {
82
+ title: "1. One company store for many sites",
83
+ text: "For example a security agency: one store supplies every site the company serves. When you set it up, tick all those sites. Staff at each site request from it; issues, usage and reports are recorded per site.",
84
+ },
85
+ {
86
+ title: "2. One store per property",
87
+ text: "For example Winsland House 1 and Winsland House 2: each property keeps its own stock, so each gets its own store. Set up the store at each property and tick only that property. Use Switch property to move between them; stock never mixes.",
88
+ },
89
+ {
90
+ title: "3. Main store and service providers",
91
+ text: "The property manager's Main store supplies the service providers at the property: their staff request, the store keeper issues to the person. A provider can also keep its own store (Our store) for stock it buys itself. Stock does not move between stores.",
92
+ },
93
+ ],
94
+ where: "Stores are set up on the web (Inventory, by a person allowed to manage inventory). The mobile apps request, receive and record usage.",
95
+ };
96
+
97
+ /**
98
+ * Two stores at one property for the same person: say which is which, so a request goes to the right one.
99
+ * Empty unless the person sees both their own company's store and another company's main store.
100
+ */
101
+ export function inventoryTwoStoresText(stores: TStoreLike[]) {
102
+ const ours = stores.some((s) => s.owner === true);
103
+ const theirs = stores.some((s) => s.owner === false && s.main);
104
+ if (!ours || !theirs) return "";
105
+ return "Two stores supply this property. Our store is your company's own stock. Main store is the property manager's stock: you can only request from it.";
106
+ }