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

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.
@@ -39,7 +39,7 @@
39
39
  <v-text-field v-model="from" type="date" label="From" density="compact" hide-details style="max-width: 170px" />
40
40
  <v-text-field v-model="to" type="date" label="To" density="compact" hide-details style="max-width: 170px" />
41
41
  <v-select v-model="type" :items="typeChoices" label="What" density="compact" hide-details style="max-width: 200px" />
42
- <v-select v-if="!item" v-model="itemPick" :items="[{ value: '', title: 'All items' }, ...itemChoices]" label="Item" density="compact" hide-details style="max-width: 240px" />
42
+ <v-autocomplete v-if="!item" v-model="itemPick" :items="[{ value: '', title: 'All items' }, ...itemChoices]" label="Item" density="compact" hide-details style="max-width: 240px" />
43
43
  <v-text-field v-model="location" label="Where (unit, tenant or area)" density="compact" hide-details clearable style="max-width: 240px" />
44
44
  </div>
45
45
 
@@ -203,7 +203,15 @@ watch(show, async (open) => {
203
203
  loadHoldings();
204
204
  if (!props.item) {
205
205
  try {
206
- itemChoices.value = (await api.getItems(props.store._id, { limit: 200 })).items.map((i) => ({ value: i._id, title: i.name }));
206
+ // The API pages at 200: read every page so a big store can filter by any item.
207
+ // ponytail: capped at 25 pages (5,000 items); switch to a server-side search if a store outgrows it.
208
+ const all: { value: string; title: string }[] = [];
209
+ for (let page = 1, pages = 1; page <= Math.min(pages, 25); page++) {
210
+ const res = await api.getItems(props.store._id, { page, limit: 200 });
211
+ all.push(...res.items.map((i) => ({ value: i._id, title: i.name })));
212
+ pages = res.pages;
213
+ }
214
+ itemChoices.value = all;
207
215
  } catch {
208
216
  itemChoices.value = [];
209
217
  }
@@ -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,42 @@
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
+ <!-- A delivery's new item has six fields: put qty / ordered / price on their own line so none gets squashed. -->
82
+ <div v-if="mode === 'receive'" class="w-100" aria-hidden="true" />
83
+ </template>
49
84
  <v-autocomplete
85
+ v-else
50
86
  v-model="line.item"
51
87
  :items="choices"
52
88
  item-title="name"
@@ -56,12 +92,24 @@
56
92
  density="comfortable"
57
93
  :rules="[requiredRule]"
58
94
  class="flex-grow-1"
59
- style="min-width: 240px"
60
- @update:search="(q: string) => mode !== 'return' && searchItems(q)"
95
+ style="min-width: 220px"
96
+ @update:search="(q: string) => typedSearch(line, q)"
61
97
  >
62
98
  <template #item="{ props: p, item }">
63
99
  <v-list-item v-bind="p" :subtitle="availableText(item.raw)" />
64
100
  </template>
101
+ <!-- mousedown.prevent keeps the field focused, so the typed name is still there on click. -->
102
+ <template #no-data>
103
+ <v-list-item v-if="line.typed && canAddNew" prepend-icon="mdi-plus" @mousedown.prevent @click="addNew(line)">
104
+ <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>
105
+ </v-list-item>
106
+ <v-list-item v-else-if="line.typed && mode === 'receive'">
107
+ <v-list-item-title class="text-wrap text-medium-emphasis">{{ notListedText(line.typed) }}</v-list-item-title>
108
+ </v-list-item>
109
+ <v-list-item v-else>
110
+ <v-list-item-title class="text-medium-emphasis">{{ line.typed ? "No items match" : "Type to search" }}</v-list-item-title>
111
+ </v-list-item>
112
+ </template>
65
113
  </v-autocomplete>
66
114
  <v-text-field
67
115
  v-model.number="line.qty"
@@ -71,7 +119,7 @@
71
119
  density="comfortable"
72
120
  style="max-width: 110px"
73
121
  :rules="[qtyRule(line)]"
74
- :suffix="unitWord(line.qty, unitOf(line.item))"
122
+ :suffix="unitWord(line.qty, line.newItem ? line.newItem.unit : unitOf(line.item))"
75
123
  />
76
124
  <v-text-field
77
125
  v-if="mode === 'receive' && receivingType !== 'CASH'"
@@ -94,11 +142,26 @@
94
142
  label="Unit price"
95
143
  prefix="$"
96
144
  density="comfortable"
97
- style="max-width: 140px"
145
+ class="line-price"
146
+ :class="{ 'line-price--wide': line.newItem }"
98
147
  hint="Leave blank to keep the last price"
99
148
  persistent-hint
100
149
  />
101
150
  <v-btn v-if="rows.length > 1" icon="mdi-delete-outline" variant="text" aria-label="Remove line" @click="rows.splice(i, 1)" />
151
+ <div v-if="line.newItem" class="w-100 mb-2">
152
+ <v-text-field
153
+ v-if="mode === 'request'"
154
+ v-model="line.newItem.note"
155
+ label="Note for the store keeper (optional)"
156
+ placeholder="e.g. brand, size, what it is for"
157
+ density="comfortable"
158
+ maxlength="500"
159
+ />
160
+ <div class="text-caption text-medium-emphasis">
161
+ {{ 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." }}
162
+ <a href="#" @click.prevent="line.newItem = null">Pick from the list instead</a>
163
+ </div>
164
+ </div>
102
165
  </div>
103
166
  <div class="mb-4">
104
167
  <v-btn variant="text" class="text-none" prepend-icon="mdi-plus" @click="rows.push(blank())">Add another item</v-btn>
@@ -173,9 +236,11 @@ import useUtils from "../composables/useUtils";
173
236
  import { normaliseUsedBy, usedByChips, usedByText } from "../utils/inventory-used-by";
174
237
  import { availableQty, availableText as availableTextOf, qtyUnit, unitWord } from "../utils/inventory-ack";
175
238
  import { RECEIVING_TYPES, receivingFields, receivingProblem, type TReceivingType } from "../utils/inventory-receiving";
239
+ import { notListedText } from "../utils/inventory-request-text";
176
240
 
177
241
  type TMode = "receive" | "issue" | "request" | "return";
178
- type TRow = { item: string; qty: number | null; unitCost?: number | null; ordered?: number | null };
242
+ type TNewItem = { name: string; unit: string; category: string; note: string };
243
+ type TRow = { item: string; qty: number | null; unitCost?: number | null; ordered?: number | null; typed?: string; newItem?: TNewItem | null };
179
244
 
180
245
  const show = defineModel<boolean>({ default: false });
181
246
  const props = defineProps({
@@ -243,7 +308,17 @@ const copy = computed(() => {
243
308
 
244
309
  const form = ref();
245
310
  const saving = ref(false);
246
- const blank = (): TRow => ({ item: "", qty: null, unitCost: null, ordered: null });
311
+ const blank = (): TRow => ({ item: "", qty: null, unitCost: null, ordered: null, typed: "", newItem: null });
312
+ /** Receive: only store managers may add items to the list (the API says 403 otherwise). Request: anyone may ask. */
313
+ const canAddNew = computed(() => (props.mode === "receive" ? props.store.access.canManage : props.mode === "request"));
314
+ function typedSearch(line: TRow, q: string) {
315
+ line.typed = String(q ?? "").replace(/\s+/g, " ").trim();
316
+ if (props.mode !== "return") searchItems(q);
317
+ }
318
+ function addNew(line: TRow) {
319
+ line.newItem = { name: line.typed || "", unit: "pcs", category: "", note: "" };
320
+ line.item = "";
321
+ }
247
322
  const rows = ref<TRow[]>([blank()]);
248
323
  const supplier = ref("");
249
324
  const reference = ref("");
@@ -346,13 +421,17 @@ async function submit() {
346
421
  tried.value = true;
347
422
  const { valid } = await form.value.validate();
348
423
  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) }));
424
+ const lines = rows.value.filter((r) => !r.newItem && r.item && r.qty).map((r) => ({ item: r.item, qty: Number(r.qty) }));
425
+ const fresh = rows.value.filter((r) => r.newItem && r.qty);
426
+ if (props.mode === "request" && fresh.length > 20) return notify("Ask for up to 20 new items in one request.", "error");
350
427
  saving.value = true;
351
428
  try {
352
429
  if (props.mode === "receive") {
353
430
  await api.receive(props.store._id, {
354
431
  lines: rows.value.map((r) => ({
355
- item: r.item,
432
+ ...(r.newItem
433
+ ? { newItem: { name: r.newItem.name.trim(), unit: r.newItem.unit.trim(), ...(r.newItem.category.trim() ? { category: r.newItem.category.trim() } : {}) } }
434
+ : { item: r.item }),
356
435
  qty: Number(r.qty),
357
436
  ...(r.unitCost !== null && r.unitCost !== undefined && r.unitCost !== ("" as any) ? { unitCost: Number(r.unitCost) } : {}),
358
437
  ...(receivingType.value !== "CASH" && hasOrdered(r) ? { poOrderedQty: Number(r.ordered) } : {}),
@@ -371,7 +450,13 @@ async function submit() {
371
450
  remarks: remarks.value,
372
451
  });
373
452
  } else if (props.mode === "request") {
374
- await api.createRequest(props.store._id, { site: props.siteId, lines, reference: reference.value, remarks: remarks.value });
453
+ const newItems = fresh.map((r) => ({
454
+ name: r.newItem!.name.trim(),
455
+ qty: Number(r.qty),
456
+ ...(r.newItem!.unit.trim() ? { unit: r.newItem!.unit.trim() } : {}),
457
+ ...(r.newItem!.note.trim() ? { note: r.newItem!.note.trim() } : {}),
458
+ }));
459
+ await api.createRequest(props.store._id, { site: props.siteId, lines, ...(newItems.length ? { newItems } : {}), reference: reference.value, remarks: remarks.value });
375
460
  } else if (props.mode === "issue") {
376
461
  await api.issue(props.store._id, { holder: holder.value, site: site.value || props.siteId, lines, reference: reference.value, remarks: remarks.value });
377
462
  } else {
@@ -414,4 +499,18 @@ watch(show, (open) => {
414
499
  height: auto !important;
415
500
  flex-wrap: wrap;
416
501
  }
502
+ /* Unit price: compact beside an existing item; wide enough for its hint on a new item's second line or a phone. */
503
+ .line-price {
504
+ flex: 1 1 140px;
505
+ max-width: 140px;
506
+ }
507
+ .line-price--wide {
508
+ flex-basis: 240px;
509
+ max-width: 320px;
510
+ }
511
+ @media (max-width: 599px) {
512
+ .line-price {
513
+ max-width: none;
514
+ }
515
+ }
417
516
  </style>
@@ -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.97.1-staging.652",
5
+ "version": "4.97.1-staging.654",
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[]) {