@7365admin1/layer-common 4.97.1-staging.734 → 4.97.1-staging.736

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.
@@ -150,6 +150,8 @@ const props = defineProps({
150
150
  store: { type: Object as PropType<TInventoryStore>, required: true },
151
151
  /** Only the signed-in person's checkouts (My Stock). */
152
152
  mine: { type: Boolean, default: false },
153
+ /** Bumped when stock changed on another tab (a return accepted in Cleaners): reload. */
154
+ refresh: { type: Number, default: 0 },
153
155
  });
154
156
  const emit = defineEmits<{ counts: [{ out: number; overdue: number }]; changed: [] }>();
155
157
  /** Store keepers take items back (the API checks too). */
@@ -253,5 +255,6 @@ watch(
253
255
  },
254
256
  );
255
257
  onMounted(load);
258
+ watch(() => props.refresh, () => load());
256
259
  defineExpose({ load });
257
260
  </script>
@@ -65,7 +65,7 @@
65
65
  </thead>
66
66
  <tbody>
67
67
  <tr v-for="t in history" :key="t._id">
68
- <td class="text-no-wrap">{{ formatDate(t.date) }}</td>
68
+ <td class="text-no-wrap">{{ whenText(t) }}</td>
69
69
  <td>
70
70
  {{ typeLabels[t.type] }}
71
71
  <template v-if="t.workOrder">
@@ -118,7 +118,7 @@ const emit = defineEmits(["edit", "done"]);
118
118
 
119
119
  const { getTransactions, count, typeLabels } = useInventory();
120
120
  const { getFileUrl } = useFile();
121
- const { requiredRule, standardFormatDate } = useUtils();
121
+ const { requiredRule, standardFormatDate, standardFormatDateTime } = useUtils();
122
122
  const notify = inject<(text: string, color?: string) => void>("inventoryNotify", () => {});
123
123
 
124
124
  const history = ref<TInventoryTransaction[]>([]);
@@ -134,6 +134,14 @@ const writingOff = ref(false);
134
134
  const stepsLive = computed(() => inventoryStepsLive(props.store));
135
135
 
136
136
  const formatDate = (d: string) => standardFormatDate(d);
137
+ /** DV-1787: date and time of every row (DD/MM/YYYY HH:mm). A row dated a day only (a usage job date) takes the time it was recorded. */
138
+ function whenText(t: TInventoryTransaction) {
139
+ const d = new Date(t.date);
140
+ const dayOnly = d.getHours() === 0 && d.getMinutes() === 0;
141
+ const recorded = (t as any).createdAt as string | undefined;
142
+ if (dayOnly && recorded) return `${standardFormatDate(t.date)} ${String(standardFormatDateTime(recorded)).split(" ").pop()}`;
143
+ return standardFormatDateTime(t.date);
144
+ }
137
145
 
138
146
  /**
139
147
  * The work order a "Used" row came from: its feedback's details when it is tied
@@ -177,7 +177,7 @@
177
177
  :hint="serialHint(line)"
178
178
  persistent-hint
179
179
  :no-data-text="'No serial numbers on the shelf'"
180
- @update:model-value="(v: string[] | null) => (line.qty = Math.max(Number(line.qty) || 0, v?.length ?? 0) || null)"
180
+ @update:model-value="(v: string[] | null) => serialsPicked(line, v)"
181
181
  />
182
182
  <v-text-field
183
183
  v-if="mode === 'receive' && receivingType !== 'CASH'"
@@ -414,6 +414,14 @@ const copy = computed(() => {
414
414
  });
415
415
 
416
416
  const form = ref();
417
+ /** DV-1787: serials picked - Qty covers them, and its message is checked again (not left stale). */
418
+ function serialsPicked(line: TRow, v: string[] | null) {
419
+ line.qty = Math.max(Number(line.qty) || 0, v?.length ?? 0) || null;
420
+ nextTick(() => {
421
+ const qtyField = (form.value?.items ?? []).find((i: any) => i.errorMessages?.length && /serial/i.test(String(i.errorMessages)));
422
+ qtyField?.validate?.();
423
+ });
424
+ }
417
425
  const saving = ref(false);
418
426
  const blank = (): TRow => ({ item: null, qty: null, unitCost: null, ordered: null, typed: "", newItem: null });
419
427
  /** Receive: only store managers may add items to the list (the API says 403 otherwise). Request: anyone may ask. */
@@ -171,7 +171,7 @@
171
171
  </v-window-item>
172
172
  <!-- DV-1787: what is checked out (issued for a work order / to come back by a date), overdue first. -->
173
173
  <v-window-item v-if="seesCheckouts" value="checkouts">
174
- <InventoryCheckoutsTab :store="store" @counts="(c: { out: number; overdue: number }) => (overdueCount = c.overdue)" @changed="refreshCounts" />
174
+ <InventoryCheckoutsTab :store="store" :refresh="refreshTick" @counts="(c: { out: number; overdue: number }) => (overdueCount = c.overdue)" @changed="refreshCounts" />
175
175
  </v-window-item>
176
176
  <v-window-item v-if="ctl.tabs.requests" value="requests">
177
177
  <InventoryRequestsTab :store="store" :site-id="siteId" :focus-request="focusRequest" @changed="refreshCounts" />
@@ -416,7 +416,10 @@ async function refreshReturns() {
416
416
  }
417
417
  }
418
418
 
419
+ /** DV-1787: tells the Checked out list to reload after stock changed on another tab. */
420
+ const refreshTick = ref(0);
419
421
  async function refreshCounts() {
422
+ refreshTick.value++;
420
423
  refreshToConfirm();
421
424
  refreshReturns();
422
425
  refreshOverdue();
@@ -211,6 +211,17 @@
211
211
  style="max-width: 200px"
212
212
  :rules="[retQtyRule]"
213
213
  />
214
+ <!-- DV-1787: which serial numbers come back; the rest are units without a serial -->
215
+ <InventorySerialPick
216
+ v-model="ret.serials"
217
+ :item="String(ret.holding.item)"
218
+ source="mine"
219
+ :qty="Number(ret.qty || 0)"
220
+ :units="freeOf(ret.holding)"
221
+ :open="ret.show"
222
+ label="Which serial numbers? (optional)"
223
+ @update:model-value="(v: string[] | null) => (ret.qty = Math.max(Number(ret.qty) || 0, v?.length ?? 0) || null)"
224
+ />
214
225
  <InputLabel title="Note (optional)" class="mb-1" />
215
226
  <v-text-field v-model="ret.note" density="comfortable" maxlength="500" placeholder="e.g. job cancelled, not needed" />
216
227
  </v-form>
@@ -287,14 +298,14 @@ async function loadToReceive() {
287
298
  }
288
299
 
289
300
  const retForm = ref();
290
- const ret = reactive({ show: false, holding: null as TInventoryHolding | null, qty: 1 as number | null, note: "", saving: false });
301
+ const ret = reactive({ show: false, holding: null as TInventoryHolding | null, qty: 1 as number | null, note: "", serials: [] as string[], saving: false });
291
302
  const retQtyRule = (v: any) => {
292
303
  if (!Number.isInteger(Number(v)) || Number(v) < 1) return "Enter a whole number";
293
304
  const max = ret.holding ? freeOf(ret.holding) : 0;
294
305
  return Number(v) <= max || `You can return up to ${max}`;
295
306
  };
296
307
  function openReturn(h: TInventoryHolding) {
297
- Object.assign(ret, { show: true, holding: h, qty: freeOf(h), note: "", saving: false });
308
+ Object.assign(ret, { show: true, holding: h, qty: freeOf(h), note: "", serials: [], saving: false });
298
309
  }
299
310
  async function submitReturn() {
300
311
  const { valid } = await retForm.value.validate();
@@ -302,7 +313,13 @@ async function submitReturn() {
302
313
  ret.saving = true;
303
314
  try {
304
315
  const site = props.store.sites.includes(props.siteId) ? props.siteId : props.store.sites[0];
305
- await api.requestReturn(props.store._id, { site, item: String(ret.holding.item), qty: Number(ret.qty), note: ret.note });
316
+ await api.requestReturn(props.store._id, {
317
+ site,
318
+ item: String(ret.holding.item),
319
+ qty: Number(ret.qty),
320
+ note: ret.note,
321
+ ...(ret.serials.length ? { serials: ret.serials } : {}),
322
+ });
306
323
  notify("Return requested. Bring the items to the store keeper; they leave your stock once the keeper accepts them.");
307
324
  ret.show = false;
308
325
  changed();
@@ -128,6 +128,9 @@ const STATUS: Record<string, { text: string; color: string; info: string }> = {
128
128
  const EVENT: Record<string, string> = {
129
129
  added: "Serial number added",
130
130
  issued: "Issued",
131
+ received: "Received",
132
+ return_asked: "Asked to return",
133
+ return_declined: "Return not received",
131
134
  returned: "Returned to the store",
132
135
  written_off: "Written off",
133
136
  used: "Used",
@@ -138,9 +141,15 @@ function eventText(e: TInventorySerial["history"][number]) {
138
141
  const parts = [EVENT[e.type] ?? e.type];
139
142
  // Write-off: why - "Written off as damaged" (Used up, Spoilt, Damaged, Lost, Other).
140
143
  if (e.reason) parts[0] += ` as ${writeOffLabel(e.reason).toLowerCase()}`;
141
- if (e.holderName) parts.push(e.type === "handed_over" ? `to ${e.holderName}` : `to ${e.holderName}`);
144
+ // Both people (Benar 2026-11-23): who had it, and who did the step.
145
+ if (e.fromName && !["issued", "return_declined"].includes(e.type)) parts.push(`from ${e.fromName}`);
146
+ if (e.holderName) parts.push(`to ${e.holderName}`);
142
147
  if (e.workOrderNumber) parts.push(`for ${e.workOrderNumber}`);
143
- if (e.byName) parts.push(`· by ${e.byName}`);
148
+ if (e.byName) {
149
+ if (e.type === "received" || e.type === "return_asked") parts.push(`by ${e.byName}`);
150
+ else if (e.type === "returned" || e.type === "closed") parts.push(`· accepted by ${e.byName}`);
151
+ else if (!(e.fromName && e.fromName === e.byName)) parts.push(`· by ${e.byName}`);
152
+ }
144
153
  if (e.note) parts.push(`· ${e.note}`);
145
154
  return parts.join(" ");
146
155
  }
@@ -21,6 +21,19 @@
21
21
  >
22
22
  <v-app-bar-nav-icon v-if="!props.hideNavIcon" @click="drawer = !drawer"></v-app-bar-nav-icon>
23
23
 
24
+ <!-- Account application only: back to the services app page that opened
25
+ Manage Account (DV-1874). Shown only when that page was passed in and
26
+ is one of ours - see `utils/account-return.ts`. -->
27
+ <v-btn
28
+ v-if="accountReturn"
29
+ :href="accountReturn"
30
+ variant="text"
31
+ prepend-icon="mdi-arrow-left"
32
+ class="text-none me-2"
33
+ >
34
+ Back
35
+ </v-btn>
36
+
24
37
  <div ref="crumbEl" class="app-topbar-shell__crumb">
25
38
  <span v-if="siteName" class="app-topbar-shell__site">{{ siteName }}</span>
26
39
  <span v-if="siteName && moduleName" class="app-topbar-shell__sep">/</span>
@@ -74,7 +87,7 @@
74
87
  v-if="APP_NAME.toLowerCase() !== 'account'"
75
88
  type="button"
76
89
  class="app-profile-menu__row"
77
- @click="redirect(APP_ACCOUNT, 'home')"
90
+ @click="openAccount()"
78
91
  >
79
92
  <v-icon icon="mdi-account-cog-outline" size="18" />
80
93
  Manage Account
@@ -131,6 +144,7 @@
131
144
  // Explicit, not the `$tr` global: renders the same in unit tests that mount this file.
132
145
  import { uiTr } from "../../composables/useUiLanguage";
133
146
  import { moduleNameFromRoute } from "../../utils/breadcrumb";
147
+ import { ACCOUNT_RETURN_KEY, safeAccountReturn } from "../../utils/account-return";
134
148
 
135
149
  const props = defineProps({
136
150
  hideNavIcon: {
@@ -246,6 +260,41 @@ const profile = computed(() => {
246
260
  return `/api/public/${currentUser.value?.profile}`;
247
261
  });
248
262
 
263
+ /**
264
+ * Manage Account carries the page the user is on, so the Account application
265
+ * can offer a way back to it (DV-1874). It opens Personal Info directly:
266
+ * `/home` is a server redirect there that would drop the query.
267
+ */
268
+ function openAccount() {
269
+ redirect(
270
+ APP_ACCOUNT,
271
+ `personal-info?return=${encodeURIComponent(window.location.href)}`
272
+ );
273
+ }
274
+
275
+ /**
276
+ * In the Account application, the Back target: taken from `?return=` when it
277
+ * arrives (and only if it is one of our own apps), then kept for the tab's
278
+ * session so it survives moving between the Personal Info screens, which drop
279
+ * the query. Read in `onMounted` - the bar is pre-rendered on the server,
280
+ * where there is no `window` or `sessionStorage`.
281
+ */
282
+ const accountReturn = ref("");
283
+
284
+ onMounted(() => {
285
+ if (APP_NAME.toLowerCase() !== "account") return;
286
+ try {
287
+ const fromQuery = safeAccountReturn(route.query.return, String(APP_ACCOUNT));
288
+ if (fromQuery) sessionStorage.setItem(ACCOUNT_RETURN_KEY, fromQuery);
289
+ accountReturn.value =
290
+ fromQuery ||
291
+ safeAccountReturn(sessionStorage.getItem(ACCOUNT_RETURN_KEY), String(APP_ACCOUNT));
292
+ } catch {
293
+ // Storage blocked (private mode): fall back to the query alone.
294
+ accountReturn.value = safeAccountReturn(route.query.return, String(APP_ACCOUNT));
295
+ }
296
+ });
297
+
249
298
  function logout() {
250
299
  if (APP_NAME.toLowerCase() !== "main") {
251
300
  redirect(APP_MAIN, "logout");
@@ -113,7 +113,7 @@ export default function useInventory() {
113
113
  writeOff: (store: string, body: { from: "holding" | "store"; site?: string; item: string; qty: number; reason: string; remarks?: string; photos?: string[]; serials?: string[] }) =>
114
114
  api<TInventoryTransaction>(`/stores/${store}/write-offs`, { method: "POST", body }),
115
115
  /** The holder asks to give stock back; a store keeper accepts it (acceptHandover) when it arrives. */
116
- requestReturn: (store: string, body: { site: string; item: string; qty: number; note?: string }) =>
116
+ requestReturn: (store: string, body: { site: string; item: string; qty: number; note?: string; serials?: string[] }) =>
117
117
  api<TInventoryHandover>(`/stores/${store}/returns/request`, { method: "POST", body }),
118
118
  takeOverDraft: (id: string) => api<TInventoryUsageDraft>(`/usage-drafts/${id}/take-over`, { method: "POST", body: {} }),
119
119
  acknowledgeLowStock: (itemId: string, poNumber = "") =>
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.734",
5
+ "version": "4.97.1-staging.736",
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.",
@@ -295,6 +295,6 @@ declare type TInventorySerial = {
295
295
  status: "in_store" | "out" | "written_off" | "used";
296
296
  holderName?: string;
297
297
  workOrderNumber?: string;
298
- history: { type: string; at: string; byName: string; holderName?: string; workOrderNumber?: string; reason?: string; note?: string }[];
298
+ history: { type: string; at: string; byName: string; holderName?: string; workOrderNumber?: string; reason?: string; fromName?: string; note?: string }[];
299
299
  createdAt: string;
300
300
  };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * THE ACCOUNT SITE'S "BACK" LINK (DV-1874).
3
+ *
4
+ * Manage Account sends the user to the Account application on its own
5
+ * hostname, and that application had no way back: no button, no link, only the
6
+ * browser's Back. The services apps now pass the page the user was on as
7
+ * `?return=`, and the Account header offers a Back button to it.
8
+ *
9
+ * `?return=` comes from the address bar, so it is untrusted: a link that sends
10
+ * someone to Account with `?return=https://evil.example` must not turn our
11
+ * Back button into an open redirect. Only an http(s) address on the SAME parent
12
+ * domain as the Account application itself is accepted:
13
+ *
14
+ * account.app.iservice365.org -> *.app.iservice365.org
15
+ * iservice365-staging-account.apptesting.work -> *.apptesting.work
16
+ * localhost (development) -> localhost
17
+ *
18
+ * The Account application itself is refused - "Back" to the page you are on is
19
+ * no way back at all.
20
+ */
21
+ export function safeAccountReturn(candidate: unknown, accountUrl: string): string {
22
+ if (typeof candidate !== "string" || !candidate) return "";
23
+
24
+ let target: URL;
25
+ let account: URL;
26
+ try {
27
+ target = new URL(candidate);
28
+ account = new URL(accountUrl);
29
+ } catch {
30
+ return "";
31
+ }
32
+
33
+ if (target.protocol !== "https:" && target.protocol !== "http:") return "";
34
+ if (target.origin === account.origin) return "";
35
+
36
+ const host = target.hostname.toLowerCase();
37
+ const accountHost = account.hostname.toLowerCase();
38
+
39
+ if (accountHost === "localhost" || accountHost === "127.0.0.1") {
40
+ return host === accountHost ? target.href : "";
41
+ }
42
+
43
+ // The Account host minus its first label is the shared parent domain.
44
+ const parent = accountHost.split(".").slice(1).join(".");
45
+ if (!parent || !parent.includes(".")) return "";
46
+
47
+ return host.endsWith(`.${parent}`) ? target.href : "";
48
+ }
49
+
50
+ /** Where the Account header keeps the Back target while the user moves around it. */
51
+ export const ACCOUNT_RETURN_KEY = "account-return-to";