@7365admin1/layer-common 4.167.1 → 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,11 @@
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
+
3
9
  ## 4.167.1
4
10
 
5
11
  ### Patch Changes
@@ -3785,11 +3791,11 @@ Monthly report: a month that had patrols opens the list of that month's patrol r
3785
3791
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
3786
3792
  own rule from two endpoints the console already calls, unprojected:
3787
3793
 
3788
- GET /api/members/user/:user/app/admin the Seven365 staff membership
3789
- 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
3790
3796
 
3791
- owner = member.type === "admin" && role.type === "admin" && role.default === true
3792
- 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"
3793
3799
 
3794
3800
  `role.default` is the marker because it is the only property of a platform
3795
3801
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -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: {} }),
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.1",
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";
@@ -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[]) {