@7365admin1/layer-common 4.97.1-staging.733 → 4.97.1-staging.735

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,188 @@
1
+ <template>
2
+ <!--
3
+ DV-1787: scan serial numbers with the device camera, one after another, until every unit has
4
+ one (or Done). Reads 1D barcodes (Code 128, Code 39, EAN, UPC, ...) and 2D codes (QR, Data
5
+ Matrix, PDF417, Aztec). The same code twice, or one already entered, is skipped.
6
+ -->
7
+ <v-dialog v-model="show" max-width="560" persistent @after-enter="start">
8
+ <v-card class="screen-modal">
9
+ <v-card-title class="d-flex align-center">
10
+ Scan serial numbers
11
+ <v-spacer />
12
+ <v-btn icon="mdi-close" variant="text" class="screen-modal__close" aria-label="Close" @click="finish" />
13
+ </v-card-title>
14
+ <v-card-text class="screen-modal__body">
15
+ <p class="text-body-2 text-medium-emphasis mb-2">
16
+ Point the camera at each unit's barcode or QR code, one at a time. Each scan fills the next unit.
17
+ </p>
18
+ <div class="d-flex align-center mb-2">
19
+ <span class="text-subtitle-2">{{ scanned.length }} of {{ max }} scanned</span>
20
+ <v-spacer />
21
+ <v-btn v-if="cameras > 1" size="small" variant="text" class="text-none" prepend-icon="mdi-camera-switch" @click="switchCamera">Switch camera</v-btn>
22
+ </div>
23
+ <v-progress-linear :model-value="max ? (scanned.length / max) * 100 : 0" color="primary" rounded class="mb-3" />
24
+ <div :id="readerId" class="serial-scan__reader" />
25
+ <v-alert v-if="error" type="warning" variant="tonal" density="compact" class="mt-2">{{ error }}</v-alert>
26
+ <div v-if="last" class="serial-scan__last mt-2" :class="`serial-scan__last--${last.kind}`">
27
+ <v-icon :icon="last.kind === 'ok' ? 'mdi-check-circle' : 'mdi-information'" size="18" class="mr-1" />{{ last.text }}
28
+ </div>
29
+ <div v-if="scanned.length" class="d-flex flex-wrap ga-1 mt-3">
30
+ <v-chip v-for="(s, i) in scanned" :key="s" size="small" closable @click:close="scanned.splice(i, 1)">{{ s }}</v-chip>
31
+ </div>
32
+ </v-card-text>
33
+ <div class="screen-modal__footer">
34
+ <v-btn class="screen-btn-ghost" variant="outlined" @click="cancel">Cancel</v-btn>
35
+ <v-btn class="screen-btn-primary" variant="flat" :disabled="!scanned.length" @click="finish">
36
+ Done{{ scanned.length ? ` (${scanned.length})` : "" }}
37
+ </v-btn>
38
+ </div>
39
+ </v-card>
40
+ </v-dialog>
41
+ </template>
42
+
43
+ <script setup lang="ts">
44
+ const show = defineModel<boolean>({ default: false });
45
+ const props = defineProps({
46
+ /** How many serials are still needed (the scan stops by itself at this many). */
47
+ max: { type: Number, default: 1 },
48
+ /** Serials already entered or saved: scanning one of them is skipped. */
49
+ existing: { type: Array as PropType<string[]>, default: () => [] },
50
+ });
51
+ const emit = defineEmits<{ scanned: [serials: string[]] }>();
52
+
53
+ const { $Html5Qrcode }: any = useNuxtApp();
54
+ const readerId = `serial-scan-${Math.random().toString(36).slice(2, 8)}`;
55
+ const scanned = ref<string[]>([]);
56
+ const error = ref("");
57
+ const last = ref<{ kind: "ok" | "skip"; text: string } | null>(null);
58
+ const cameras = ref(0);
59
+ const facing = ref<"environment" | "user">("environment");
60
+ let reader: any = null;
61
+ let lastCode = "";
62
+ let lastAt = 0;
63
+
64
+ const key = (s: string) => s.trim().replace(/\s+/g, " ").toUpperCase();
65
+
66
+ function beep() {
67
+ try {
68
+ const ctx = new (window.AudioContext || (window as any).webkitAudioContext)();
69
+ const o = ctx.createOscillator();
70
+ o.frequency.value = 880;
71
+ o.connect(ctx.destination);
72
+ o.start();
73
+ setTimeout(() => (o.stop(), ctx.close()), 120);
74
+ } catch {
75
+ /* no sound - fine */
76
+ }
77
+ navigator.vibrate?.(80);
78
+ }
79
+
80
+ function onCode(text: string) {
81
+ const code = String(text ?? "").trim();
82
+ if (!code) return;
83
+ const now = Date.now();
84
+ // The same code stays in front of the camera for a while: read it once.
85
+ if (code === lastCode && now - lastAt < 2500) return;
86
+ lastCode = code;
87
+ lastAt = now;
88
+ const k = key(code);
89
+ if (scanned.value.some((s) => key(s) === k) || props.existing.some((s) => key(String(s)) === k)) {
90
+ last.value = { kind: "skip", text: `${code} is already in the list` };
91
+ return;
92
+ }
93
+ if (code.length > 100) {
94
+ last.value = { kind: "skip", text: "That code is too long for a serial number" };
95
+ return;
96
+ }
97
+ scanned.value.push(code);
98
+ last.value = { kind: "ok", text: `${code} added` };
99
+ beep();
100
+ if (scanned.value.length >= props.max) finish();
101
+ }
102
+
103
+ async function start() {
104
+ error.value = "";
105
+ if (reader) return;
106
+ try {
107
+ const list = await $Html5Qrcode.getCameras();
108
+ cameras.value = list?.length ?? 0;
109
+ } catch {
110
+ cameras.value = 0;
111
+ }
112
+ try {
113
+ reader = new $Html5Qrcode(readerId, { verbose: false, experimentalFeatures: { useBarCodeDetectorIfSupported: true } });
114
+ await reader.start(
115
+ { facingMode: facing.value },
116
+ {
117
+ fps: 10,
118
+ // Wide box: long 1D barcodes fit; square codes fit too.
119
+ qrbox: (w: number, h: number) => ({ width: Math.floor(Math.min(w * 0.85, 420)), height: Math.floor(Math.min(h * 0.6, 240)) }),
120
+ },
121
+ onCode,
122
+ () => {},
123
+ );
124
+ } catch (e: any) {
125
+ reader = null;
126
+ error.value = `Could not open the camera. Allow camera access in the browser and try again. (${e?.message ?? e})`;
127
+ }
128
+ }
129
+
130
+ async function stop() {
131
+ const r = reader;
132
+ reader = null;
133
+ if (!r) return;
134
+ try {
135
+ if (r.isScanning) await r.stop();
136
+ r.clear();
137
+ } catch {
138
+ /* already stopped */
139
+ }
140
+ }
141
+
142
+ async function switchCamera() {
143
+ await stop();
144
+ facing.value = facing.value === "environment" ? "user" : "environment";
145
+ start();
146
+ }
147
+
148
+ async function finish() {
149
+ await stop();
150
+ if (scanned.value.length) emit("scanned", [...scanned.value]);
151
+ show.value = false;
152
+ }
153
+
154
+ async function cancel() {
155
+ await stop();
156
+ show.value = false;
157
+ }
158
+
159
+ watch(show, (open) => {
160
+ if (open) {
161
+ scanned.value = [];
162
+ last.value = null;
163
+ lastCode = "";
164
+ } else stop();
165
+ });
166
+ onBeforeUnmount(stop);
167
+ </script>
168
+
169
+ <style scoped>
170
+ .serial-scan__reader {
171
+ width: 100%;
172
+ min-height: 240px;
173
+ border-radius: 8px;
174
+ overflow: hidden;
175
+ background: #000;
176
+ }
177
+ .serial-scan__last {
178
+ display: flex;
179
+ align-items: center;
180
+ font-size: 0.875rem;
181
+ }
182
+ .serial-scan__last--ok {
183
+ color: rgb(var(--v-theme-success));
184
+ }
185
+ .serial-scan__last--skip {
186
+ color: rgb(var(--v-theme-warning));
187
+ }
188
+ </style>
@@ -0,0 +1,202 @@
1
+ <template>
2
+ <!--
3
+ DV-1787: serial numbers of an item. Units on the shelf can each be given a serial; from then on
4
+ every unit is tracked one by one, with its own history (added, issued to whom and for which work
5
+ order, returned, written off, handed over).
6
+ -->
7
+ <v-dialog v-model="show" max-width="720" scrollable>
8
+ <v-card v-if="item" class="screen-modal">
9
+ <v-card-title class="d-flex align-center">
10
+ Serial numbers · {{ item.name }}
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 text-medium-emphasis mb-3">
16
+ {{ inStore }} of {{ onHand }} {{ unitWord(onHand, item.unit) }} on the shelf {{ inStore === 1 ? "has" : "have" }} a serial number.
17
+ {{ rows.length - inStore > 0 ? `${rows.length - inStore} more with people or closed.` : "" }}
18
+ </p>
19
+
20
+ <!-- one field per unit on the shelf that has no serial number yet -->
21
+ <template v-if="canAdd && free > 0">
22
+ <div class="d-flex align-center mb-2">
23
+ <div class="text-subtitle-2">Add serial numbers</div>
24
+ <v-spacer />
25
+ <span class="text-caption text-medium-emphasis mr-2">{{ free }} {{ unitWord(free, item.unit) }} without one</span>
26
+ <!-- DV-1787: scan barcodes / QR codes with the camera, one after another -->
27
+ <v-btn size="small" variant="tonal" color="primary" class="text-none" prepend-icon="mdi-barcode-scan" :disabled="!emptySlots" @click="scanning = true">
28
+ Scan
29
+ </v-btn>
30
+ </div>
31
+ <v-row dense>
32
+ <v-col v-for="(v, i) in entries" :key="i" cols="12" sm="6">
33
+ <v-text-field v-model="entries[i]" :label="`Unit ${i + 1}`" density="comfortable" maxlength="100" clearable persistent-clear hide-details />
34
+ </v-col>
35
+ </v-row>
36
+ <div class="d-flex justify-end mt-2 mb-4">
37
+ <v-btn class="screen-btn-primary text-none" variant="flat" :loading="saving" :disabled="!filled.length" @click="save">
38
+ Save {{ filled.length || "" }} serial {{ filled.length === 1 ? "number" : "numbers" }}
39
+ </v-btn>
40
+ </div>
41
+ </template>
42
+
43
+ <div class="d-flex align-center mb-2 ga-2 flex-wrap">
44
+ <div class="text-subtitle-2">Serial numbers and history</div>
45
+ <v-spacer />
46
+ <v-text-field v-model="search" density="compact" prepend-inner-icon="mdi-magnify" placeholder="Search serial" hide-details clearable style="max-width: 220px" />
47
+ </div>
48
+ <div v-if="!shown.length" class="text-body-2 text-medium-emphasis py-4 text-center">{{ loading ? "Loading…" : "No serial numbers yet." }}</div>
49
+ <v-expansion-panels v-else variant="accordion" density="compact">
50
+ <v-expansion-panel v-for="s in shown" :key="s._id">
51
+ <v-expansion-panel-title>
52
+ <div class="d-flex flex-wrap align-center ga-2 w-100">
53
+ <span class="font-weight-medium">{{ s.serial }}</span>
54
+ <v-tooltip :text="STATUS[s.status].info" location="top" max-width="260">
55
+ <template #activator="{ props: tip }">
56
+ <v-chip v-bind="tip" size="x-small" variant="tonal" :color="STATUS[s.status].color">{{ STATUS[s.status].text }}</v-chip>
57
+ </template>
58
+ </v-tooltip>
59
+ <span v-if="s.status === 'out'" class="text-caption text-medium-emphasis">
60
+ with {{ s.holderName }}<template v-if="s.workOrderNumber"> · {{ s.workOrderNumber }}</template>
61
+ </span>
62
+ </div>
63
+ </v-expansion-panel-title>
64
+ <v-expansion-panel-text>
65
+ <div v-for="(e, i) in [...s.history].reverse()" :key="i" class="serial-event">
66
+ <span class="text-no-wrap text-medium-emphasis">{{ standardFormatDateTime(e.at) }}</span>
67
+ <span>{{ eventText(e) }}</span>
68
+ </div>
69
+ </v-expansion-panel-text>
70
+ </v-expansion-panel>
71
+ </v-expansion-panels>
72
+ </v-card-text>
73
+ <div class="screen-modal__footer">
74
+ <v-btn class="screen-btn-ghost" variant="outlined" @click="show = false">Close</v-btn>
75
+ </div>
76
+ </v-card>
77
+ </v-dialog>
78
+ <InventorySerialScanner v-model="scanning" :max="emptySlots" :existing="[...rows.map((r) => r.serial), ...filled]" @scanned="fillScanned" />
79
+ </template>
80
+
81
+ <script setup lang="ts">
82
+ import useInventory from "../composables/useInventory";
83
+ import useUtils from "../composables/useUtils";
84
+ import { unitWord, writeOffLabel } from "../utils/inventory-ack";
85
+
86
+ const show = defineModel<boolean>({ default: false });
87
+ const props = defineProps({
88
+ store: { type: Object as PropType<TInventoryStore>, required: true },
89
+ item: { type: Object as PropType<TInventoryItem | null>, default: null },
90
+ });
91
+ const emit = defineEmits<{ changed: [] }>();
92
+
93
+ const api = useInventory();
94
+ const { standardFormatDateTime } = useUtils();
95
+ const notify = inject<(text: string, color?: string) => void>("inventoryNotify", () => {});
96
+
97
+ const rows = ref<TInventorySerial[]>([]);
98
+ const inStore = ref(0);
99
+ const onHand = ref(0);
100
+ const loading = ref(false);
101
+ const saving = ref(false);
102
+ const search = ref("");
103
+ const entries = ref<string[]>([]);
104
+
105
+ /** Keepers and managers add serial numbers (the API checks too). */
106
+ const canAdd = computed(() => Boolean(props.store.access?.canHandle || props.store.access?.canManage));
107
+ const free = computed(() => Math.max(0, onHand.value - inStore.value));
108
+ const filled = computed(() => entries.value.map((v) => String(v ?? "").trim()).filter(Boolean));
109
+ /** DV-1787: camera scan - fills the empty unit fields in order. */
110
+ const scanning = ref(false);
111
+ const emptySlots = computed(() => entries.value.filter((v) => !String(v ?? "").trim()).length);
112
+ function fillScanned(list: string[]) {
113
+ const queue = [...list];
114
+ entries.value = entries.value.map((v) => (String(v ?? "").trim() || !queue.length ? v : (queue.shift() as string)));
115
+ notify(`${list.length} serial ${list.length === 1 ? "number" : "numbers"} scanned. Check them, then Save.`);
116
+ }
117
+ const shown = computed(() => {
118
+ const q = String(search.value ?? "").trim().toLowerCase();
119
+ return q ? rows.value.filter((r) => r.serial.toLowerCase().includes(q)) : rows.value;
120
+ });
121
+
122
+ const STATUS: Record<string, { text: string; color: string; info: string }> = {
123
+ in_store: { text: "In store", color: "success", info: "On the shelf, ready to issue." },
124
+ out: { text: "Out", color: "info", info: "Issued to the person shown, for the work order shown, until it is returned." },
125
+ written_off: { text: "Written off", color: "grey", info: "Lost, damaged or used up: no longer in stock." },
126
+ used: { text: "Used", color: "grey", info: "Used up on a job: no longer in stock." },
127
+ };
128
+ const EVENT: Record<string, string> = {
129
+ added: "Serial number added",
130
+ issued: "Issued",
131
+ received: "Received",
132
+ return_asked: "Asked to return",
133
+ return_declined: "Return not received",
134
+ returned: "Returned to the store",
135
+ written_off: "Written off",
136
+ used: "Used",
137
+ handed_over: "Handed over",
138
+ closed: "Back in the store",
139
+ };
140
+ function eventText(e: TInventorySerial["history"][number]) {
141
+ const parts = [EVENT[e.type] ?? e.type];
142
+ // Write-off: why - "Written off as damaged" (Used up, Spoilt, Damaged, Lost, Other).
143
+ if (e.reason) parts[0] += ` as ${writeOffLabel(e.reason).toLowerCase()}`;
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}`);
147
+ if (e.workOrderNumber) parts.push(`for ${e.workOrderNumber}`);
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
+ }
153
+ if (e.note) parts.push(`· ${e.note}`);
154
+ return parts.join(" ");
155
+ }
156
+
157
+ async function load() {
158
+ if (!props.item) return;
159
+ loading.value = true;
160
+ try {
161
+ const res = await api.getSerials(props.item._id, "all");
162
+ rows.value = res.items;
163
+ inStore.value = res.inStore;
164
+ onHand.value = res.onHand;
165
+ entries.value = Array.from({ length: Math.min(100, Math.max(0, res.onHand - res.inStore)) }, () => "");
166
+ } catch (error: any) {
167
+ notify(error?.data?.message || "Could not load the serial numbers.", "error");
168
+ } finally {
169
+ loading.value = false;
170
+ }
171
+ }
172
+
173
+ async function save() {
174
+ if (!props.item || !filled.value.length) return;
175
+ saving.value = true;
176
+ try {
177
+ await api.addSerials(props.item._id, filled.value);
178
+ notify(`${filled.value.length} serial ${filled.value.length === 1 ? "number" : "numbers"} added.`);
179
+ await load();
180
+ emit("changed");
181
+ } catch (error: any) {
182
+ notify(error?.data?.message || "Could not add the serial numbers.", "error");
183
+ } finally {
184
+ saving.value = false;
185
+ }
186
+ }
187
+
188
+ watch(show, (open) => {
189
+ if (!open) return;
190
+ search.value = "";
191
+ load();
192
+ });
193
+ </script>
194
+
195
+ <style scoped>
196
+ .serial-event {
197
+ display: flex;
198
+ gap: 12px;
199
+ font-size: 0.8125rem;
200
+ padding: 2px 0;
201
+ }
202
+ </style>
@@ -106,6 +106,16 @@
106
106
  <v-chip v-if="item.status === 'inactive'" size="x-small" variant="tonal" class="ml-2">Not in use</v-chip>
107
107
  <div v-if="item.reserved" class="text-caption text-medium-emphasis">+ {{ item.reserved }} set aside for requests (still on the shelf)</div>
108
108
  <div v-if="item.awaitingReceipt" class="text-caption text-medium-emphasis">{{ item.awaitingReceipt }} handed out, waiting for Received</div>
109
+ <!-- DV-1787: give each unit its own serial number, and see each one's history -->
110
+ <a
111
+ v-if="item.serialsTotal || canSerial"
112
+ href="#"
113
+ class="text-caption text-primary d-flex align-center ga-1"
114
+ @click.prevent.stop="openSerials(item)"
115
+ >
116
+ <v-icon icon="mdi-barcode" size="14" />
117
+ {{ item.serialsTotal ? `Serial numbers (${item.serialsInStore} in store)` : "Serial numbers" }}
118
+ </a>
109
119
  <!-- Acknowledge / PO details are for the people who handle the store; a technician sees only the Low chip. -->
110
120
  <div v-if="item.lowStockAlert && canAckLow" class="text-caption text-error" @click.stop>
111
121
  {{ lowStockAlertText(item.lowStockAlert, standardFormatDate) }}
@@ -127,6 +137,7 @@
127
137
 
128
138
  <InventoryLinesDialog v-model="lines.show" :mode="lines.mode" :store="store" :site-id="siteId" :sites="sites" @done="done" />
129
139
  <InventoryItemDialog v-model="itemDialog.show" :store="store" :item="itemDialog.item" @done="done" />
140
+ <InventorySerialsDialog v-model="serialsDialog.show" :store="store" :item="serialsDialog.item" @changed="done" />
130
141
  <InventoryImportDialog v-model="showImport" :store="store" @done="done" />
131
142
  <InventoryImportDialog v-model="showReceiveImport" :store="store" kind="receipts" @done="done" />
132
143
  <InventoryPoDialog v-model="showPo" :store="store" />
@@ -298,6 +309,12 @@ function open(mode: "receive" | "issue" | "request" | "transfer") {
298
309
  }
299
310
 
300
311
  const itemDialog = reactive({ show: false, item: null as TInventoryItem | null });
312
+ // DV-1787: serial numbers of an item (store keepers / managers add them; everyone sees their history).
313
+ const serialsDialog = reactive({ show: false, item: null as TInventoryItem | null });
314
+ const canSerial = computed(() => Boolean(props.store.access?.canHandle || props.store.access?.canManage));
315
+ function openSerials(item: TInventoryItem) {
316
+ Object.assign(serialsDialog, { show: true, item });
317
+ }
301
318
  function editItem(item: TInventoryItem | null) {
302
319
  detail.show = false;
303
320
  Object.assign(itemDialog, { show: true, item });
@@ -27,6 +27,18 @@
27
27
  style="max-width: 200px"
28
28
  :rules="[(v: any) => (Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= maxQty) || `1 to ${maxQty}`]"
29
29
  />
30
+ <!-- DV-1787: which serial numbers are used up (an item with serials) -->
31
+ <InventorySerialPick
32
+ v-model="serials"
33
+ :item="holding.item"
34
+ source="mine"
35
+ :qty="Number(qty || 0)"
36
+ :units="holding.qty"
37
+ :open="show"
38
+ :initial="draftPicks"
39
+ label="Which serial numbers? (optional)"
40
+ @update:model-value="(v: string[] | null) => (qty = Math.max(Number(qty) || 0, v?.length ?? 0) || null)"
41
+ />
30
42
 
31
43
  <InputLabel title="Where?" required class="mb-1" />
32
44
  <v-btn-toggle v-model="where" mandatory divided variant="outlined" density="comfortable" class="mb-3">
@@ -173,6 +185,9 @@ const stepsLive = computed(() => inventoryStepsLive(props.store));
173
185
  const date = ref(today);
174
186
  const photosBefore = ref<string[]>([]);
175
187
  const photosAfter = ref<string[]>([]);
188
+ const serials = ref<string[]>([]);
189
+ /** A draft's earlier choice of serial numbers. */
190
+ const draftPicks = computed(() => ((props.draft as any)?.serialPicks ?? []).map(String) as string[]);
176
191
  const photoError = ref("");
177
192
  const USAGE_PHOTOS_REQUIRED = "Add a before photo and an after photo to record usage.";
178
193
 
@@ -214,6 +229,8 @@ function body() {
214
229
  photosAfter: photosAfter.value,
215
230
  remarks: remarks.value,
216
231
  reportedBy: reportedBy.value,
232
+ // DV-1787: serials only when chosen, or to clear a draft's earlier choice.
233
+ ...(serials.value.length || draftPicks.value.length ? { serials: serials.value } : {}),
217
234
  // Only to an API that knows it (an older one refuses an unknown field).
218
235
  ...(stepsLive.value && attendedWith.value.trim() ? { attendedWith: attendedWith.value.trim() } : {}),
219
236
  };
@@ -293,6 +310,7 @@ watch(show, (open) => {
293
310
  photoError.value = "";
294
311
  photosBefore.value = [];
295
312
  photosAfter.value = [];
313
+ serials.value = [];
296
314
  qty.value = 1;
297
315
  unit.value = "";
298
316
  area.value = "";