@7365admin1/layer-common 4.189.2 → 4.190.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.
@@ -0,0 +1,349 @@
1
+ <template>
2
+ <!--
3
+ DV-1787: stock issued for a work order and/or to come back by a date ("checked out"), until it
4
+ is returned, written off, used or handed over. `mine`: only the signed-in person's (My Stock).
5
+ -->
6
+ <div>
7
+ <div v-if="!mine" class="d-flex flex-wrap align-center ga-2 mb-3">
8
+ <v-btn-toggle v-model="status" mandatory divided variant="outlined" density="comfortable">
9
+ <v-btn value="out" class="text-none">Out ({{ counts.out }})</v-btn>
10
+ <v-btn value="overdue" class="text-none" :class="{ 'text-error': counts.overdue > 0 }">Overdue ({{ counts.overdue }})</v-btn>
11
+ <v-btn value="closed" class="text-none">Returned / closed</v-btn>
12
+ <v-btn value="all" class="text-none">All</v-btn>
13
+ </v-btn-toggle>
14
+ <v-spacer />
15
+ <v-text-field
16
+ v-model="search"
17
+ density="compact"
18
+ prepend-inner-icon="mdi-magnify"
19
+ placeholder="Item, person or work order"
20
+ clearable
21
+ hide-details
22
+ style="max-width: 280px"
23
+ />
24
+ </div>
25
+
26
+ <v-alert v-if="mine && counts.overdue > 0" type="error" variant="tonal" density="compact" class="mb-2" icon="mdi-alarm">
27
+ {{ counts.overdue === 1 ? "1 item is" : `${counts.overdue} items are` }} past the return date. Please return {{ counts.overdue === 1 ? "it" : "them" }} to the store.
28
+ </v-alert>
29
+
30
+ <v-data-table-server
31
+ :headers="headers"
32
+ :items="rows"
33
+ :items-length="total"
34
+ :loading="loading"
35
+ :page="page"
36
+ :items-per-page="limit"
37
+ :items-per-page-options="[10, 25, 50]"
38
+ density="comfortable"
39
+ :no-data-text="mine ? 'Nothing checked out to you.' : 'Nothing here.'"
40
+ hover
41
+ class="co-table"
42
+ @click:row="(_e: unknown, r: { item: TInventoryCheckout }) => openDetail(r.item)"
43
+ @update:page="(p: number) => ((page = p), load())"
44
+ @update:items-per-page="(n: number) => ((limit = n), (page = 1), load())"
45
+ >
46
+ <template #item.itemName="{ item }">
47
+ <span class="font-weight-medium">{{ item.itemName }}</span>
48
+ <div v-if="item.serials?.length" class="text-caption text-medium-emphasis">S/N {{ item.serials.map((s) => s.serial).join(", ") }}</div>
49
+ </template>
50
+ <template #item.createdAt="{ item }">
51
+ <div class="text-no-wrap">{{ standardFormatDateTime(item.createdAt) }}</div>
52
+ <div class="text-caption text-medium-emphasis">by {{ item.createdByName }}</div>
53
+ </template>
54
+ <template #item.holderName="{ item }">{{ item.holderName }}</template>
55
+ <template #item.qty="{ item }">
56
+ <span v-if="item.status === 'out'">{{ qtyUnit(item.outQty, item.unit) }}<span v-if="item.outQty !== item.qty" class="text-caption text-medium-emphasis"> of {{ item.qty }}</span></span>
57
+ <span v-else class="text-medium-emphasis">{{ qtyUnit(item.qty, item.unit) }}</span>
58
+ </template>
59
+ <template #item.workOrderNumber="{ item }">
60
+ <NuxtLink v-if="workOrderLinkTarget(item, route, router)" :to="workOrderLinkTarget(item, route, router)!" class="text-primary">{{ item.workOrderNumber }}</NuxtLink>
61
+ <span v-else>{{ item.workOrderNumber || "—" }}</span>
62
+ </template>
63
+ <template #item.returnDate="{ item }">
64
+ <span class="text-no-wrap">{{ item.returnDate ? returnDayText(item.returnDate) : "—" }}</span>
65
+ <!-- DV-1787: changed after the issue - by whom, and when -->
66
+ <div v-if="item.dateChanges?.length" class="text-caption text-medium-emphasis text-no-wrap">
67
+ changed by {{ item.dateChanges[item.dateChanges.length - 1].byName }}
68
+ </div>
69
+ </template>
70
+ <template #item.closedAt="{ item }">
71
+ <span class="text-no-wrap">{{ item.status !== "out" && item.closedAt ? standardFormatDateTime(item.closedAt) : "—" }}</span>
72
+ </template>
73
+ <template #item.status="{ item }">
74
+ <!-- DV-1787: how much is where (Not Returned, Return Asked, Returned, ...); tap the row for the serials -->
75
+ <div class="d-flex flex-wrap align-center ga-1 py-1">
76
+ <v-tooltip v-if="chipShown(item)" :text="chip(item).info" location="top" max-width="280">
77
+ <template #activator="{ props: tip }">
78
+ <v-chip v-bind="tip" size="small" variant="tonal" :color="chip(item).color" :prepend-icon="chip(item).icon">{{ chip(item).text }}</v-chip>
79
+ </template>
80
+ </v-tooltip>
81
+ <v-tooltip v-if="item.status === 'out' && item.returnRequest && !item.returnAsked" :text="RETURN_ASKED_INFO" location="top" max-width="280">
82
+ <template #activator="{ props: tip }">
83
+ <v-chip v-bind="tip" size="small" variant="tonal" color="primary" prepend-icon="mdi-keyboard-return">Return Asked</v-chip>
84
+ </template>
85
+ </v-tooltip>
86
+ <span v-for="st in rowStats(item)" :key="st.label" class="co-pill">
87
+ <b :class="st.cls">{{ st.n }}</b> {{ st.label }}
88
+ </span>
89
+ </div>
90
+ </template>
91
+ <!-- DV-1787: return THIS checkout (its work order), not the earliest one of the item. -->
92
+ <template #item.actions="{ item }">
93
+ <template v-if="item.status === 'out'">
94
+ <!-- DV-1787: not received yet - Received (then Ask to return), or Not Received -->
95
+ <div v-if="mine && item.received === false" class="d-flex ga-1 justify-end">
96
+ <v-btn size="small" variant="flat" color="primary" class="text-none" prepend-icon="mdi-check" :loading="recv.busy === item._id" @click.stop="markReceived(item)">Received</v-btn>
97
+ <v-btn v-if="item.ackStatus !== 'not_received'" size="small" variant="outlined" color="error" class="text-none" prepend-icon="mdi-close" @click.stop="openNotReceived(item)">Not Received</v-btn>
98
+ </div>
99
+ <v-btn v-else-if="mine && askLeft(item) > 0" size="small" variant="tonal" color="primary" class="text-none" prepend-icon="mdi-keyboard-return" @click.stop="openReturn(item)">
100
+ Ask to return
101
+ </v-btn>
102
+ <div v-else-if="!mine && canTakeBack" class="d-flex ga-1 justify-end">
103
+ <v-btn size="small" variant="tonal" color="primary" class="text-none" prepend-icon="mdi-keyboard-return" @click.stop="openReturn(item)">
104
+ {{ item.returnRequest ? "Accept return" : "Return" }}
105
+ </v-btn>
106
+ <!-- DV-1787: set, change or clear the return date (forgotten at the issue, or more time given) -->
107
+ <v-tooltip text="Change return date" location="top">
108
+ <template #activator="{ props: tip }">
109
+ <v-btn v-bind="tip" size="small" variant="tonal" icon="mdi-calendar-edit" aria-label="Change return date" @click.stop="openDate(item)" />
110
+ </template>
111
+ </v-tooltip>
112
+ </div>
113
+ </template>
114
+ </template>
115
+ </v-data-table-server>
116
+
117
+ <!-- DV-1787: the row's details - the same as on the feedback / work order -->
118
+ <InventoryCheckoutDetail v-model="det.show" :rows="det.row ? [det.row] : []" :subtitle="det.row?.workOrderNumber || ''" @changed="afterDetail" />
119
+
120
+ <InventoryCheckoutReturnDialog v-model="ret.show" :row="ret.row" :mode="mine ? 'ask' : 'return'" @done="afterReturn" />
121
+
122
+ <!-- DV-1787: Not Received - why, so the store keeper can check -->
123
+ <v-dialog v-model="recv.show" max-width="440">
124
+ <v-card class="screen-modal">
125
+ <v-card-title class="d-flex align-center">
126
+ Not Received
127
+ <v-spacer />
128
+ <v-btn icon="mdi-close" variant="text" class="screen-modal__close" aria-label="Close" @click="recv.show = false" />
129
+ </v-card-title>
130
+ <v-card-text class="screen-modal__body">
131
+ <p class="text-body-1 mb-3">Tell the store keeper you did not get {{ recv.row ? `${qtyUnit(recv.row.qty, recv.row.unit)} of ${recv.row.itemName}` : "it" }}. It stays out until they check and take it back.</p>
132
+ <InputLabel title="Why?" required class="mb-1" />
133
+ <v-text-field v-model="recv.reason" density="comfortable" placeholder="e.g. nothing was handed to me" hide-details="auto" :rules="[(v) => !!String(v || '').trim() || 'Required']" />
134
+ </v-card-text>
135
+ <div class="screen-modal__footer">
136
+ <v-btn class="screen-btn-ghost" variant="outlined" :disabled="recv.saving" @click="recv.show = false">Cancel</v-btn>
137
+ <v-btn class="screen-btn-primary" variant="flat" color="error" :loading="recv.saving" :disabled="!recv.reason.trim()" @click="saveNotReceived">Not Received</v-btn>
138
+ </div>
139
+ </v-card>
140
+ </v-dialog>
141
+
142
+ <v-dialog v-model="date.show" max-width="440">
143
+ <v-card v-if="date.row" class="screen-modal">
144
+ <v-card-title class="d-flex align-center">
145
+ Change return date
146
+ <v-spacer />
147
+ <v-btn icon="mdi-close" variant="text" class="screen-modal__close" aria-label="Close" @click="date.show = false" />
148
+ </v-card-title>
149
+ <v-card-text class="screen-modal__body">
150
+ <p class="text-body-2 mb-3">
151
+ <strong>{{ qtyUnit(date.row.outQty, date.row.unit) }} of {{ date.row.itemName }}</strong> with {{ date.row.holderName }}
152
+ <template v-if="date.row.workOrderNumber"> for {{ date.row.workOrderNumber }}</template>.
153
+ Now: <strong>{{ date.row.returnDate ? returnDayText(date.row.returnDate) : "no return date" }}</strong>.
154
+ </p>
155
+ <InputLabel title="New return date" class="mb-1" />
156
+ <InputDatePicker
157
+ v-model="date.value"
158
+ :min="todayKey"
159
+ placeholder="DD/MM/YYYY"
160
+ density="comfortable"
161
+ clearable
162
+ persistent-clear
163
+ hint="Leave empty to remove the return date (it is then never overdue)."
164
+ persistent-hint
165
+ />
166
+ <InputLabel title="Reason (optional)" class="mb-1 mt-3" />
167
+ <v-text-field v-model="date.reason" density="comfortable" maxlength="300" placeholder="e.g. job extended, forgot to set it" clearable persistent-clear hide-details />
168
+ </v-card-text>
169
+ <div class="screen-modal__footer">
170
+ <v-btn class="screen-btn-ghost" variant="outlined" :disabled="date.saving" @click="date.show = false">Cancel</v-btn>
171
+ <v-btn class="screen-btn-primary" variant="flat" :loading="date.saving" @click="saveDate">Save</v-btn>
172
+ </div>
173
+ </v-card>
174
+ </v-dialog>
175
+ </div>
176
+ </template>
177
+
178
+ <script setup lang="ts">
179
+ import useInventory from "../composables/useInventory";
180
+ import useUtils from "../composables/useUtils";
181
+ import { qtyUnit } from "../utils/inventory-ack";
182
+ import { workOrderLinkTarget } from "../utils/work-order-link";
183
+ import { askLeft, checkoutChip, checkoutStats, returnDayKey, RETURN_ASKED_INFO } from "../utils/inventory-checkout";
184
+
185
+ const props = defineProps({
186
+ store: { type: Object as PropType<TInventoryStore>, required: true },
187
+ /** Only the signed-in person's checkouts (My Stock). */
188
+ mine: { type: Boolean, default: false },
189
+ /** Bumped when stock changed on another tab (a return accepted in Cleaners): reload. */
190
+ refresh: { type: Number, default: 0 },
191
+ });
192
+ const emit = defineEmits<{ counts: [{ out: number; overdue: number }]; changed: [] }>();
193
+ /** Store keepers take items back (the API checks too). */
194
+ const canTakeBack = computed(() => Boolean(props.store.access?.canHandle));
195
+
196
+ // DV-1787: Received / Not Received on a row not received yet (its issue's request).
197
+ const recv = reactive({ show: false, row: null as TInventoryCheckout | null, reason: "", saving: false, busy: "" });
198
+ async function markReceived(row: TInventoryCheckout) {
199
+ if (!row.request) return;
200
+ recv.busy = row._id;
201
+ try {
202
+ await useInventory().acknowledgeRequest(String(row.request));
203
+ await load();
204
+ emit("changed");
205
+ } finally {
206
+ recv.busy = "";
207
+ }
208
+ }
209
+ const openNotReceived = (row: TInventoryCheckout) => Object.assign(recv, { show: true, row, reason: "" });
210
+ async function saveNotReceived() {
211
+ if (!recv.row?.request || !recv.reason.trim()) return;
212
+ recv.saving = true;
213
+ try {
214
+ await useInventory().notReceived(String(recv.row.request), recv.reason.trim());
215
+ recv.show = false;
216
+ await load();
217
+ emit("changed");
218
+ } finally {
219
+ recv.saving = false;
220
+ }
221
+ }
222
+ // DV-1787: Return / Ask to return on one row - closes that checkout (its work order).
223
+ const ret = reactive({ show: false, row: null as TInventoryCheckout | null });
224
+ function openReturn(row: TInventoryCheckout) {
225
+ Object.assign(ret, { show: true, row });
226
+ }
227
+ // DV-1787: store keepers set, change or clear a checkout's return date.
228
+ const notifyDate = inject<(text: string, color?: string) => void>("inventoryNotify", () => {});
229
+ const todayKey = new Date().toLocaleDateString("en-CA", { timeZone: "Asia/Singapore" });
230
+ const date = reactive({ show: false, row: null as TInventoryCheckout | null, value: null as string | null, reason: "", saving: false });
231
+ function openDate(row: TInventoryCheckout) {
232
+ Object.assign(date, { show: true, row, value: row.returnDate ? String(row.returnDate).slice(0, 10) : null, reason: "", saving: false });
233
+ }
234
+ async function saveDate() {
235
+ if (!date.row) return;
236
+ date.saving = true;
237
+ try {
238
+ await api.changeReturnDate(date.row._id, date.value || null, date.reason || "");
239
+ notifyDate(date.value ? "Return date changed." : "Return date removed.");
240
+ date.show = false;
241
+ await load();
242
+ emit("changed");
243
+ } catch (error: any) {
244
+ notifyDate(error?.data?.message || "Could not change the return date.", "error");
245
+ } finally {
246
+ date.saving = false;
247
+ }
248
+ }
249
+
250
+ // DV-1787: Status shows the quantities; the plain "Not returned yet" / "Out" chip says nothing more.
251
+ const rowStats = (c: TInventoryCheckout) => checkoutStats([c]).filter((x) => x.n > 0);
252
+ const chipShown = (c: TInventoryCheckout) => !["Not returned yet", "Out"].includes(checkoutChip(c).text);
253
+ // DV-1787: tap a row for its details (serial table, Received / Not Received / Ask to Return).
254
+ const det = reactive({ show: false, row: null as TInventoryCheckout | null });
255
+ const openDetail = (row: TInventoryCheckout) => Object.assign(det, { show: true, row });
256
+ async function afterDetail() {
257
+ await load();
258
+ // keep the dialog on the same row, now refreshed
259
+ det.row = rows.value.find((r) => r._id === det.row?._id) ?? det.row;
260
+ emit("changed");
261
+ }
262
+
263
+ async function afterReturn() {
264
+ await load();
265
+ emit("changed");
266
+ }
267
+
268
+ const api = useInventory();
269
+ const { standardFormatDate, standardFormatDateTime, debounce } = useUtils();
270
+ const route = useRoute();
271
+ const router = useRouter();
272
+
273
+ const status = ref<"out" | "overdue" | "closed" | "all">("out");
274
+ const search = ref("");
275
+ const page = ref(1);
276
+ const limit = ref(10);
277
+ const rows = ref<TInventoryCheckout[]>([]);
278
+ const total = ref(0);
279
+ const loading = ref(false);
280
+ const counts = ref({ out: 0, overdue: 0 });
281
+
282
+ const headers = computed(() => [
283
+ { title: "Item", key: "itemName", sortable: false },
284
+ { title: "Issued", key: "createdAt", sortable: false },
285
+ ...(props.mine ? [] : [{ title: "With", key: "holderName", sortable: false }]),
286
+ { title: "Qty", key: "qty", sortable: false },
287
+ { title: "Work order", key: "workOrderNumber", sortable: false },
288
+ { title: "Return by", key: "returnDate", sortable: false },
289
+ { title: "Returned", key: "closedAt", sortable: false },
290
+ { title: "Status", key: "status", sortable: false },
291
+ ...(props.mine || canTakeBack.value ? [{ title: "", key: "actions", sortable: false, align: "end" as const }] : []),
292
+ ]);
293
+
294
+ /** A return date is a calendar day: the standard date format, as that day wherever the browser is. */
295
+ const returnDayText = (d: string) => standardFormatDate(returnDayKey(d));
296
+ const chip = checkoutChip;
297
+
298
+ async function load() {
299
+ loading.value = true;
300
+ try {
301
+ const res = await api.getCheckouts(props.store._id, {
302
+ status: status.value === "overdue" ? "out" : status.value,
303
+ overdue: status.value === "overdue",
304
+ mine: props.mine,
305
+ page: page.value,
306
+ limit: limit.value,
307
+ search: search.value || "",
308
+ });
309
+ rows.value = res.items;
310
+ total.value = res.total;
311
+ counts.value = res.counts;
312
+ emit("counts", res.counts);
313
+ } catch {
314
+ rows.value = [];
315
+ total.value = 0;
316
+ } finally {
317
+ loading.value = false;
318
+ }
319
+ }
320
+ const reload = debounce(() => {
321
+ page.value = 1;
322
+ load();
323
+ }, 300);
324
+ watch([status, search], () => reload());
325
+ watch(
326
+ () => props.store._id,
327
+ () => {
328
+ page.value = 1;
329
+ load();
330
+ },
331
+ );
332
+ onMounted(load);
333
+ watch(() => props.refresh, () => load());
334
+ defineExpose({ load });
335
+ </script>
336
+
337
+ <style scoped>
338
+ .co-table :deep(tbody tr) {
339
+ cursor: pointer;
340
+ }
341
+ .co-pill {
342
+ font-size: 0.875rem;
343
+ border: 1px solid rgba(var(--v-border-color), var(--v-border-opacity));
344
+ border-radius: 14px;
345
+ padding: 1px 9px;
346
+ white-space: nowrap;
347
+ color: rgba(var(--v-theme-on-surface), var(--v-medium-emphasis-opacity));
348
+ }
349
+ </style>
@@ -60,7 +60,12 @@
60
60
  <template #item.person="{ item }">{{ item.holderLabel || item.holderName || "—" }}</template>
61
61
  <template #item.qty="{ item }">{{ qtyUnit(item.qty, item.unit) }}</template>
62
62
  <template #item.where="{ item }">{{ whereText(item.location) || (item.type === "handover" ? item.remarks : "") || "—" }}</template>
63
- <template #item.reference="{ item }">{{ item.type === "handover" ? "—" : item.reference || "—" }}</template>
63
+ <template #item.reference="{ item }">
64
+ <!-- DV-1787: a work order is a link; never a raw id -->
65
+ <NuxtLink v-if="item.workOrder && item.workOrderNumber && workOrderRoute(item)" :to="workOrderRoute(item)!" class="history-wo-link" @click="show = false">{{ item.workOrderNumber }}</NuxtLink>
66
+ <span v-else-if="item.workOrderNumber">{{ item.workOrderNumber }}</span>
67
+ <span v-else>{{ item.type === "handover" || /^[a-f0-9]{24}$/i.test(item.reference || "") ? "—" : item.reference || "—" }}</span>
68
+ </template>
64
69
  <template #item.photos="{ item }">
65
70
  <InventoryPhotoThumbs :photos="item.photos" :before-at="item.photosBeforeAt" :after-at="item.photosAfterAt" />
66
71
  </template>
@@ -81,6 +86,7 @@
81
86
  import useInventory from "../composables/useInventory";
82
87
  import useUtils from "../composables/useUtils";
83
88
  import useLocalAuth from "../composables/useLocalAuth";
89
+ import { workOrderLinkTarget } from "../utils/work-order-link";
84
90
  import { historyText, whereText } from "../utils/inventory-usage";
85
91
  import { inventoryStepsLive, qtyUnit } from "../utils/inventory-ack";
86
92
 
@@ -90,6 +96,9 @@ import { inventoryStepsLive, qtyUnit } from "../utils/inventory-ack";
90
96
  * store, hand-overs in and out, usage with where + work order + photos, and returns. Drafts are not history.
91
97
  */
92
98
  const show = defineModel<boolean>({ default: false });
99
+ const route = useRoute();
100
+ const router = useRouter();
101
+ const workOrderRoute = (t: TInventoryTransaction) => workOrderLinkTarget(t, route, router);
93
102
  const props = defineProps({
94
103
  store: { type: Object as PropType<TInventoryStore>, required: true },
95
104
  holder: { type: String, default: "" },
@@ -218,3 +227,15 @@ watch(show, async (open) => {
218
227
  }
219
228
  });
220
229
  </script>
230
+
231
+ <style scoped>
232
+ /* DV-1787: work order link (as in item History) */
233
+ .history-wo-link {
234
+ color: var(--accent);
235
+ font-weight: 600;
236
+ text-decoration: none;
237
+ }
238
+ .history-wo-link:hover {
239
+ text-decoration: underline;
240
+ }
241
+ </style>
@@ -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
@@ -164,6 +172,8 @@ function describe(t: TInventoryTransaction) {
164
172
  if (t.type === "transfer") parts.push(`${t.qty} ${t.storeChange > 0 ? "from" : "to"} ${t.transferStoreName || "another store"}`, t.reference || "", t.remarks || "");
165
173
  if (t.type === "write_off") parts.push(`${t.qty} ${writeOffLabel(t.writeOffReason).toLowerCase()}`, (t.holderChange ?? 0) < 0 ? `by ${who}` : "from the shelf", t.remarks || "");
166
174
  if (t.type === "opening") parts.push(t.supplier || "", t.reference ? `PO ${t.reference}` : "", t.receivedBy ? `received by ${t.receivedBy}` : "", t.remarks || "");
175
+ // DV-1787: which units, for an item with serial numbers.
176
+ if (t.serials?.length) parts.push(`S/N ${t.serials.join(", ")}`);
167
177
  return parts.filter(Boolean).join(" · ");
168
178
  }
169
179
 
@@ -20,6 +20,28 @@
20
20
  <v-col v-if="!item" cols="12" sm="4">
21
21
  <InputLabel title="Quantity in store now" class="mb-1" />
22
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
+ <!-- DV-1787: a serial number for each unit; each is then tracked one by one -->
24
+ <v-btn
25
+ v-if="Number(f.openingQty) > 0"
26
+ size="small"
27
+ variant="text"
28
+ color="primary"
29
+ class="text-none px-1 mt-1"
30
+ prepend-icon="mdi-barcode"
31
+ @click="serialsOpen = !serialsOpen"
32
+ >
33
+ {{ serialsOpen ? "Hide serial numbers" : "Serial numbers" }}{{ serialCount ? ` (${serialCount})` : "" }}
34
+ </v-btn>
35
+ </v-col>
36
+ <v-col v-if="serialsOpen && Number(f.openingQty) > 0" cols="12">
37
+ <div class="text-caption text-medium-emphasis mb-1">
38
+ One per unit (optional). Units with a serial number are tracked one by one: you choose the serial when issuing, and each has its own history.
39
+ </div>
40
+ <v-row dense>
41
+ <v-col v-for="(s, i) in serialFields" :key="i" cols="12" sm="4">
42
+ <v-text-field v-model="serialFields[i]" :label="`Unit ${i + 1}`" density="compact" maxlength="100" clearable persistent-clear hide-details />
43
+ </v-col>
44
+ </v-row>
23
45
  </v-col>
24
46
  <v-col cols="12" sm="4">
25
47
  <InputLabel title="Pack size (info only)" class="mb-1" />
@@ -163,6 +185,18 @@ const inUse = ref(true);
163
185
  /** A bare-number pack size on a new item with 0 in store: asked once before saving. */
164
186
  const packGuess = ref<number | null>(null);
165
187
  const zeroConfirmed = ref(false);
188
+ // DV-1787: serial numbers for the opening units (one field per unit, up to 100).
189
+ const serialsOpen = ref(false);
190
+ const serialFields = ref<string[]>([]);
191
+ const serialCount = computed(() => serialFields.value.filter((s) => String(s ?? "").trim()).length);
192
+ watch(
193
+ () => Number(f.openingQty) || 0,
194
+ (n) => {
195
+ const size = Math.min(100, Math.max(0, n));
196
+ serialFields.value = Array.from({ length: size }, (_, i) => serialFields.value[i] ?? "");
197
+ },
198
+ { immediate: true },
199
+ );
166
200
  watch(() => [f.openingQty, f.packing], () => {
167
201
  packGuess.value = null;
168
202
  zeroConfirmed.value = false;
@@ -183,6 +217,8 @@ watch(show, (open) => {
183
217
  if (!open) return;
184
218
  const i = props.item;
185
219
  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) } : {});
220
+ serialsOpen.value = false;
221
+ serialFields.value = [];
186
222
  photo.value = i?.photo ? [i.photo] : [];
187
223
  inUse.value = i ? i.status === "active" : true;
188
224
  packGuess.value = null;
@@ -223,6 +259,7 @@ async function save() {
223
259
  openingReference: f.openingReference,
224
260
  openingReceivedBy: f.openingReceivedBy,
225
261
  openingRemarks: f.openingRemarks,
262
+ serials: serialFields.value.map((s) => String(s ?? "").trim()).filter(Boolean),
226
263
  }
227
264
  : { openingQty: 0 };
228
265
  await createItem(props.store._id, { ...body, ...opening });