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

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.
@@ -333,7 +333,7 @@
333
333
  :icon="card.icon"
334
334
  :tint="card.tint"
335
335
  :color="card.color"
336
- :label="cardTitle(card)"
336
+ :label="uiTr(cardTitle(card))"
337
337
  :value="card.value"
338
338
  :chip="kpiChipText(card)"
339
339
  :down="Number(card.percentage) < 0"
@@ -422,7 +422,7 @@
422
422
  >
423
423
  <div class="d-flex align-center justify-space-between">
424
424
  <h2 class="dashboard-card-title mb-0">
425
- {{ activityTitle }}
425
+ {{ uiTr(activityTitle) }}
426
426
  </h2>
427
427
  </div>
428
428
 
@@ -1108,10 +1108,10 @@
1108
1108
  <div
1109
1109
  class="text-body-2 font-weight-black text-high-emphasis"
1110
1110
  >
1111
- {{ widget.title }}
1111
+ {{ uiTr(widget.title) }}
1112
1112
  </div>
1113
1113
  <div class="text-caption text-medium-emphasis mt-1">
1114
- {{ widget.description }}
1114
+ {{ uiTr(widget.description) }}
1115
1115
  </div>
1116
1116
  </div>
1117
1117
  <!--
@@ -1230,6 +1230,8 @@
1230
1230
  </template>
1231
1231
 
1232
1232
  <script setup lang="ts">
1233
+ // Explicit, not the `$tr` global: renders the same in unit tests that mount this file.
1234
+ import { uiTr } from "../composables/useUiLanguage";
1233
1235
  // The one non-auto-imported thing this file needs: the cookie options type, so
1234
1236
  // `runtimeConfig.public.cookieConfig` (typed `unknown`) can be narrowed once
1235
1237
  // rather than at the call site. Same import `useThemePreference.ts` uses.
@@ -0,0 +1,144 @@
1
+ <template>
2
+ <!--
3
+ DV-1787: return ONE checked-out item (its work order). `ask`: the holder asks to return it (a store
4
+ keeper accepts it when they have it). `return`: a store keeper takes it back now, or accepts the
5
+ holder's request.
6
+ -->
7
+ <v-dialog v-model="show" max-width="500">
8
+ <v-card v-if="row" class="screen-modal">
9
+ <v-card-title class="d-flex align-center">
10
+ {{ title }}
11
+ <v-spacer />
12
+ <v-btn icon="mdi-close" variant="text" class="screen-modal__close" aria-label="Close" @click="show = false" />
13
+ </v-card-title>
14
+ <v-card-text class="screen-modal__body">
15
+ <p class="text-body-2 mb-3">
16
+ <strong>{{ qtyUnit(row.outQty, row.unit) }} of {{ row.itemName }}</strong>
17
+ <template v-if="row.workOrderNumber"> for work order <strong>{{ row.workOrderNumber }}</strong></template>
18
+ <template v-if="mode === 'return'"> from {{ row.holderName }}</template>
19
+ <template v-if="row.returnDate"> · return by {{ returnDayText(row.returnDate) }}</template>
20
+ </p>
21
+
22
+ <v-alert type="info" variant="tonal" density="compact" class="mb-3" icon="mdi-information-outline">
23
+ <template v-if="mode === 'ask'">
24
+ <div class="font-weight-medium mb-1">How Ask to return works</div>
25
+ <ol class="return-steps">
26
+ <li>The store keeper is told you are bringing this back. (If you had not tapped Received for it yet, this also confirms you got it.)</li>
27
+ <li>Hand it over at the store. Until the store keeper accepts it, it stays with you: it still shows under Checked out to me and on the work order, with "Return asked".</li>
28
+ <li>When they accept, it goes back into the store and shows Returned with the date and time.</li>
29
+ <li>Only then can the work order (or its feedback) be completed, if Work Order Settings ask for items to be returned first.</li>
30
+ </ol>
31
+ </template>
32
+ <template v-else-if="row.returnRequest">
33
+ {{ row.holderName }} asked to return it. Accept once you have it in hand: it goes back into the store now and the work order is freed.
34
+ </template>
35
+ <template v-else>
36
+ Take it back now: it goes back into the store straight away and shows Returned for this work order. Use this when it is in your hands.
37
+ </template>
38
+ </v-alert>
39
+
40
+ <!-- DV-1787: serial numbers out on it - return all of them, or only some (one) -->
41
+ <template v-if="serials.length > 1 && !(mode === 'return' && row.returnRequest)">
42
+ <InputLabel title="Serial numbers" class="mb-1" />
43
+ <v-radio-group v-model="which" inline hide-details density="compact" class="mb-1">
44
+ <v-radio :label="`All ${serials.length}`" value="all" />
45
+ <v-radio label="Choose which" value="some" />
46
+ </v-radio-group>
47
+ <div v-if="which === 'all'" class="text-caption text-medium-emphasis mb-3">{{ serials.map((s) => s.serial).join(", ") }}</div>
48
+ <div v-else class="d-flex flex-wrap ga-2 mb-3">
49
+ <v-checkbox
50
+ v-for="s in serials"
51
+ :key="s._id"
52
+ v-model="picked"
53
+ :value="s._id"
54
+ :label="s.serial"
55
+ density="compact"
56
+ hide-details
57
+ />
58
+ </div>
59
+ </template>
60
+ <div v-else-if="serials.length === 1" class="text-caption text-medium-emphasis mb-3">Serial number: {{ serials[0].serial }}</div>
61
+ <template v-if="!(mode === 'return' && row.returnRequest)">
62
+ <InputLabel title="Note (optional)" class="mb-1" />
63
+ <v-text-field v-model="note" density="comfortable" placeholder="e.g. job done, left at the store counter" hide-details />
64
+ </template>
65
+ </v-card-text>
66
+ <div class="screen-modal__footer">
67
+ <v-btn class="screen-btn-ghost" variant="outlined" :disabled="saving" @click="show = false">Cancel</v-btn>
68
+ <v-btn class="screen-btn-primary" variant="flat" :loading="saving" :disabled="which === 'some' && !picked.length" @click="confirm">
69
+ {{ title }}{{ which === "some" && picked.length ? ` (${picked.length})` : "" }}
70
+ </v-btn>
71
+ </div>
72
+ </v-card>
73
+ </v-dialog>
74
+ <Snackbar v-model="toast.show" :text="toast.message" :color="toast.color" />
75
+ </template>
76
+
77
+ <script setup lang="ts">
78
+ import useInventory from "../composables/useInventory";
79
+ import useUtils from "../composables/useUtils";
80
+ import { qtyUnit } from "../utils/inventory-ack";
81
+ import { returnDayKey } from "../utils/inventory-checkout";
82
+
83
+ const show = defineModel<boolean>({ default: false });
84
+ const props = defineProps({
85
+ row: { type: Object as PropType<TInventoryCheckout | null>, default: null },
86
+ /** `ask`: the holder asks to return it. `return`: a store keeper takes it back (or accepts the request). */
87
+ mode: { type: String as PropType<"ask" | "return">, default: "ask" },
88
+ });
89
+ const emit = defineEmits<{ done: [] }>();
90
+
91
+ const api = useInventory();
92
+ const { standardFormatDate } = useUtils();
93
+ // Inventory pages give their own message bar; elsewhere (work order / feedback details) this one is used.
94
+ const toast = reactive({ show: false, message: "", color: "success" });
95
+ const injected = inject<((text: string, color?: string) => void) | null>("inventoryNotify", null);
96
+ const notify = (text: string, color = "success") => (injected ? injected(text, color) : Object.assign(toast, { show: true, message: text, color }));
97
+ const note = ref("");
98
+ const saving = ref(false);
99
+ // DV-1787: serial numbers still out on it; return all, or the chosen ones.
100
+ const serials = computed(() => props.row?.serials ?? []);
101
+ const which = ref<"all" | "some">("all");
102
+ const picked = ref<string[]>([]);
103
+ const chosenSerials = () => (which.value === "some" ? picked.value : undefined);
104
+
105
+ const title = computed(() => (props.mode === "ask" ? "Ask to return" : props.row?.returnRequest ? "Accept return" : "Return to store"));
106
+ const returnDayText = (d: string) => standardFormatDate(returnDayKey(d));
107
+
108
+ async function confirm() {
109
+ if (!props.row) return;
110
+ saving.value = true;
111
+ try {
112
+ if (props.mode === "ask") {
113
+ await api.requestCheckoutReturn(props.row._id, note.value, chosenSerials());
114
+ notify("Return asked. The store keeper accepts it when they have it.");
115
+ } else {
116
+ await api.returnCheckout(props.row._id, note.value, chosenSerials());
117
+ notify("Returned to the store.");
118
+ }
119
+ show.value = false;
120
+ emit("done");
121
+ } catch (error: any) {
122
+ notify(error?.data?.message || "Something went wrong. Please try again.", "error");
123
+ } finally {
124
+ saving.value = false;
125
+ }
126
+ }
127
+
128
+ watch(show, (open) => {
129
+ if (!open) return;
130
+ note.value = "";
131
+ which.value = "all";
132
+ picked.value = [];
133
+ });
134
+ </script>
135
+
136
+ <style scoped>
137
+ .return-steps {
138
+ padding-left: 18px;
139
+ margin: 0;
140
+ }
141
+ .return-steps li {
142
+ margin-bottom: 2px;
143
+ }
144
+ </style>
@@ -0,0 +1,257 @@
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
+ @update:page="(p: number) => ((page = p), load())"
41
+ @update:items-per-page="(n: number) => ((limit = n), (page = 1), load())"
42
+ >
43
+ <template #item.itemName="{ item }">
44
+ <span class="font-weight-medium">{{ item.itemName }}</span>
45
+ <div v-if="item.serials?.length" class="text-caption text-medium-emphasis">S/N {{ item.serials.map((s) => s.serial).join(", ") }}</div>
46
+ </template>
47
+ <template #item.createdAt="{ item }">
48
+ <div class="text-no-wrap">{{ standardFormatDateTime(item.createdAt) }}</div>
49
+ <div class="text-caption text-medium-emphasis">by {{ item.createdByName }}</div>
50
+ </template>
51
+ <template #item.holderName="{ item }">{{ item.holderName }}</template>
52
+ <template #item.qty="{ item }">
53
+ <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>
54
+ <span v-else class="text-medium-emphasis">{{ qtyUnit(item.qty, item.unit) }}</span>
55
+ </template>
56
+ <template #item.workOrderNumber="{ item }">
57
+ <NuxtLink v-if="workOrderLinkTarget(item, route, router)" :to="workOrderLinkTarget(item, route, router)!" class="text-primary">{{ item.workOrderNumber }}</NuxtLink>
58
+ <span v-else>{{ item.workOrderNumber || "—" }}</span>
59
+ </template>
60
+ <template #item.returnDate="{ item }">
61
+ <span class="text-no-wrap">{{ item.returnDate ? returnDayText(item.returnDate) : "—" }}</span>
62
+ <!-- DV-1787: changed after the issue - by whom, and when -->
63
+ <div v-if="item.dateChanges?.length" class="text-caption text-medium-emphasis text-no-wrap">
64
+ changed by {{ item.dateChanges[item.dateChanges.length - 1].byName }}
65
+ </div>
66
+ </template>
67
+ <template #item.closedAt="{ item }">
68
+ <span class="text-no-wrap">{{ item.status !== "out" && item.closedAt ? standardFormatDateTime(item.closedAt) : "—" }}</span>
69
+ </template>
70
+ <template #item.status="{ item }">
71
+ <!-- hover: what the status means -->
72
+ <v-tooltip :text="chip(item).info" location="top" max-width="280">
73
+ <template #activator="{ props: tip }">
74
+ <v-chip v-bind="tip" size="small" variant="tonal" :color="chip(item).color" :prepend-icon="chip(item).icon">{{ chip(item).text }}</v-chip>
75
+ </template>
76
+ </v-tooltip>
77
+ <v-tooltip v-if="item.status === 'out' && item.returnRequest" :text="RETURN_ASKED_INFO" location="top" max-width="280">
78
+ <template #activator="{ props: tip }">
79
+ <v-chip v-bind="tip" size="small" variant="tonal" color="primary" class="ml-1" prepend-icon="mdi-keyboard-return">Return asked</v-chip>
80
+ </template>
81
+ </v-tooltip>
82
+ </template>
83
+ <!-- DV-1787: return THIS checkout (its work order), not the earliest one of the item. -->
84
+ <template #item.actions="{ item }">
85
+ <template v-if="item.status === 'out'">
86
+ <v-btn v-if="mine && !item.returnRequest" size="small" variant="tonal" color="primary" class="text-none" prepend-icon="mdi-keyboard-return" @click="openReturn(item)">
87
+ Ask to return
88
+ </v-btn>
89
+ <div v-else-if="!mine && canTakeBack" class="d-flex ga-1 justify-end">
90
+ <v-btn size="small" variant="tonal" color="primary" class="text-none" prepend-icon="mdi-keyboard-return" @click="openReturn(item)">
91
+ {{ item.returnRequest ? "Accept return" : "Return" }}
92
+ </v-btn>
93
+ <!-- DV-1787: set, change or clear the return date (forgotten at the issue, or more time given) -->
94
+ <v-tooltip text="Change return date" location="top">
95
+ <template #activator="{ props: tip }">
96
+ <v-btn v-bind="tip" size="small" variant="tonal" icon="mdi-calendar-edit" aria-label="Change return date" @click="openDate(item)" />
97
+ </template>
98
+ </v-tooltip>
99
+ </div>
100
+ </template>
101
+ </template>
102
+ </v-data-table-server>
103
+
104
+ <InventoryCheckoutReturnDialog v-model="ret.show" :row="ret.row" :mode="mine ? 'ask' : 'return'" @done="afterReturn" />
105
+
106
+ <v-dialog v-model="date.show" max-width="440">
107
+ <v-card v-if="date.row" class="screen-modal">
108
+ <v-card-title class="d-flex align-center">
109
+ Change return date
110
+ <v-spacer />
111
+ <v-btn icon="mdi-close" variant="text" class="screen-modal__close" aria-label="Close" @click="date.show = false" />
112
+ </v-card-title>
113
+ <v-card-text class="screen-modal__body">
114
+ <p class="text-body-2 mb-3">
115
+ <strong>{{ qtyUnit(date.row.outQty, date.row.unit) }} of {{ date.row.itemName }}</strong> with {{ date.row.holderName }}
116
+ <template v-if="date.row.workOrderNumber"> for {{ date.row.workOrderNumber }}</template>.
117
+ Now: <strong>{{ date.row.returnDate ? returnDayText(date.row.returnDate) : "no return date" }}</strong>.
118
+ </p>
119
+ <InputLabel title="New return date" class="mb-1" />
120
+ <InputDatePicker
121
+ v-model="date.value"
122
+ :min="todayKey"
123
+ placeholder="DD/MM/YYYY"
124
+ density="comfortable"
125
+ clearable
126
+ persistent-clear
127
+ hint="Leave empty to remove the return date (it is then never overdue)."
128
+ persistent-hint
129
+ />
130
+ <InputLabel title="Reason (optional)" class="mb-1 mt-3" />
131
+ <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 />
132
+ </v-card-text>
133
+ <div class="screen-modal__footer">
134
+ <v-btn class="screen-btn-ghost" variant="outlined" :disabled="date.saving" @click="date.show = false">Cancel</v-btn>
135
+ <v-btn class="screen-btn-primary" variant="flat" :loading="date.saving" @click="saveDate">Save</v-btn>
136
+ </div>
137
+ </v-card>
138
+ </v-dialog>
139
+ </div>
140
+ </template>
141
+
142
+ <script setup lang="ts">
143
+ import useInventory from "../composables/useInventory";
144
+ import useUtils from "../composables/useUtils";
145
+ import { qtyUnit } from "../utils/inventory-ack";
146
+ import { workOrderLinkTarget } from "../utils/work-order-link";
147
+ import { checkoutChip, returnDayKey, RETURN_ASKED_INFO } from "../utils/inventory-checkout";
148
+
149
+ const props = defineProps({
150
+ store: { type: Object as PropType<TInventoryStore>, required: true },
151
+ /** Only the signed-in person's checkouts (My Stock). */
152
+ mine: { type: Boolean, default: false },
153
+ });
154
+ const emit = defineEmits<{ counts: [{ out: number; overdue: number }]; changed: [] }>();
155
+ /** Store keepers take items back (the API checks too). */
156
+ const canTakeBack = computed(() => Boolean(props.store.access?.canHandle));
157
+
158
+ // DV-1787: Return / Ask to return on one row - closes that checkout (its work order).
159
+ const ret = reactive({ show: false, row: null as TInventoryCheckout | null });
160
+ function openReturn(row: TInventoryCheckout) {
161
+ Object.assign(ret, { show: true, row });
162
+ }
163
+ // DV-1787: store keepers set, change or clear a checkout's return date.
164
+ const notifyDate = inject<(text: string, color?: string) => void>("inventoryNotify", () => {});
165
+ const todayKey = new Date().toLocaleDateString("en-CA", { timeZone: "Asia/Singapore" });
166
+ const date = reactive({ show: false, row: null as TInventoryCheckout | null, value: null as string | null, reason: "", saving: false });
167
+ function openDate(row: TInventoryCheckout) {
168
+ Object.assign(date, { show: true, row, value: row.returnDate ? String(row.returnDate).slice(0, 10) : null, reason: "", saving: false });
169
+ }
170
+ async function saveDate() {
171
+ if (!date.row) return;
172
+ date.saving = true;
173
+ try {
174
+ await api.changeReturnDate(date.row._id, date.value || null, date.reason || "");
175
+ notifyDate(date.value ? "Return date changed." : "Return date removed.");
176
+ date.show = false;
177
+ await load();
178
+ emit("changed");
179
+ } catch (error: any) {
180
+ notifyDate(error?.data?.message || "Could not change the return date.", "error");
181
+ } finally {
182
+ date.saving = false;
183
+ }
184
+ }
185
+
186
+ async function afterReturn() {
187
+ await load();
188
+ emit("changed");
189
+ }
190
+
191
+ const api = useInventory();
192
+ const { standardFormatDate, standardFormatDateTime, debounce } = useUtils();
193
+ const route = useRoute();
194
+ const router = useRouter();
195
+
196
+ const status = ref<"out" | "overdue" | "closed" | "all">("out");
197
+ const search = ref("");
198
+ const page = ref(1);
199
+ const limit = ref(10);
200
+ const rows = ref<TInventoryCheckout[]>([]);
201
+ const total = ref(0);
202
+ const loading = ref(false);
203
+ const counts = ref({ out: 0, overdue: 0 });
204
+
205
+ const headers = computed(() => [
206
+ { title: "Item", key: "itemName", sortable: false },
207
+ { title: "Issued", key: "createdAt", sortable: false },
208
+ ...(props.mine ? [] : [{ title: "With", key: "holderName", sortable: false }]),
209
+ { title: "Qty", key: "qty", sortable: false },
210
+ { title: "Work order", key: "workOrderNumber", sortable: false },
211
+ { title: "Return by", key: "returnDate", sortable: false },
212
+ { title: "Returned", key: "closedAt", sortable: false },
213
+ { title: "Status", key: "status", sortable: false },
214
+ ...(props.mine || canTakeBack.value ? [{ title: "", key: "actions", sortable: false, align: "end" as const }] : []),
215
+ ]);
216
+
217
+ /** A return date is a calendar day: the standard date format, as that day wherever the browser is. */
218
+ const returnDayText = (d: string) => standardFormatDate(returnDayKey(d));
219
+ const chip = checkoutChip;
220
+
221
+ async function load() {
222
+ loading.value = true;
223
+ try {
224
+ const res = await api.getCheckouts(props.store._id, {
225
+ status: status.value === "overdue" ? "out" : status.value,
226
+ overdue: status.value === "overdue",
227
+ mine: props.mine,
228
+ page: page.value,
229
+ limit: limit.value,
230
+ search: search.value || "",
231
+ });
232
+ rows.value = res.items;
233
+ total.value = res.total;
234
+ counts.value = res.counts;
235
+ emit("counts", res.counts);
236
+ } catch {
237
+ rows.value = [];
238
+ total.value = 0;
239
+ } finally {
240
+ loading.value = false;
241
+ }
242
+ }
243
+ const reload = debounce(() => {
244
+ page.value = 1;
245
+ load();
246
+ }, 300);
247
+ watch([status, search], () => reload());
248
+ watch(
249
+ () => props.store._id,
250
+ () => {
251
+ page.value = 1;
252
+ load();
253
+ },
254
+ );
255
+ onMounted(load);
256
+ defineExpose({ load });
257
+ </script>
@@ -164,6 +164,8 @@ function describe(t: TInventoryTransaction) {
164
164
  if (t.type === "transfer") parts.push(`${t.qty} ${t.storeChange > 0 ? "from" : "to"} ${t.transferStoreName || "another store"}`, t.reference || "", t.remarks || "");
165
165
  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
166
  if (t.type === "opening") parts.push(t.supplier || "", t.reference ? `PO ${t.reference}` : "", t.receivedBy ? `received by ${t.receivedBy}` : "", t.remarks || "");
167
+ // DV-1787: which units, for an item with serial numbers.
168
+ if (t.serials?.length) parts.push(`S/N ${t.serials.join(", ")}`);
167
169
  return parts.filter(Boolean).join(" · ");
168
170
  }
169
171
 
@@ -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 });