@7365admin1/layer-common 4.97.1-staging.659 → 4.97.1-staging.661

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.
@@ -35,7 +35,7 @@ const COPY = {
35
35
  items: {
36
36
  title: "Import Items from Excel",
37
37
  noun: "items",
38
- fill: "One row per item. Unit, Packing, Category and Supplier have dropdowns with this store's values (a new supplier can still be typed in). Current Stock and the columns after it are the opening stock (date, supplier, PO no.), recorded like a delivery.",
38
+ fill: "One row per item. Unit, Pack size, Category and Supplier have dropdowns with this store's values (a new supplier can still be typed in). Pack size is info only — put how many you have in Quantity In Store Now; it and the columns after it are the opening stock (date, supplier, PO no.), recorded like a delivery.",
39
39
  duplicate: "Items already in the store are skipped and never changed, so uploading twice never doubles stock.",
40
40
  file: "inventory-items",
41
41
  done: (n: number) => `${n} item(s) added.`,
@@ -11,6 +11,7 @@
11
11
  <v-img v-if="item.photo" :src="getFileUrl(item.photo)" width="120" height="120" cover class="rounded flex-grow-0" />
12
12
  <div class="flex-grow-1">
13
13
  <div class="text-h5 mb-1" :class="item.lowStock ? 'text-error' : ''">{{ qtyUnit(item.onHand, item.unit) }} in store</div>
14
+ <div v-if="!item.onHand && !history.length && !loading" class="text-body-2 text-medium-emphasis mb-1">No stock recorded yet — use Receive Stock to add some.</div>
14
15
  <div v-if="item.reserved" class="text-body-2 mb-1">{{ availableText(item) }} (the rest is set aside for requests waiting for approval)</div>
15
16
  <div v-if="item.lowStockAlert" class="text-body-2 text-error mb-1">{{ lowStockAlertText(item.lowStockAlert, standardFormatDate) }}</div>
16
17
  <div class="text-body-2 text-medium-emphasis">
@@ -10,14 +10,20 @@
10
10
  <v-form ref="form" validate-on="blur invalid-input">
11
11
  <InputLabel title="Item name" required class="mb-1" />
12
12
  <v-text-field v-model="f.name" :rules="[requiredRule]" density="comfortable" placeholder="e.g. Philips T8 2ft 9W LED Tube" />
13
+ <!-- The stock quantity sits right under the name so it is never mistaken for Pack size (owner 2026-11-05). -->
14
+ <div v-if="!item" class="text-subtitle-2 mt-2 mb-1">How many do you have now?</div>
13
15
  <v-row dense>
14
16
  <v-col cols="12" sm="4">
15
17
  <InputLabel title="Unit" required class="mb-1" />
16
18
  <v-combobox v-model="f.unit" :items="units" :rules="[requiredRule]" density="comfortable" hint="How you count it (pcs, box, can)" persistent-hint />
17
19
  </v-col>
20
+ <v-col v-if="!item" cols="12" sm="4">
21
+ <InputLabel title="Quantity in store now" class="mb-1" />
22
+ <v-text-field v-model.number="f.openingQty" type="number" min="0" density="comfortable" :rules="[wholeRule]" :suffix="f.unit || ''" hint="0 if you have none yet" persistent-hint />
23
+ </v-col>
18
24
  <v-col cols="12" sm="4">
19
- <InputLabel title="Packing" class="mb-1" />
20
- <v-text-field v-model="f.packing" density="comfortable" placeholder="e.g. 25 pcs / box" maxlength="60" hint="How the supplier packs it (info only)" persistent-hint />
25
+ <InputLabel title="Pack size (info only)" class="mb-1" />
26
+ <v-text-field v-model="f.packing" density="comfortable" placeholder="e.g. 25 pcs / box — this is NOT the stock quantity" maxlength="60" hint="How the supplier packs it" persistent-hint />
21
27
  </v-col>
22
28
  <v-col cols="12" sm="4">
23
29
  <InputLabel title="Item code" class="mb-1" />
@@ -53,21 +59,17 @@
53
59
  </template>
54
60
  <!-- Stock already on the shelf, recorded like a delivery (one "Opening stock" entry in the item's history). -->
55
61
  <template v-if="!item">
56
- <div class="text-subtitle-2 mt-4">Opening stock</div>
62
+ <div class="text-subtitle-2 mt-4">Stock in store now — details (optional)</div>
57
63
  <div class="text-caption text-medium-emphasis mb-2">
58
- Stock you already have. It is recorded like a delivery and shows in the item's history and the Purchases report as "Opening stock".
59
- Supplier and PO no. are optional — old stock may have none. Leave the quantity at 0 if you have none yet.
64
+ The quantity in store now is recorded like a delivery and shows in the item's history and the Purchases report as "Opening stock".
65
+ Supplier and PO no. are optional — old stock may have none.
60
66
  </div>
61
67
  <v-row dense>
62
- <v-col cols="12" sm="4">
63
- <InputLabel title="Quantity" class="mb-1" />
64
- <v-text-field v-model.number="f.openingQty" type="number" min="0" density="comfortable" :rules="[wholeRule]" :suffix="f.unit || ''" hint="How many are in the store now" persistent-hint />
65
- </v-col>
66
- <v-col cols="12" sm="4">
68
+ <v-col cols="12" sm="6">
67
69
  <InputLabel title="Date received (as at)" class="mb-1" />
68
70
  <v-text-field v-model="f.openingDate" type="date" :max="today" density="comfortable" :disabled="!f.openingQty" hint="Blank = today" persistent-hint />
69
71
  </v-col>
70
- <v-col cols="12" sm="4">
72
+ <v-col cols="12" sm="6">
71
73
  <InputLabel title="Received by" class="mb-1" />
72
74
  <v-text-field v-model="f.openingReceivedBy" density="comfortable" maxlength="120" :disabled="!f.openingQty" placeholder="You" hint="Blank = you" persistent-hint />
73
75
  </v-col>
@@ -97,6 +99,13 @@
97
99
  />
98
100
  </v-form>
99
101
  </v-card-text>
102
+ <v-alert v-if="packGuess" type="warning" variant="tonal" density="compact" class="mx-4 mb-2">
103
+ Quantity in store is 0. Did you mean {{ packGuess }} in stock?
104
+ <div class="d-flex flex-wrap ga-2 mt-2">
105
+ <v-btn class="text-none" color="primary" variant="flat" size="small" @click="usePackGuess">Use {{ packGuess }} as quantity</v-btn>
106
+ <v-btn class="text-none" variant="outlined" size="small" @click="keepZero">Keep 0</v-btn>
107
+ </div>
108
+ </v-alert>
100
109
  <div class="screen-modal__footer">
101
110
  <v-btn class="screen-btn-ghost" variant="outlined" :disabled="saving" @click="show = false">Cancel</v-btn>
102
111
  <v-btn class="screen-btn-primary" variant="flat" :loading="saving" @click="save">{{ item ? "Save" : "Add item" }}</v-btn>
@@ -108,6 +117,7 @@
108
117
  <script setup lang="ts">
109
118
  import useInventory, { pickedDate } from "../composables/useInventory";
110
119
  import useUtils from "../composables/useUtils";
120
+ import { packSizeLooksLikeQty } from "../utils/inventory-store-label";
111
121
  import { normaliseUsedBy, nextUsedBy, USED_BY_ALL, USED_BY_ALL_LABEL, USED_BY_HINT, USED_BY_OPTIONS } from "../utils/inventory-used-by";
112
122
 
113
123
  const usedByItems = [{ value: USED_BY_ALL, title: USED_BY_ALL_LABEL }, ...USED_BY_OPTIONS];
@@ -150,6 +160,24 @@ const today = new Date().toLocaleDateString("en-CA");
150
160
  const f = reactive(blank());
151
161
  const photo = ref<string[]>([]);
152
162
  const inUse = ref(true);
163
+ /** A bare-number pack size on a new item with 0 in store: asked once before saving. */
164
+ const packGuess = ref<number | null>(null);
165
+ const zeroConfirmed = ref(false);
166
+ watch(() => [f.openingQty, f.packing], () => {
167
+ packGuess.value = null;
168
+ zeroConfirmed.value = false;
169
+ });
170
+
171
+ function usePackGuess() {
172
+ f.openingQty = packGuess.value!;
173
+ f.packing = "";
174
+ save();
175
+ }
176
+
177
+ function keepZero() {
178
+ zeroConfirmed.value = true;
179
+ save();
180
+ }
153
181
 
154
182
  watch(show, (open) => {
155
183
  if (!open) return;
@@ -157,11 +185,17 @@ watch(show, (open) => {
157
185
  Object.assign(f, blank(), i ? { name: i.name, unit: i.unit, packing: i.packing ?? "", code: i.code, category: i.category, reorderLevel: i.reorderLevel, unitCost: i.unitCost ?? 0, description: i.description, usedBy: normaliseUsedBy(i.usedBy) } : {});
158
186
  photo.value = i?.photo ? [i.photo] : [];
159
187
  inUse.value = i ? i.status === "active" : true;
188
+ packGuess.value = null;
189
+ zeroConfirmed.value = false;
160
190
  });
161
191
 
162
192
  async function save() {
163
193
  const { valid } = await form.value.validate();
164
194
  if (!valid) return;
195
+ if (!props.item && !zeroConfirmed.value) {
196
+ packGuess.value = packSizeLooksLikeQty(f.packing, f.openingQty);
197
+ if (packGuess.value) return;
198
+ }
165
199
  saving.value = true;
166
200
  const body = {
167
201
  name: f.name,
@@ -422,7 +422,7 @@ const headers: Record<string, any[]> = {
422
422
  movement: [
423
423
  { title: "Item", key: "name" },
424
424
  { title: "Unit", key: "unit" },
425
- { title: "Packing", key: "packing" },
425
+ { title: "Pack size", key: "packing" },
426
426
  { title: "Start", key: "opening" },
427
427
  { title: "Received", key: "received" },
428
428
  { title: "Purchase cost", key: "receivedCost" },
@@ -51,7 +51,7 @@
51
51
  <v-list-item
52
52
  density="compact"
53
53
  class="switch-context__row"
54
- v-for="item in uniqueItems"
54
+ v-for="item in visibleItems"
55
55
  :key="item.value"
56
56
  @click="selectItem(item.value)"
57
57
  >
@@ -61,6 +61,14 @@
61
61
 
62
62
  {{ item.text }}
63
63
  </v-list-item>
64
+ <v-list-item
65
+ v-if="!visibleItems.length && searchTerm"
66
+ density="compact"
67
+ class="switch-context__row"
68
+ disabled
69
+ >
70
+ No match for "{{ search }}"
71
+ </v-list-item>
64
72
  </v-list>
65
73
 
66
74
  <!-- The two actions under the list. Seven applications hand-wrote this
@@ -213,8 +221,61 @@ const uniqueItems = computed(() => {
213
221
  });
214
222
  });
215
223
 
224
+ /**
225
+ * THE SEARCH, APPLIED ON SCREEN.
226
+ *
227
+ * Owner report, 2026-11-05 (Security app, Aigle Security): typing "aigle" in
228
+ * the site switcher still listed every site. The layouts DO send the term to
229
+ * `GET /api/customer-sites`, but that search is the Sites page's search - it
230
+ * also matches the CLIENT's name (`siteOrgName`), and for an organisation's own
231
+ * sites the client is the organisation itself. So "aigle" matched every Aigle
232
+ * site and the server answer was the whole list. The organisation search
233
+ * (`$text` on memberships) has the opposite flaw: whole words only, and it also
234
+ * matches the member's own name.
235
+ *
236
+ * The switcher's contract is "find the row by the name I can see", so the rows
237
+ * are filtered here by that name (case-insensitive, contains) - instantly, as
238
+ * the user types, and over whatever the caller hands back. The caller's server
239
+ * search still runs (it is how a list longer than one page is reached); its
240
+ * rows are merged with the last unfiltered list, so a partial word the server
241
+ * cannot match still finds a row that was already loaded.
242
+ */
243
+ const searchTerm = computed(() =>
244
+ String(search.value ?? "").trim().toLowerCase(),
245
+ );
246
+
247
+ // The caller's list as it was with NO search - kept so a server answer that
248
+ // misses a row (or drops the selected one) does not hide it.
249
+ const unfilteredItems = shallowRef<Array<Record<string, any>>>([]);
250
+ watch(
251
+ uniqueItems,
252
+ (items) => {
253
+ if (!searchTerm.value) unfilteredItems.value = items;
254
+ },
255
+ { immediate: true },
256
+ );
257
+
258
+ const visibleItems = computed(() => {
259
+ const term = searchTerm.value;
260
+ if (!term) return uniqueItems.value;
261
+ const seen = new Set<unknown>();
262
+ return [...uniqueItems.value, ...unfilteredItems.value].filter((item) => {
263
+ const value = item?.value;
264
+ if (value !== undefined && value !== null && value !== "") {
265
+ if (seen.has(value)) return false;
266
+ seen.add(value);
267
+ }
268
+ return String(item?.text ?? "").toLowerCase().includes(term);
269
+ });
270
+ });
271
+
216
272
  const name = computed(() => {
217
- return uniqueItems.value.find((item) => item.value === selected.value)?.text ?? "";
273
+ const match = (item: Record<string, any>) => item.value === selected.value;
274
+ return (
275
+ uniqueItems.value.find(match)?.text ??
276
+ unfilteredItems.value.find(match)?.text ??
277
+ ""
278
+ );
218
279
  });
219
280
 
220
281
  /**
@@ -236,26 +297,35 @@ watchEffect(() => {
236
297
  });
237
298
 
238
299
  let searchDebounce: ReturnType<typeof setTimeout> | null = null;
239
- let skipNextWatch = false;
240
300
 
241
301
  const triggerSearch = () => {
242
302
  if (searchDebounce) clearTimeout(searchDebounce);
243
303
  emit("search");
244
304
  };
245
305
 
306
+ // Vuetify's clear button sets the field to `null` before `click:clear` fires;
307
+ // normalising to "" here lets the watch below do the one refetch. (The old
308
+ // skip-flag could swallow the user's NEXT keystroke when the two arrived in
309
+ // separate ticks.)
246
310
  const clearSearch = () => {
247
- skipNextWatch = true;
248
311
  search.value = "";
249
- triggerSearch();
250
312
  };
251
313
 
252
- watch(search, () => {
253
- if (skipNextWatch) {
254
- skipNextWatch = false;
314
+ watch(search, (value) => {
315
+ if (value === null || value === undefined) {
316
+ search.value = "";
255
317
  return;
256
318
  }
257
319
  if (searchDebounce) clearTimeout(searchDebounce);
258
- searchDebounce = setTimeout(triggerSearch, 1000);
320
+ // Emptied: restore the full list straight away. Typing: wait for a pause.
321
+ if (!value.trim()) triggerSearch();
322
+ else searchDebounce = setTimeout(triggerSearch, 1000);
323
+ });
324
+
325
+ // Closing the panel drops the search, so the list the caller holds (and the
326
+ // next opening) is the full one again rather than the last filtered answer.
327
+ watch(menu, (open) => {
328
+ if (!open && search.value) search.value = "";
259
329
  });
260
330
 
261
331
  onBeforeUnmount(() => {
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.659",
5
+ "version": "4.97.1-staging.661",
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.",
@@ -62,13 +62,24 @@ export function inventorySiteOptions(
62
62
 
63
63
  type TItemLike = { code?: string; category?: string; packing?: string };
64
64
 
65
- /** "Code 001 · Bulb · Packing: 25" - each figure says what it is, never a bare number. */
65
+ /** "Code 001 · Bulb · Pack size: 25" - each figure says what it is, never a bare number. */
66
66
  export function inventoryItemMeta(item: TItemLike) {
67
- return [item.code && `Code ${item.code}`, item.category, item.packing && `Packing: ${item.packing}`]
67
+ return [item.code && `Code ${item.code}`, item.category, item.packing && `Pack size: ${item.packing}`]
68
68
  .filter(Boolean)
69
69
  .join(" · ");
70
70
  }
71
71
 
72
+ /**
73
+ * A pack size typed as a bare number ("50") on a new item with 0 in store is usually the stock
74
+ * quantity in the wrong box (owner 2026-11-05: "available is 0 but there's 50 packing").
75
+ * Returns that number so the form can ask; null when the pack size reads like a pack size.
76
+ */
77
+ export function packSizeLooksLikeQty(packing: unknown, qty: unknown): number | null {
78
+ if (Number(qty || 0) !== 0) return null;
79
+ const m = /^\s*(\d+)\s*$/.exec(String(packing ?? ""));
80
+ return m && Number(m[1]) > 0 ? Number(m[1]) : null;
81
+ }
82
+
72
83
  /**
73
84
  * "How inventory works" (owner 2026-11-05): the three ways clients run stock, in the words the screens use.
74
85
  * The mobile apps carry the same sentences; change both together.