@7365admin1/layer-common 4.167.0 → 4.168.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.168.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e7bfa53: Inventory: items not in the stock list. Receive Stock offers `Add "<name>" as a new item` to store managers (unit required, category optional; the item is added to the stock list when the delivery is saved) and tells everyone else that only a store manager can add new items. Request Stock offers `Ask for "<name>" (not in the stock list)` with quantity, optional unit and note, and says which store the request goes to. Store keepers see these as "New item — not in stock list"; a store manager adds them with "Add to stock list", and Approve stays off until every new item is added. A store can now be set to supply the sites its organisation serves (e.g. a security agency's central store), and the store header reads "This store supplies: ...". Approving a request in a store with more than 200 items no longer shows the later items as 0 available.
8
+
9
+ ## 4.167.1
10
+
11
+ ### Patch Changes
12
+
13
+ - c984ac5: Document Management: a search now goes back to page 1, so searching while on a later page shows the matches instead of an empty table.
14
+ - 23be9b1: Access cards: say which EntryPass part failed (DV-0887)
15
+
16
+ Add Access Card stays open when its EntryPass lists cannot load and says
17
+ whether EntryPass is not set up for the site, did not respond, or answered with
18
+ an error, with Try again. A site with no EntryPass address shows "not set up"
19
+ there instead of using the default host. Assign to Unit and the card Preview
20
+ name the failure too instead of one "EntryPass server is unavailable" message.
21
+
3
22
  ## 4.167.0
4
23
 
5
24
  ### Minor Changes
@@ -3772,11 +3791,11 @@ Monthly report: a month that had patrols opens the list of that month's patrol r
3772
3791
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
3773
3792
  own rule from two endpoints the console already calls, unprojected:
3774
3793
 
3775
- GET /api/members/user/:user/app/admin the Seven365 staff membership
3776
- GET /api/roles/id/:role that membership's role document
3794
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
3795
+ GET /api/roles/id/:role that membership's role document
3777
3796
 
3778
- owner = member.type === "admin" && role.type === "admin" && role.default === true
3779
- staff = member.type === "admin" && role.type === "admin"
3797
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
3798
+ staff = member.type === "admin" && role.type === "admin"
3780
3799
 
3781
3800
  `role.default` is the marker because it is the only property of a platform
3782
3801
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -121,6 +121,26 @@
121
121
  <!-- Single Add Mode -->
122
122
  <v-form v-if="uploadMode === 'single'" v-model="validForm" :disabled="disable">
123
123
  <v-row no-gutters class="px-6 pt-4">
124
+ <v-col v-if="entryPassFailure" cols="12" class="px-1 pb-4">
125
+ <v-alert
126
+ :type="entryPassFailure.kind === 'not-set-up' ? 'warning' : 'error'"
127
+ variant="tonal"
128
+ density="comfortable"
129
+ data-test="entrypass-failure"
130
+ >
131
+ <div class="font-weight-bold">{{ entryPassFailure.title }}</div>
132
+ <div class="mt-1">{{ entryPassFailure.body }}</div>
133
+ <v-btn
134
+ class="mt-3 text-none"
135
+ size="small"
136
+ variant="outlined"
137
+ :loading="entryPassLoading"
138
+ @click="loadEntryPassLists"
139
+ >
140
+ Try again
141
+ </v-btn>
142
+ </v-alert>
143
+ </v-col>
124
144
  <v-col cols="12" class="px-1">
125
145
  <InputLabel
126
146
  class="text-capitalize font-weight-bold"
@@ -213,6 +233,8 @@
213
233
  item-value="no"
214
234
  hide-details
215
235
  :rules="[requiredRule]"
236
+ :loading="entryPassLoading"
237
+ :placeholder="entryPassLoading ? 'Loading from EntryPass…' : accessLevelItems.length ? '' : 'Not available'"
216
238
  >
217
239
  </v-select>
218
240
  </v-col>
@@ -231,6 +253,8 @@
231
253
  hide-details
232
254
  :rules="[requiredRule]"
233
255
  multiple
256
+ :loading="entryPassLoading"
257
+ :placeholder="entryPassLoading ? 'Loading from EntryPass…' : accessGroupItems.length ? '' : 'Not available'"
234
258
  >
235
259
  </v-select>
236
260
  </v-col>
@@ -407,6 +431,8 @@
407
431
  </v-card>
408
432
  </template>
409
433
  <script setup lang="ts">
434
+ import { describeEntryPassFailure, type EntryPassFailure } from "../utils/entrypass-failure";
435
+
410
436
  const prop = defineProps({
411
437
  mode: {
412
438
  type: String,
@@ -589,23 +615,57 @@ watch(uploadMode, (mode) => {
589
615
  if (mode === "bulk") fetchEntryPassTemplate();
590
616
  });
591
617
 
592
- onMounted(async () => {
618
+ // DV-0887: the dialog stays open and says which part failed (not set up, did
619
+ // not respond, or what EntryPass answered), with Try again, instead of one
620
+ // generic toast. A site with no EntryPass address is "not set up" here rather
621
+ // than using the default host. Lists that did load are kept.
622
+ const entryPassLoading = ref(true);
623
+ const entryPassFailure = ref<EntryPassFailure | null>(null);
624
+
625
+ async function loadEntryPassLists() {
626
+ entryPassLoading.value = true;
627
+ entryPassFailure.value = null;
593
628
  try {
594
- const acmUrl = await _getEncryptedAcmUrl(siteId);
629
+ let acmUrl = "";
630
+ try {
631
+ acmUrl = await _getEncryptedAcmUrl(siteId, { requireSiteUrl: true });
632
+ } catch (error) {
633
+ console.error("Failed to resolve the EntryPass address:", error);
634
+ entryPassFailure.value = describeEntryPassFailure(error);
635
+ return;
636
+ }
595
637
  encryptedAcmUrl.value = acmUrl;
596
- const [doorLevels, liftLevels, groups] = await Promise.all([
638
+
639
+ const [doorLevels, liftLevels, groups] = await Promise.allSettled([
597
640
  _getDoorAccessLevels(acmUrl),
598
641
  _getLiftAccessLevels(acmUrl),
599
642
  _getAccessGroups(acmUrl),
600
643
  ]);
601
- accessLevelItems.value = doorLevels.data ?? [];
602
- liftAccessLevelItems.value = liftLevels.data ?? [];
603
- accessGroupItems.value = groups.data ?? [];
604
- } catch (error) {
605
- console.error("Failed to fetch access management data:", error);
606
- emit("error", "EntryPass server is unavailable. Please contact your administrator.");
644
+ if (doorLevels.status === "fulfilled") accessLevelItems.value = doorLevels.value.data ?? [];
645
+ if (liftLevels.status === "fulfilled") liftAccessLevelItems.value = liftLevels.value.data ?? [];
646
+ if (groups.status === "fulfilled") accessGroupItems.value = groups.value.data ?? [];
647
+
648
+ const failed = (
649
+ [
650
+ [doorLevels, "door locations"],
651
+ [liftLevels, "lift access levels"],
652
+ [groups, "access groups"],
653
+ ] as const
654
+ ).filter(([result]) => result.status === "rejected");
655
+ if (!failed.length) return;
656
+
657
+ const firstError = (failed[0][0] as PromiseRejectedResult).reason;
658
+ console.error("Failed to fetch access management data:", firstError);
659
+ entryPassFailure.value = describeEntryPassFailure(
660
+ firstError,
661
+ failed.map(([, list]) => list),
662
+ );
663
+ } finally {
664
+ entryPassLoading.value = false;
607
665
  }
608
- });
666
+ }
667
+
668
+ onMounted(loadEntryPassLists);
609
669
 
610
670
  function limitCardNumber() {
611
671
  if (card.value.cardNumber && card.value.cardNumber.toString().length > cardNoMaxLength.value) {
@@ -187,6 +187,8 @@
187
187
  </v-card>
188
188
  </template>
189
189
  <script setup lang="ts">
190
+ import { describeEntryPassFailure, entryPassFailureToast } from "../utils/entrypass-failure";
191
+
190
192
  const props = defineProps({
191
193
  siteId: {
192
194
  type: String,
@@ -318,17 +320,17 @@ onMounted(async () => {
318
320
  ]);
319
321
  accessLevelItems.value = [NO_SELECTION, ...(doorLevels.data ?? [])];
320
322
  liftAccessLevelItems.value = [NO_SELECTION, ...(liftLevels.data ?? [])];
321
- } catch {
323
+ } catch (error) {
324
+ // DV-0887: say what failed rather than one generic message.
322
325
  emit(
323
326
  "error",
324
- "EntryPass server is unavailable. Please contact your administrator."
327
+ entryPassFailureToast(
328
+ describeEntryPassFailure(error, ["door locations", "lift access levels"])
329
+ )
325
330
  );
326
331
  }
327
332
  } else {
328
- emit(
329
- "error",
330
- "EntryPass server is unavailable. Please contact your administrator."
331
- );
333
+ emit("error", entryPassFailureToast(describeEntryPassFailure(acmResult.reason)));
332
334
  }
333
335
  levelsLoading.value = false;
334
336
  });
@@ -756,8 +756,9 @@ async function confirmAssign() {
756
756
  emit("refresh");
757
757
  } catch (e: any) {
758
758
  const rawMsg = e?.data?.message ?? "";
759
+ // DV-0887: EntryPass's own answer is shown rather than one generic message.
759
760
  const msg = rawMsg.includes("500")
760
- ? "EntryPass server is unavailable. Please contact your administrator."
761
+ ? `EntryPass could not assign the card. It answered: "${rawMsg}".`
761
762
  : rawMsg || "Failed to assign. Please try again.";
762
763
  assignError.value = msg;
763
764
  showToast(msg, "error");
@@ -903,6 +903,12 @@ watch(activeTab, () => {
903
903
  page.value = 1;
904
904
  });
905
905
 
906
+ // Same for a search: typed on page 21 of the full list, it would ask for page
907
+ // 21 of the matches and show an empty table, as if nothing matched.
908
+ watch(headerSearch, () => {
909
+ page.value = 1;
910
+ });
911
+
906
912
  const loading = computed(() => getAllReqStatus.value === "pending");
907
913
 
908
914
  // The page totals are the server's count of the WHOLE list, read through the
@@ -8,7 +8,8 @@
8
8
  </v-card-title>
9
9
 
10
10
  <v-card-text class="screen-modal__body">
11
- <p class="text-body-2 text-medium-emphasis mb-4">{{ copy.help }}</p>
11
+ <p class="text-body-2 text-medium-emphasis" :class="mode === 'request' ? 'mb-1' : 'mb-4'">{{ copy.help }}</p>
12
+ <p v-if="mode === 'request'" class="text-body-2 mb-4">Requesting from: <strong>{{ store.name }}</strong></p>
12
13
  <!-- Errors once a field is left or the button is pressed, never from opening or resetting the form. -->
13
14
  <v-form ref="form" validate-on="blur invalid-input">
14
15
  <template v-if="mode === 'receive'">
@@ -46,7 +47,40 @@
46
47
 
47
48
  <div class="text-subtitle-2 mb-2">Items</div>
48
49
  <div v-for="(line, i) in rows" :key="i" class="d-flex flex-wrap ga-2 align-start mb-1">
50
+ <!-- An item not in the stock list (client 2026-11): a delivery adds it, a request asks for it. -->
51
+ <template v-if="line.newItem">
52
+ <v-text-field
53
+ v-model="line.newItem.name"
54
+ label="New item"
55
+ density="comfortable"
56
+ maxlength="200"
57
+ :rules="[requiredRule]"
58
+ class="flex-grow-1"
59
+ style="min-width: 240px"
60
+ >
61
+ <template #append-inner>
62
+ <v-chip size="x-small" color="primary" variant="tonal">New item</v-chip>
63
+ </template>
64
+ </v-text-field>
65
+ <v-text-field
66
+ v-model="line.newItem.unit"
67
+ :label="mode === 'receive' ? 'Unit' : 'Unit (optional)'"
68
+ density="comfortable"
69
+ maxlength="30"
70
+ style="max-width: 130px"
71
+ :rules="mode === 'receive' ? [requiredRule] : []"
72
+ />
73
+ <v-text-field
74
+ v-if="mode === 'receive'"
75
+ v-model="line.newItem.category"
76
+ label="Category (optional)"
77
+ density="comfortable"
78
+ maxlength="80"
79
+ style="max-width: 180px"
80
+ />
81
+ </template>
49
82
  <v-autocomplete
83
+ v-else
50
84
  v-model="line.item"
51
85
  :items="choices"
52
86
  item-title="name"
@@ -57,11 +91,23 @@
57
91
  :rules="[requiredRule]"
58
92
  class="flex-grow-1"
59
93
  style="min-width: 240px"
60
- @update:search="(q: string) => mode !== 'return' && searchItems(q)"
94
+ @update:search="(q: string) => typedSearch(line, q)"
61
95
  >
62
96
  <template #item="{ props: p, item }">
63
97
  <v-list-item v-bind="p" :subtitle="availableText(item.raw)" />
64
98
  </template>
99
+ <!-- mousedown.prevent keeps the field focused, so the typed name is still there on click. -->
100
+ <template #no-data>
101
+ <v-list-item v-if="line.typed && canAddNew" prepend-icon="mdi-plus" @mousedown.prevent @click="addNew(line)">
102
+ <v-list-item-title>{{ mode === "receive" ? `Add "${line.typed}" as a new item` : `Ask for "${line.typed}" (not in the stock list)` }}</v-list-item-title>
103
+ </v-list-item>
104
+ <v-list-item v-else-if="line.typed && mode === 'receive'">
105
+ <v-list-item-title class="text-wrap text-medium-emphasis">{{ notListedText(line.typed) }}</v-list-item-title>
106
+ </v-list-item>
107
+ <v-list-item v-else>
108
+ <v-list-item-title class="text-medium-emphasis">{{ line.typed ? "No items match" : "Type to search" }}</v-list-item-title>
109
+ </v-list-item>
110
+ </template>
65
111
  </v-autocomplete>
66
112
  <v-text-field
67
113
  v-model.number="line.qty"
@@ -71,7 +117,7 @@
71
117
  density="comfortable"
72
118
  style="max-width: 110px"
73
119
  :rules="[qtyRule(line)]"
74
- :suffix="unitWord(line.qty, unitOf(line.item))"
120
+ :suffix="unitWord(line.qty, line.newItem ? line.newItem.unit : unitOf(line.item))"
75
121
  />
76
122
  <v-text-field
77
123
  v-if="mode === 'receive' && receivingType !== 'CASH'"
@@ -99,6 +145,20 @@
99
145
  persistent-hint
100
146
  />
101
147
  <v-btn v-if="rows.length > 1" icon="mdi-delete-outline" variant="text" aria-label="Remove line" @click="rows.splice(i, 1)" />
148
+ <div v-if="line.newItem" class="w-100 mb-2">
149
+ <v-text-field
150
+ v-if="mode === 'request'"
151
+ v-model="line.newItem.note"
152
+ label="Note for the store keeper (optional)"
153
+ placeholder="e.g. brand, size, what it is for"
154
+ density="comfortable"
155
+ maxlength="500"
156
+ />
157
+ <div class="text-caption text-medium-emphasis">
158
+ {{ mode === "receive" ? "New item — added to your stock list when you save." : "The store keeper will see this as a new item and decide whether to add it." }}
159
+ <a href="#" @click.prevent="line.newItem = null">Pick from the list instead</a>
160
+ </div>
161
+ </div>
102
162
  </div>
103
163
  <div class="mb-4">
104
164
  <v-btn variant="text" class="text-none" prepend-icon="mdi-plus" @click="rows.push(blank())">Add another item</v-btn>
@@ -173,9 +233,11 @@ import useUtils from "../composables/useUtils";
173
233
  import { normaliseUsedBy, usedByChips, usedByText } from "../utils/inventory-used-by";
174
234
  import { availableQty, availableText as availableTextOf, qtyUnit, unitWord } from "../utils/inventory-ack";
175
235
  import { RECEIVING_TYPES, receivingFields, receivingProblem, type TReceivingType } from "../utils/inventory-receiving";
236
+ import { notListedText } from "../utils/inventory-request-text";
176
237
 
177
238
  type TMode = "receive" | "issue" | "request" | "return";
178
- type TRow = { item: string; qty: number | null; unitCost?: number | null; ordered?: number | null };
239
+ type TNewItem = { name: string; unit: string; category: string; note: string };
240
+ type TRow = { item: string; qty: number | null; unitCost?: number | null; ordered?: number | null; typed?: string; newItem?: TNewItem | null };
179
241
 
180
242
  const show = defineModel<boolean>({ default: false });
181
243
  const props = defineProps({
@@ -243,7 +305,17 @@ const copy = computed(() => {
243
305
 
244
306
  const form = ref();
245
307
  const saving = ref(false);
246
- const blank = (): TRow => ({ item: "", qty: null, unitCost: null, ordered: null });
308
+ const blank = (): TRow => ({ item: "", qty: null, unitCost: null, ordered: null, typed: "", newItem: null });
309
+ /** Receive: only store managers may add items to the list (the API says 403 otherwise). Request: anyone may ask. */
310
+ const canAddNew = computed(() => (props.mode === "receive" ? props.store.access.canManage : props.mode === "request"));
311
+ function typedSearch(line: TRow, q: string) {
312
+ line.typed = String(q ?? "").replace(/\s+/g, " ").trim();
313
+ if (props.mode !== "return") searchItems(q);
314
+ }
315
+ function addNew(line: TRow) {
316
+ line.newItem = { name: line.typed || "", unit: "pcs", category: "", note: "" };
317
+ line.item = "";
318
+ }
247
319
  const rows = ref<TRow[]>([blank()]);
248
320
  const supplier = ref("");
249
321
  const reference = ref("");
@@ -346,13 +418,17 @@ async function submit() {
346
418
  tried.value = true;
347
419
  const { valid } = await form.value.validate();
348
420
  if (!valid || (props.mode === "receive" && receivingCheck())) return;
349
- const lines = rows.value.filter((r) => r.item && r.qty).map((r) => ({ item: r.item, qty: Number(r.qty) }));
421
+ const lines = rows.value.filter((r) => !r.newItem && r.item && r.qty).map((r) => ({ item: r.item, qty: Number(r.qty) }));
422
+ const fresh = rows.value.filter((r) => r.newItem && r.qty);
423
+ if (props.mode === "request" && fresh.length > 20) return notify("Ask for up to 20 new items in one request.", "error");
350
424
  saving.value = true;
351
425
  try {
352
426
  if (props.mode === "receive") {
353
427
  await api.receive(props.store._id, {
354
428
  lines: rows.value.map((r) => ({
355
- item: r.item,
429
+ ...(r.newItem
430
+ ? { newItem: { name: r.newItem.name.trim(), unit: r.newItem.unit.trim(), ...(r.newItem.category.trim() ? { category: r.newItem.category.trim() } : {}) } }
431
+ : { item: r.item }),
356
432
  qty: Number(r.qty),
357
433
  ...(r.unitCost !== null && r.unitCost !== undefined && r.unitCost !== ("" as any) ? { unitCost: Number(r.unitCost) } : {}),
358
434
  ...(receivingType.value !== "CASH" && hasOrdered(r) ? { poOrderedQty: Number(r.ordered) } : {}),
@@ -371,7 +447,13 @@ async function submit() {
371
447
  remarks: remarks.value,
372
448
  });
373
449
  } else if (props.mode === "request") {
374
- await api.createRequest(props.store._id, { site: props.siteId, lines, reference: reference.value, remarks: remarks.value });
450
+ const newItems = fresh.map((r) => ({
451
+ name: r.newItem!.name.trim(),
452
+ qty: Number(r.qty),
453
+ ...(r.newItem!.unit.trim() ? { unit: r.newItem!.unit.trim() } : {}),
454
+ ...(r.newItem!.note.trim() ? { note: r.newItem!.note.trim() } : {}),
455
+ }));
456
+ await api.createRequest(props.store._id, { site: props.siteId, lines, ...(newItems.length ? { newItems } : {}), reference: reference.value, remarks: remarks.value });
375
457
  } else if (props.mode === "issue") {
376
458
  await api.issue(props.store._id, { holder: holder.value, site: site.value || props.siteId, lines, reference: reference.value, remarks: remarks.value });
377
459
  } else {
@@ -65,6 +65,9 @@
65
65
  <p class="text-body-2 mb-4">
66
66
  Set up a store to keep track of stock: what comes in, who takes it, and where it is used.
67
67
  </p>
68
+ <p class="text-body-2 mb-4">
69
+ 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.
70
+ </p>
68
71
  <v-btn class="text-none screen-btn-primary" variant="flat" @click="showSetup = true">Set up inventory</v-btn>
69
72
  <p class="text-caption mt-3">
70
73
  Only people allowed to manage inventory can finish the setup. Others will see the store once it is ready.
@@ -74,7 +77,7 @@
74
77
  <div class="text-h6 mb-4">Set up inventory</div>
75
78
  <InputLabel title="Store name" required class="mb-1" />
76
79
  <v-text-field v-model="setup.name" :rules="[requiredRule]" density="comfortable" placeholder="e.g. Main Store" class="mb-2" />
77
- <template v-if="orgSites.length > 1">
80
+ <template v-if="supplySites.length > 1">
78
81
  <InputLabel title="Properties this store supplies" required class="mb-1" />
79
82
  <v-select
80
83
  v-model="setup.sites"
@@ -85,7 +88,7 @@
85
88
  chips
86
89
  density="comfortable"
87
90
  :rules="[(v: string[]) => v.length > 0 || 'Choose at least one property']"
88
- hint="Most properties keep their own store. Choose more than one only if they share one store room."
91
+ hint="Choose more than one if one store supplies them all, e.g. a company's central store for all its sites."
89
92
  persistent-hint
90
93
  class="mb-4"
91
94
  />
@@ -148,7 +151,7 @@
148
151
  <InventorySuppliersTab :store="store" />
149
152
  </v-window-item>
150
153
  <v-window-item v-if="ctl.tabs.settings" value="settings">
151
- <InventorySettingsTab :store="store" :org-sites="orgSites" @saved="loadStores" />
154
+ <InventorySettingsTab :store="store" :org-sites="supplySites" @saved="loadStores" />
152
155
  </v-window-item>
153
156
  </v-window>
154
157
  </template>
@@ -163,7 +166,7 @@ import useWorkerTerm from "../composables/useWorkerTerm";
163
166
  import useSite from "../composables/useSite";
164
167
  import useCustomerSite from "../composables/useCustomerSite";
165
168
  import useUtils from "../composables/useUtils";
166
- import { inventoryManagedBy, inventorySiteOptions, inventoryStoreLabel, inventorySuppliesText } from "../utils/inventory-store-label";
169
+ import { inventoryManagedBy, inventorySiteOptions, inventoryStoreLabel, inventorySuppliesText, inventorySupplySites } from "../utils/inventory-store-label";
167
170
  import { inventoryControls } from "../utils/inventory-presets";
168
171
  import { inventoryStepsLive } from "../utils/inventory-ack";
169
172
  import useLocalAuth from "../composables/useLocalAuth";
@@ -336,9 +339,11 @@ async function refreshCounts() {
336
339
  /** The properties this person works at in this organisation (the same list as the site switcher). */
337
340
  const { getAll: getCustomerSites } = useCustomerSite();
338
341
  const mySites = ref<{ _id: string; name: string }[]>([]);
342
+ // A service provider (e.g. a security agency) owns no site: its central store supplies the sites it serves.
343
+ const supplySites = computed(() => inventorySupplySites(orgSites.value, mySites.value));
339
344
  // The property being viewed may be one the organisation serves, not owns: name it, never show its id.
340
345
  const setupSiteOptions = computed(() =>
341
- inventorySiteOptions(orgSites.value, { sites: setup.sites, siteNames: [...mySites.value, { _id: props.siteId, name: currentSiteName.value }] }),
346
+ inventorySiteOptions(supplySites.value, { sites: setup.sites, siteNames: [...mySites.value, { _id: props.siteId, name: currentSiteName.value }] }),
342
347
  );
343
348
  const currentSiteName = computed(() => mySites.value.find((s) => s._id === props.siteId)?.name || storeSites.value.find((s) => s._id === props.siteId)?.name || "this property");
344
349
  async function loadMySites() {
@@ -50,6 +50,11 @@
50
50
  </div>
51
51
  <div v-for="l in r.lines" :key="String(l.item)" class="text-body-2">
52
52
  {{ requestLineText(r.status, l) }}
53
+ <v-chip v-if="l.wasNewItem" size="x-small" color="primary" variant="tonal" class="ml-1">New item</v-chip>
54
+ </div>
55
+ <div v-for="n in r.newItems ?? []" :key="n.key" class="text-body-2">
56
+ {{ newItemLineText(n) }}
57
+ <v-chip size="x-small" color="warning" variant="tonal" class="ml-1">{{ NEW_ITEM_FLAG }}</v-chip>
53
58
  </div>
54
59
  <div v-if="r.reference || r.remarks" class="text-caption text-medium-emphasis mt-1">{{ [r.reference, r.remarks].filter(Boolean).join(" · ") }}</div>
55
60
  <div v-if="r.decidedByName" class="text-caption mt-1">
@@ -90,13 +95,47 @@
90
95
  :rules="[(v: any) => (Number.isInteger(Number(v)) && Number(v) >= 0 && Number(v) <= l.qty) || `0 to ${l.qty}`, (v: any) => l.onHand === undefined || Number(v) <= l.onHand || `Only ${l.onHand} available`]"
91
96
  />
92
97
  </div>
98
+ <div v-for="n in decision.request.newItems ?? []" :key="n.key" class="d-flex flex-wrap align-center ga-3 mb-2">
99
+ <div class="flex-grow-1">
100
+ <div class="font-weight-medium">
101
+ {{ n.name }}
102
+ <v-chip size="x-small" color="warning" variant="tonal" class="ml-1">{{ NEW_ITEM_FLAG }}</v-chip>
103
+ </div>
104
+ <div class="text-caption text-medium-emphasis">Asked {{ qtyUnit(n.qty, n.unit) }}{{ n.note ? ` · ${n.note}` : "" }}</div>
105
+ <div v-if="!store.access.canManage" class="text-caption">{{ NEW_ITEM_MANAGER_ONLY }}</div>
106
+ </div>
107
+ <v-btn v-if="store.access.canManage" size="small" variant="outlined" class="text-none" prepend-icon="mdi-plus" @click="openAddNew(n)">Add to stock list</v-btn>
108
+ </div>
109
+ <v-alert v-if="approveBlocked" type="info" variant="tonal" density="compact" class="mb-2">{{ approveBlocked }}</v-alert>
93
110
  <InputLabel title="Remarks" class="mb-1 mt-2" />
94
111
  <v-textarea v-model="decision.remarks" rows="2" auto-grow density="comfortable" placeholder="Required when rejecting" />
95
112
  </v-form>
96
113
  </v-card-text>
97
114
  <div class="screen-modal__footer">
98
115
  <v-btn class="screen-btn-ghost" variant="outlined" color="error" :loading="decision.busy === 'reject'" :disabled="!!decision.busy" @click="reject">Reject</v-btn>
99
- <v-btn class="screen-btn-primary" variant="flat" :loading="decision.busy === 'approve'" :disabled="!!decision.busy" @click="approve">Approve and issue</v-btn>
116
+ <v-btn class="screen-btn-primary" variant="flat" :loading="decision.busy === 'approve'" :disabled="!!decision.busy || !!approveBlocked" @click="approve">Approve and issue</v-btn>
117
+ </div>
118
+ </v-card>
119
+ </v-dialog>
120
+
121
+ <!-- Store manager: put a requested new item on the stock list; it then needs stock received before approving. -->
122
+ <v-dialog v-model="addNew.show" max-width="440" persistent>
123
+ <v-card class="screen-modal">
124
+ <v-card-title>Add to stock list</v-card-title>
125
+ <v-card-text class="screen-modal__body">
126
+ <v-form ref="addNewForm" validate-on="blur invalid-input">
127
+ <InputLabel title="Item name" required class="mb-1" />
128
+ <v-text-field v-model="addNew.name" density="comfortable" maxlength="200" :rules="[requiredRule]" />
129
+ <InputLabel title="Unit" required class="mb-1" />
130
+ <v-text-field v-model="addNew.unit" density="comfortable" maxlength="30" :rules="[requiredRule]" />
131
+ <InputLabel title="Category (optional)" class="mb-1" />
132
+ <v-text-field v-model="addNew.category" density="comfortable" maxlength="80" />
133
+ <p class="text-caption text-medium-emphasis">It starts with no stock: receive the delivery first, then approve the request.</p>
134
+ </v-form>
135
+ </v-card-text>
136
+ <div class="screen-modal__footer">
137
+ <v-btn class="screen-btn-ghost" variant="outlined" :disabled="addNew.busy" @click="addNew.show = false">Cancel</v-btn>
138
+ <v-btn class="screen-btn-primary" variant="flat" :loading="addNew.busy" @click="saveNew">Add to stock list</v-btn>
100
139
  </div>
101
140
  </v-card>
102
141
  </v-dialog>
@@ -108,7 +147,7 @@
108
147
  <script setup lang="ts">
109
148
  import useInventory from "../composables/useInventory";
110
149
  import useUtils from "../composables/useUtils";
111
- import { REQUEST_STATUS, requestLineText, requestOutcomeText } from "../utils/inventory-request-text";
150
+ import { NEW_ITEM_FLAG, NEW_ITEM_MANAGER_ONLY, REQUEST_STATUS, approveBlockedText, newItemLineText, requestLineText, requestOutcomeText } from "../utils/inventory-request-text";
112
151
  import useLocalAuth from "../composables/useLocalAuth";
113
152
  import { inventoryControls } from "../utils/inventory-presets";
114
153
  import { ACK_CHIP, ackText, approveCap, inventoryStepsLive, qtyUnit } from "../utils/inventory-ack";
@@ -123,7 +162,7 @@ const ctl = computed(() => inventoryControls(props.store.access));
123
162
  const emit = defineEmits(["changed"]);
124
163
 
125
164
  const api = useInventory();
126
- const { standardFormatDateTime } = useUtils();
165
+ const { standardFormatDateTime, requiredRule } = useUtils();
127
166
  const { currentUser } = useLocalAuth();
128
167
  const notify = inject<(text: string, color?: string) => void>("inventoryNotify", () => {});
129
168
 
@@ -198,9 +237,17 @@ async function openDecision(r: TInventoryRequest) {
198
237
  lines: r.lines.map((l) => ({ item: String(l.item), itemName: l.itemName, unit: l.unit, qty: l.qty, give: l.qty, onHand: undefined, reservedQty: l.reservedQty })),
199
238
  });
200
239
  try {
201
- const res = await api.getItems(props.store._id, { limit: 200, includeInactive: true });
240
+ // The API pages at 200: a store with more items read the rest as "0 available" and could not approve them.
241
+ const all: TInventoryItem[] = [];
242
+ let got = 0;
243
+ let last = 1;
244
+ while (got < last && decision.lines.some((l) => !all.some((i) => i._id === l.item))) {
245
+ const res = await api.getItems(props.store._id, { page: ++got, limit: 200, includeInactive: true });
246
+ all.push(...res.items);
247
+ last = res.pages;
248
+ }
202
249
  for (const line of decision.lines) {
203
- const found = res.items.find((i) => i._id === line.item);
250
+ const found = all.find((i) => i._id === line.item);
204
251
  // What is free, plus what this request already set aside for itself.
205
252
  line.onHand = approveCap(found, line.reservedQty ?? 0) ?? 0;
206
253
  line.give = Math.min(line.qty, line.onHand);
@@ -210,6 +257,39 @@ async function openDecision(r: TInventoryRequest) {
210
257
  }
211
258
  }
212
259
 
260
+ const approveBlocked = computed(() => (decision.request ? approveBlockedText(decision.request) : ""));
261
+
262
+ const addNewForm = ref();
263
+ const addNew = reactive({ show: false, key: "", name: "", unit: "", category: "", busy: false });
264
+ function openAddNew(n: NonNullable<TInventoryRequest["newItems"]>[number]) {
265
+ Object.assign(addNew, { show: true, key: n.key, name: n.name, unit: n.unit || "pcs", category: "", busy: false });
266
+ addNewForm.value?.resetValidation();
267
+ }
268
+ async function saveNew() {
269
+ const { valid } = await addNewForm.value.validate();
270
+ if (!valid || !decision.request) return;
271
+ addNew.busy = true;
272
+ try {
273
+ const res = await api.addRequestNewItem(decision.request._id, {
274
+ key: addNew.key,
275
+ name: addNew.name.trim(),
276
+ unit: addNew.unit.trim(),
277
+ ...(addNew.category.trim() ? { category: addNew.category.trim() } : {}),
278
+ });
279
+ notify(`${res.item?.name || addNew.name} is now in the stock list. Receive stock for it, then approve.`);
280
+ addNew.show = false;
281
+ // Re-read the request (the item is now a normal line); keep the remarks already typed.
282
+ const remarks = decision.remarks;
283
+ await openDecision(res.request);
284
+ decision.remarks = remarks;
285
+ changed();
286
+ } catch (error: any) {
287
+ notify(error?.data?.message || "Could not add the item.", "error");
288
+ } finally {
289
+ addNew.busy = false;
290
+ }
291
+ }
292
+
213
293
  async function approve() {
214
294
  const { valid } = await decisionForm.value.validate();
215
295
  if (!valid || !decision.request) return;
@@ -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="Keep one property per store unless they share one store room."
18
+ hint="Choose more than one if this store supplies them all, e.g. a company's central store for all its sites."
19
19
  persistent-hint
20
20
  class="mb-4"
21
21
  />
@@ -65,6 +65,9 @@ export default function useInventory() {
65
65
  approveRequest: (id: string, body: { lines?: TInventoryLine[]; remarks?: string }) =>
66
66
  api(`/requests/${id}/approve`, { method: "POST", body }),
67
67
  rejectRequest: (id: string, remarks: string) => api(`/requests/${id}/reject`, { method: "POST", body: { remarks } }),
68
+ /** Store manager: put a requested new item on the stock list (or link a same-name item); it becomes a normal line. */
69
+ addRequestNewItem: (id: string, body: { key: string; name: string; unit: string; category?: string }) =>
70
+ api<{ request: TInventoryRequest; item: TInventoryItem }>(`/requests/${id}/new-item`, { method: "POST", body }),
68
71
  cancelRequest: (id: string) => api(`/requests/${id}/cancel`, { method: "POST" }),
69
72
  /** The person confirms the issued stock reached them (or did not, with a reason). */
70
73
  acknowledgeRequest: (id: string) => api<TInventoryRequest>(`/requests/${id}/acknowledge`, { method: "POST", body: {} }),
@@ -1,3 +1,5 @@
1
+ import { EntryPassNotSetUpError } from "../utils/entrypass-failure";
2
+
1
3
  export default function useSiteEntryPassSettings() {
2
4
  function getBySiteId(siteId: string) {
3
5
  return useNuxtApp().$api<Record<string, any>>(
@@ -37,8 +39,14 @@ export default function useSiteEntryPassSettings() {
37
39
  * levels and access groups came from the route's hardcoded default host
38
40
  * whatever the site had configured. A site with no URL set, or whose
39
41
  * settings cannot be read, still gets that default.
42
+ *
43
+ * `requireSiteUrl` (Add Access Card, DV-0887): no default. A site with no
44
+ * URL set throws `EntryPassNotSetUpError`, so the screen can say so.
40
45
  */
41
- async function getEncryptedAcmUrl(siteId: string): Promise<string> {
46
+ async function getEncryptedAcmUrl(
47
+ siteId: string,
48
+ options: { requireSiteUrl?: boolean } = {},
49
+ ): Promise<string> {
42
50
  let rawUrl = "";
43
51
  try {
44
52
  const settings: any = await getBySiteId(siteId);
@@ -46,6 +54,7 @@ export default function useSiteEntryPassSettings() {
46
54
  } catch {
47
55
  // No entry pass settings for this site yet - the default host applies.
48
56
  }
57
+ if (!rawUrl && options.requireSiteUrl) throw new EntryPassNotSetUpError();
49
58
  const { encrypted } = await $fetch<{ encrypted: string }>(
50
59
  `/api/encrypt-acm-url${rawUrl ? `?url=${encodeURIComponent(rawUrl)}` : ""}`,
51
60
  );
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.167.0",
5
+ "version": "4.168.0",
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.",
@@ -78,7 +78,10 @@ declare type TInventoryRequest = {
78
78
  siteName?: string;
79
79
  requestedBy: string;
80
80
  requestedByName: string;
81
- lines: { item: string; itemName: string; unit: string; qty: number; issuedQty: number; reservedQty?: number }[];
81
+ /** `wasNewItem`: asked for as a new item, then added to the stock list by a store manager. */
82
+ lines: { item: string; itemName: string; unit: string; qty: number; issuedQty: number; reservedQty?: number; wasNewItem?: boolean }[];
83
+ /** Items asked for that are not in the stock list yet. Approve is refused while any remain. */
84
+ newItems?: { key: string; name: string; qty: number; unit?: string; note?: string }[];
82
85
  reference: string;
83
86
  remarks: string;
84
87
  status: "pending" | "issued" | "rejected" | "cancelled";
@@ -0,0 +1,94 @@
1
+ /**
2
+ * What went wrong when an access-card screen asked EntryPass for its lists
3
+ * (door locations, lift access levels, access groups), in words a site admin
4
+ * can act on.
5
+ *
6
+ * API-core answers every EntryPass failure with a 400 whose `message` is the
7
+ * underlying error, e.g. "Request failed with status code 500" when the
8
+ * EntryPass host itself errors. The screens used to replace all of these with
9
+ * one "EntryPass server is unavailable" toast (DV-0887).
10
+ *
11
+ * - not-set-up the site has no EntryPass address saved
12
+ * - no-response the request never got an answer (timeout, refused, offline)
13
+ * - error EntryPass, or the API in front of it, answered with an error
14
+ */
15
+ export type EntryPassFailureKind = "not-set-up" | "no-response" | "error";
16
+
17
+ export type EntryPassFailure = {
18
+ kind: EntryPassFailureKind;
19
+ title: string;
20
+ body: string;
21
+ /** The server's own message, when there is one. */
22
+ detail: string;
23
+ };
24
+
25
+ /** Thrown when a screen requires the site's own EntryPass address and it has none. */
26
+ export class EntryPassNotSetUpError extends Error {
27
+ constructor() {
28
+ super("EntryPass is not set up for this site.");
29
+ this.name = "EntryPassNotSetUpError";
30
+ }
31
+ }
32
+
33
+ const NO_RESPONSE =
34
+ /timeout|timed out|ECONNREFUSED|ECONNRESET|ENOTFOUND|EAI_AGAIN|socket hang up|network ?error|fetch failed|failed to fetch/i;
35
+
36
+ /** The server's message for a failed request, or the error's own. */
37
+ export function entryPassErrorMessage(error: unknown): string {
38
+ const e = error as any;
39
+ return String(e?.data?.message ?? e?.message ?? "").trim();
40
+ }
41
+
42
+ function listText(lists: string[]): string {
43
+ if (lists.length <= 1) return lists[0] ?? "the lists";
44
+ return `${lists.slice(0, -1).join(", ")} and ${lists[lists.length - 1]}`;
45
+ }
46
+
47
+ /**
48
+ * @param lists the lists that could not be loaded, e.g. ["access groups"]
49
+ */
50
+ export function describeEntryPassFailure(
51
+ error: unknown,
52
+ lists: string[] = ["door locations", "access groups"],
53
+ ): EntryPassFailure {
54
+ const e = error as any;
55
+
56
+ if (e instanceof EntryPassNotSetUpError || e?.name === "EntryPassNotSetUpError") {
57
+ return {
58
+ kind: "not-set-up",
59
+ title: "EntryPass is not set up for this site.",
60
+ body: "Door locations and access groups come from EntryPass, so a physical card can't be added yet. Ask an administrator to set the EntryPass address in Access Management settings.",
61
+ detail: "",
62
+ };
63
+ }
64
+
65
+ const detail = entryPassErrorMessage(error);
66
+ const status = e?.statusCode ?? e?.status ?? e?.response?.status;
67
+ // No status and no body: the request itself never got an answer.
68
+ const noAnswer = !status && !e?.data;
69
+
70
+ if (noAnswer || NO_RESPONSE.test(detail)) {
71
+ return {
72
+ kind: "no-response",
73
+ title: "EntryPass did not respond.",
74
+ body: "Door locations and access groups could not be loaded. Try again in a moment. If it keeps happening, contact your administrator.",
75
+ detail,
76
+ };
77
+ }
78
+
79
+ return {
80
+ kind: "error",
81
+ title: `EntryPass could not load the ${listText(lists)}.`,
82
+ body: detail
83
+ ? `It answered: "${detail}". Try again, or contact your administrator with this message.`
84
+ : "Try again, or contact your administrator.",
85
+ detail,
86
+ };
87
+ }
88
+
89
+ /** One line for a toast: the title, plus the server's message when there is one. */
90
+ export function entryPassFailureToast(failure: EntryPassFailure): string {
91
+ return failure.kind === "error" && failure.detail
92
+ ? `${failure.title} It answered: "${failure.detail}".`
93
+ : failure.title;
94
+ }
@@ -29,3 +29,25 @@ export function requestOutcomeText(r: TRequest, formatWhen: (d: string) => strin
29
29
  const why = r.decisionRemarks ? ` — ${r.decisionRemarks}` : "";
30
30
  return `${what} by ${r.decidedByName}${when}${why}`;
31
31
  }
32
+
33
+ /** Asked-for items that are not in the stock list yet (requests) and typed names a delivery cannot add. */
34
+ export const NEW_ITEM_FLAG = "New item — not in stock list";
35
+ export const NEW_ITEM_MANAGER_ONLY = "A store manager needs to add this item first.";
36
+
37
+ type TNewItem = { name: string; qty: number; unit?: string; note?: string };
38
+
39
+ /** "Bidet Spray — 3 pcs · for unit 05-12" (no unit given reads as a bare number). */
40
+ export function newItemLineText(n: TNewItem) {
41
+ return `${n.name} — ${qtyUnit(n.qty, n.unit)}${n.note ? ` · ${n.note}` : ""}`;
42
+ }
43
+
44
+ /** Why Approve is off while new items remain (the API refuses it with the same reason), or "". */
45
+ export function approveBlockedText(r: { newItems?: { name: string }[] }) {
46
+ const first = r.newItems?.[0];
47
+ return first ? `"${first.name}" is not in the stock list yet. A store manager adds it first (Add to stock list), or reject the request.` : "";
48
+ }
49
+
50
+ /** A delivery line typed by someone who cannot add items to the stock list. */
51
+ export function notListedText(name: string) {
52
+ return `"${name}" is not in the stock list. Only a store manager can add new items — ask them to add it first.`;
53
+ }
@@ -6,11 +6,21 @@
6
6
  */
7
7
  type TStoreLike = { ownerType: string; orgName?: string; main?: boolean; owner?: boolean; ownerServiceLabel?: string };
8
8
 
9
- /** "Supplies Winsland House I and Winsland House II" for a store that supplies several sites. */
9
+ /** "This store supplies: Winsland House I and Winsland House II" for a store that supplies several sites. */
10
10
  export function inventorySuppliesText(names: string[]) {
11
11
  const named = names.map((n) => n || "another property");
12
12
  if (named.length < 2) return "";
13
- return `Supplies ${named.slice(0, -1).join(", ")} and ${named[named.length - 1]}`;
13
+ return `This store supplies: ${named.slice(0, -1).join(", ")} and ${named[named.length - 1]}`;
14
+ }
15
+
16
+ /**
17
+ * The properties a store may be set to supply: the organisation's own sites plus
18
+ * the sites it serves (`customer-sites` engagements). A security agency owns no
19
+ * site, so its central store needs the served ones to supply all its sites.
20
+ */
21
+ export function inventorySupplySites(owned: { _id: string; name: string }[], served: { _id: string; name: string }[]) {
22
+ const seen = new Set<string>();
23
+ return [...owned, ...served].filter((s) => s._id && !seen.has(s._id) && seen.add(s._id));
14
24
  }
15
25
 
16
26
  export function inventoryStoreLabel(store: TStoreLike, all: TStoreLike[]) {