@7365admin1/layer-common 4.97.1-staging.696 → 4.97.1-staging.698

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.
@@ -280,6 +280,24 @@
280
280
  Add Plate
281
281
  </AppButton>
282
282
  </template>
283
+
284
+ <!--
285
+ A blank (pre-printed) QR sticker to link as the vehicle is
286
+ added: the next sticker number is picked already. Optional -
287
+ "No sticker" adds the vehicle alone. With several plates the
288
+ sticker goes on the first plate, as Link QR sticker does per plate.
289
+ -->
290
+ <template v-if="prop.qrLink && qrPickItems.length > 1">
291
+ <InputLabel title="QR sticker" class="mt-2" />
292
+ <v-autocomplete
293
+ v-model="qrPick"
294
+ :items="qrPickItems"
295
+ density="comfortable"
296
+ :hint="newPlateNumbers.filter(Boolean).length > 1 ? 'Linked to the first plate number above.' : 'Type a sticker number to find it.'"
297
+ persistent-hint
298
+ data-test="vehicle-form-qr-sticker"
299
+ />
300
+ </template>
283
301
  </template>
284
302
 
285
303
  <template v-else-if="prop.mode === 'edit'">
@@ -493,6 +511,7 @@
493
511
 
494
512
  <script setup lang="ts">
495
513
  import { errorConverter } from "../utils/data";
514
+ import { blankPickLabel, type BlankPick } from "../utils/vehicle-qr-blank";
496
515
  import { isPermissionRefusalError } from "../utils/permission-refusal";
497
516
  const prop = defineProps({
498
517
  type: {
@@ -543,6 +562,11 @@ const prop = defineProps({
543
562
  * Blocking from a visitor transaction: the visit's block / level / unit,
544
563
  * saved on the Block Listed vehicle and shown read-only.
545
564
  */
565
+ /** Offer a blank QR sticker to link on add (site has Vehicle QR on and the person may link). */
566
+ qrLink: {
567
+ type: Boolean,
568
+ default: false,
569
+ },
546
570
  presetLocation: {
547
571
  type: Object as PropType<{
548
572
  block?: { id: string; name: string };
@@ -561,7 +585,51 @@ const {
561
585
  formatVehicleStatus,
562
586
  checkExistingPlates,
563
587
  moveVehicle,
588
+ getBlankStickersBySerial,
589
+ linkVehicleQr,
564
590
  } = useVehicle();
591
+
592
+ /*
593
+ * Link a blank QR sticker while adding (owner 2026-11-16). The host passes
594
+ * `qrLink` only when the site has Vehicle QR on and this person may link.
595
+ */
596
+ const qrPicks = ref<BlankPick[]>([]);
597
+ const qrPick = ref("");
598
+ const qrPickItems = computed(() => [
599
+ ...qrPicks.value.map((p) => ({ title: blankPickLabel(p), value: p.code })),
600
+ { title: "No sticker", value: "" },
601
+ ]);
602
+ onMounted(async () => {
603
+ if (!prop.qrLink || prop.mode !== "add") return;
604
+ try {
605
+ const res = await getBlankStickersBySerial(prop.site, { limit: 50 });
606
+ qrPicks.value = res.items;
607
+ qrPick.value = res.next?.code ?? "";
608
+ } catch {
609
+ qrPicks.value = []; // ponytail: no list, no picker - the vehicle still adds
610
+ }
611
+ });
612
+
613
+ /** After the add: link the picked sticker to the first new plate. A failure keeps the vehicle and says so. */
614
+ async function linkPickedSticker(plates: string[]): Promise<{ text: string; ok: boolean }> {
615
+ const code = qrPick.value;
616
+ const plate = plates[0];
617
+ if (!code || !plate) return { text: "", ok: true };
618
+ const label = blankPickLabel(qrPicks.value.find((p) => p.code === code) ?? { token: code, code });
619
+ try {
620
+ const found = await checkExistingPlates({ site: prop.site, plateNumbers: [plate] });
621
+ const key = (v: unknown) => String(v ?? "").replace(/[^A-Za-z0-9]/g, "").toUpperCase();
622
+ const id = found?.items?.find((i) => key(i.plateNumber) === key(plate))?._id;
623
+ if (!id) throw new Error("The new vehicle could not be found.");
624
+ await linkVehicleQr(code, String(id));
625
+ return { text: `QR sticker ${label.split(" - ")[0]} linked to ${plate}.`, ok: true };
626
+ } catch (error: any) {
627
+ return {
628
+ text: `Vehicle saved, but the QR sticker was not linked (${errorConverter(error)}). Link it from Link QR sticker on the vehicle.`,
629
+ ok: false,
630
+ };
631
+ }
632
+ }
565
633
  const { getSiteById, getSiteLevels, getSiteUnits } = useSiteSettings();
566
634
  const { findPersonByNRICMultipleResult, getPeopleByUnit } = usePeople();
567
635
  const { getBlocksSelection, getLevelsSelection, getUnitSelection } =
@@ -1154,13 +1222,17 @@ async function confirmExistingUpdate() {
1154
1222
  }
1155
1223
 
1156
1224
  const remaining = newPlatesAfterExisting.value;
1225
+ let linkOk = true;
1157
1226
  if (remaining.length) {
1158
1227
  const res: any = await addVehicle({ ...payload, plateNumber: remaining });
1159
1228
  messages.push(res?.data || res?.message || "Vehicle added successfully.");
1229
+ const linked = await linkPickedSticker(remaining);
1230
+ if (linked.text) messages.push(linked.text);
1231
+ linkOk = linked.ok;
1160
1232
  }
1161
1233
 
1162
1234
  showExistingDialog.value = false;
1163
- showMessage(messages.join(" ") || "Vehicle updated.", "success");
1235
+ showMessage(messages.join(" ") || "Vehicle updated.", linkOk ? "success" : "warning");
1164
1236
  emit("done");
1165
1237
  } catch (error: any) {
1166
1238
  // Shown under the form. A record moved before the failure stays moved.
@@ -1310,7 +1382,9 @@ async function submit() {
1310
1382
  }
1311
1383
 
1312
1384
  const res: any = await addVehicle(payload);
1313
- showMessage(res?.data || res?.message || "Vehicle added successfully.", "success");
1385
+ const added = res?.data || res?.message || "Vehicle added successfully.";
1386
+ const linked = await linkPickedSticker(plates);
1387
+ showMessage([added, linked.text].filter(Boolean).join(" "), linked.ok ? "success" : "warning");
1314
1388
  } else if (prop.mode === "edit") {
1315
1389
  const plateNumberId = prop.plateNumberId as string;
1316
1390
  const res: any = await updateVehicle(plateNumberId, payload);
@@ -161,6 +161,7 @@
161
161
  <v-dialog v-model="dialog.createVehicle" v-if="vehicleType" width="450" persistent>
162
162
  <VehicleForm :type="vehicleType" :mode="mode" :vehicle-data="selectedVehicleObject"
163
163
  :plate-number-id="selectedPlateNumberId" :name-hints="nameHints" @back="handleBackToSelection" @done="handleAddVehicleComplete"
164
+ :qr-link="qrActionsOn({ type: vehicleType })"
164
165
  :org="org" :site="props.site" @close:all="handleCloseAll" @refused="handleFormRefused" />
165
166
  </v-dialog>
166
167
 
@@ -429,10 +430,10 @@
429
430
  <v-card data-test="vehicle-qr-link-dialog">
430
431
  <v-card-title>Link QR sticker</v-card-title>
431
432
  <v-card-text>
432
- Pick an available sticker code, scan the sticker, or type the code printed on it. It will show
433
- {{ qrPlate?.plateNumber }} when scanned.
434
- <v-combobox v-model="qrLinkCode" v-model:search="qrSearch" :items="qrCodes" no-filter clearable label="Sticker code"
435
- placeholder="Pick or type ABCD-EFGH-JKMN-PQRS-TVWX-YZ01" density="compact" variant="outlined" class="mt-3"
433
+ Pick an available sticker (next number first) or type its sticker number, scan the sticker, or type the code
434
+ printed on it. It will show {{ qrPlate?.plateNumber }} when scanned.
435
+ <v-combobox v-model="qrLinkCode" v-model:search="qrSearch" :items="qrCodes" no-filter clearable label="Sticker"
436
+ placeholder="Pick, or type TLR002 / ABCD-EFGH-JKMN-PQRS-TVWX-YZ01" density="compact" variant="outlined" class="mt-3"
436
437
  :disabled="qrBusy" :hint="qrLinkHint" persistent-hint hide-no-data data-test="vehicle-qr-link-code"
437
438
  @keyup.enter="confirmLink(false)" />
438
439
  <p v-if="qrSummary" class="text-caption mt-2" data-test="vehicle-qr-link-summary">{{ blankSummaryText(qrSummary) }}</p>
@@ -489,7 +490,7 @@ import {
489
490
  // `error.message` put ofetch's own developer string in the delete dialog:
490
491
  // `[PUT] "/api/vehicles/6a9691f25648d7633171c9e3": 502`.
491
492
  import { errorConverter } from '../utils/data';
492
- import { BLANK_LIST_NOTE, UNDO_REISSUE_NOTE, blankSummaryText, qrStickerNumbers, qrStickerSummary, stickerCodeHint, type BlankSummary } from '../utils/vehicle-qr-blank';
493
+ import { BLANK_LIST_NOTE, UNDO_REISSUE_NOTE, blankPickLabel, blankSummaryText, pickedStickerCode, qrStickerNumbers, qrStickerSummary, stickerCodeHint, type BlankPick, type BlankSummary } from '../utils/vehicle-qr-blank';
493
494
  import { isPermissionRefusalError } from '../utils/permission-refusal';
494
495
 
495
496
 
@@ -606,7 +607,7 @@ const canAddBlocklist = computed(() => props.canManageBlocklist === true);
606
607
 
607
608
 
608
609
  const { formatCamelCaseToWords, formatDate, debounce, maskNRIC } = useUtils();
609
- const { getVehicles, deleteVehicle, formatVehicleStatus, approveVehicle, blockVehicle, unblockVehicle, getSpecificVehicleById, getActiveCameraCounts, getVehicleQrSettings, regenerateVehicleQr, undoReissueVehicleQr, linkVehicleQr, unlinkVehicleQr, getAvailableBlankVehicleQr } = useVehicle();
610
+ const { getVehicles, deleteVehicle, formatVehicleStatus, approveVehicle, blockVehicle, unblockVehicle, getSpecificVehicleById, getActiveCameraCounts, getVehicleQrSettings, regenerateVehicleQr, undoReissueVehicleQr, linkVehicleQr, unlinkVehicleQr, getBlankStickersBySerial } = useVehicle();
610
611
 
611
612
  // Vehicle QR stickers: the site's switch (Settings) decides whether the print
612
613
  // and re-issue actions exist; only people who may update vehicles get them.
@@ -672,26 +673,31 @@ const qrError = ref("");
672
673
  const qrLinkHint = computed(() => (qrCodeToLink.value ? stickerCodeHint(qrCodeToLink.value) : ""));
673
674
  // the combobox keeps a typed-but-not-committed code in its search text
674
675
  const qrSearch = ref("");
675
- const qrCodes = ref<string[]>([]);
676
+ // the pick-list's stickers ("TLR002 - ABCD-..."), by sticker number with the next one first
677
+ const qrPicks = ref<BlankPick[]>([]);
678
+ const qrCodes = computed(() => qrPicks.value.map(blankPickLabel));
676
679
  const qrSummary = ref<BlankSummary | null>(null);
677
- const qrCodeToLink = computed(() => String(qrLinkCode.value || qrSearch.value || "").trim());
680
+ // a picked line or a typed sticker number becomes that sticker's code; a typed code is sent as is
681
+ const qrCodeToLink = computed(() => pickedStickerCode(qrLinkCode.value || qrSearch.value, qrPicks.value));
678
682
 
679
683
  // Saved blank codes still free to link + the site's printed / linked / available count.
680
684
  async function loadQrAvailable(search = "") {
681
685
  // The Link dialog lists the blanks for whoever may link this plate.
682
686
  if (!qrStickersOn.value && !(dialog.qrLink && qrActionsOn(qrPlate.value))) return;
683
687
  try {
684
- const res = await getAvailableBlankVehicleQr(props.site, { search, limit: 50 });
685
- qrSummary.value = res?.summary ?? null;
686
- qrCodes.value = (res?.items ?? []).map((i) => i.code);
688
+ const res = await getBlankStickersBySerial(props.site, { search, limit: 50 });
689
+ qrSummary.value = res.summary;
690
+ qrPicks.value = res.items;
687
691
  } catch {
688
692
  qrSummary.value = null;
689
- qrCodes.value = [];
693
+ qrPicks.value = [];
690
694
  }
691
695
  }
692
696
  let qrSearchTimer: ReturnType<typeof setTimeout> | undefined;
693
697
  watch(qrSearch, (v) => {
694
698
  clearTimeout(qrSearchTimer);
699
+ // picking a line puts its label in the search text - that is not a search
700
+ if (qrCodes.value.includes(String(v ?? ""))) return;
695
701
  if (dialog.qrLink) qrSearchTimer = setTimeout(() => loadQrAvailable(String(v ?? "")), 250);
696
702
  });
697
703
  watch(qrStickersOn, (on) => on && loadQrAvailable());
@@ -98,7 +98,7 @@
98
98
  @update:model-value="(v: any) => (ticked = setIds(ticked, [it.vehicleId], !!v))" /></td>
99
99
  <template v-if="isBlank">
100
100
  <td class="font-weight-bold">{{ blankRowLabel(it) }}</td>
101
- <td class="text-medium-emphasis">{{ BLANK_STRIP_NOTE }}</td>
101
+ <td class="text-medium-emphasis">{{ blankStripNote(it, design) }}</td>
102
102
  </template>
103
103
  <template v-else>
104
104
  <td>{{ installerLine(it).place || "-" }}</td>
@@ -117,10 +117,19 @@
117
117
  </v-table>
118
118
  <v-alert v-if="isBlank && design.shape !== 'square' && design.text === 'none'" type="warning" variant="tonal"
119
119
  density="compact" class="my-2" data-test="vehicle-qr-blank-notext">
120
- With "No text" the sticker's code is not printed on it, so these stickers can only be linked by scanning them with
121
- iMA365 / iSecure365 - Vehicles &gt; Link QR sticker needs the printed code. Pick another Text option to print it.
120
+ With "No text" nothing is printed under the shape - neither the sticker's code nor its number - so these stickers
121
+ can only be linked by scanning them with iMA365 / iSecure365. Pick another Text option to print it.
122
122
  </v-alert>
123
- <p v-if="isBlank" class="text-caption text-medium-emphasis my-2">
123
+ <v-alert v-if="isBlank && design.blankCode === 'hide' && blankWithoutNumber" type="info" variant="tonal"
124
+ density="compact" class="my-2" data-test="vehicle-qr-blank-code-kept">
125
+ {{ blankWithoutNumber }} sticker(s) have no sticker number, so their long code is still printed on them.
126
+ </v-alert>
127
+ <p v-if="isBlank && design.blankCode === 'hide'" class="text-caption text-medium-emphasis my-2">
128
+ Each sticker has a cut-off strip under the dashed line saying it is not linked yet - cut it off before pasting
129
+ the sticker on the car. To link one, pick its sticker number in Vehicles &gt; Link QR sticker, or scan it with
130
+ iMA365 / iSecure365.
131
+ </p>
132
+ <p v-else-if="isBlank" class="text-caption text-medium-emphasis my-2">
124
133
  Each sticker has a cut-off strip under the dashed line saying it is not linked yet - cut it off before pasting
125
134
  the sticker on the car. The code on the sticker is what you type in Vehicles &gt; Link QR sticker.
126
135
  </p>
@@ -178,6 +187,10 @@
178
187
  <v-select v-model="design.serial" :items="SERIAL_OPTIONS" label="Serial number" density="compact"
179
188
  hide-details data-test="vehicle-qr-serial" />
180
189
  </v-col>
190
+ <v-col v-if="isBlank" cols="12" sm="6" md="4">
191
+ <v-select v-model="design.blankCode" :items="BLANK_CODE_OPTIONS" label="Sticker code (long code)"
192
+ density="compact" hide-details data-test="vehicle-qr-blank-code" />
193
+ </v-col>
181
194
  <v-col v-if="!isBlank" cols="12" sm="6" md="4">
182
195
  <v-select v-model="design.plate" :items="PLATE_OPTIONS" label="Plate number on the sticker" density="compact"
183
196
  hide-details data-test="vehicle-qr-plate" />
@@ -260,7 +273,7 @@
260
273
  <script lang="ts" setup>
261
274
  import QRCode from "qrcode";
262
275
  import useVehicle from "../composables/useVehicle";
263
- import { BLANK_DEFAULT_COUNT, BLANK_LIST_NOTE, BLANK_MAX_COUNT, BLANK_STRIP_NOTE, SAVED_REPRINT_MAX, blankRowLabel, savedBlankItems, STICKER_NEW_NOTE, STICKER_SAME_NOTE, blankCount, blankStickerItems, blankSummaryText, reprintItems, type BlankSummary } from "../utils/vehicle-qr-blank";
276
+ import { BLANK_DEFAULT_COUNT, BLANK_LIST_NOTE, BLANK_MAX_COUNT, SAVED_REPRINT_MAX, blankRowLabel, savedBlankItems, STICKER_NEW_NOTE, STICKER_SAME_NOTE, blankCount, blankStickerItems, blankSummaryText, reprintItems, type BlankSummary } from "../utils/vehicle-qr-blank";
264
277
  import { errorConverter } from "../utils/data";
265
278
  import { saveFile, stickerBundleName, stickerFileNames, svgToImage, zipFiles, type ImageFormat } from "../utils/vehicle-qr-export";
266
279
  import {
@@ -277,11 +290,14 @@ import {
277
290
  stickerSizeLines,
278
291
  stickerCardSvgs,
279
292
  stickerFileLabel,
293
+ stickerSerial,
280
294
  stickerWarning,
295
+ blankStripNote,
281
296
  type StickerItem,
282
297
  type StickerPlateRow,
283
298
  } from "../utils/vehicle-qr-sticker";
284
299
  import {
300
+ BLANK_CODE_OPTIONS,
285
301
  DEFAULT_STICKER_DESIGN,
286
302
  DOT_OPTIONS,
287
303
  EYE_OPTIONS,
@@ -337,6 +353,8 @@ const step = ref<"select" | "review">("select");
337
353
  const plates = ref<StickerPlateRow[]>([]);
338
354
  const selected = ref<string[]>([]);
339
355
  const items = ref<StickerItem[]>([]);
356
+ // "Sticker code: Hide" keeps the code on a blank that has no number (never neither).
357
+ const blankWithoutNumber = computed(() => items.value.filter((i) => i.blank && !stickerSerial(i)).length);
340
358
  const ticked = ref<string[]>([]);
341
359
  const missing = ref<string[]>([]);
342
360
  const dropped = ref(0);
@@ -1,3 +1,5 @@
1
+ import { orderedBlankPicks, type BlankPick } from "../utils/vehicle-qr-blank";
2
+
1
3
  export default function useVehicle() {
2
4
  async function getVehicles({
3
5
  search = "",
@@ -330,17 +332,35 @@ function getSpecificVehicleById(id: string){
330
332
 
331
333
  // Blank codes saved when printed and still free to link, plus {printed, linked, available}.
332
334
  // `search` matches the code or the sticker number; `qr` lets a saved sticker be printed again.
333
- function getAvailableBlankVehicleQr(site: string, query: { search?: string; page?: number; limit?: number } = {}) {
335
+ function getAvailableBlankVehicleQr(site: string, query: { search?: string; page?: number; limit?: number; sort?: "serial" } = {}) {
334
336
  return useNuxtApp().$api<{
335
337
  site?: { _id: string; name: string };
336
338
  summary: { printed: number; linked: number; available: number };
337
339
  total: number;
338
340
  page: number;
339
341
  limit: number;
340
- items: Array<{ token: string; code: string; qr?: string; serialNo?: number | null; serialLabel?: string | null }>;
342
+ items: BlankPick[];
343
+ /** With `sort=serial`: the first available sticker (lowest number). */
344
+ next?: BlankPick | null;
341
345
  }>(`/api/vehicles/qr/blank-stickers/site/${site}`, { query });
342
346
  }
343
347
 
348
+ /**
349
+ * Blank stickers for a pick-list: by sticker number, the NEXT one first.
350
+ * Asks for `sort=serial`; a server without it yet refuses the unknown field
351
+ * (400), so the list is asked again without it and sorted here.
352
+ */
353
+ async function getBlankStickersBySerial(site: string, query: { search?: string; limit?: number } = {}) {
354
+ let res: Awaited<ReturnType<typeof getAvailableBlankVehicleQr>>;
355
+ try {
356
+ res = await getAvailableBlankVehicleQr(site, { ...query, sort: "serial" });
357
+ } catch (e: any) {
358
+ if ((e?.statusCode ?? e?.status ?? e?.response?.status) !== 400) throw e;
359
+ res = await getAvailableBlankVehicleQr(site, query);
360
+ }
361
+ return { summary: res?.summary ?? null, ...orderedBlankPicks(res) };
362
+ }
363
+
344
364
  // `token` is sent as typed - the server ignores case, spaces and dashes.
345
365
  function linkVehicleQr(token: string, vehicleId: string, replace?: boolean) {
346
366
  return useNuxtApp().$api<Record<string, any>>("/api/vehicles/qr/link", {
@@ -381,6 +401,7 @@ function getSpecificVehicleById(id: string){
381
401
  undoReissueVehicleQr,
382
402
  getBlankVehicleQrStickers,
383
403
  getAvailableBlankVehicleQr,
404
+ getBlankStickersBySerial,
384
405
  linkVehicleQr,
385
406
  unlinkVehicleQr,
386
407
  };
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.696",
5
+ "version": "4.97.1-staging.698",
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.",
@@ -148,3 +148,63 @@ export function blankSummaryText(s: Partial<BlankSummary> | null | undefined): s
148
148
 
149
149
  /** Shown beside the pick-list: stickers printed before the list existed were never saved. */
150
150
  export const BLANK_LIST_NOTE = "Stickers printed before 9 Oct 2026 are not in this list - scan them or type their code.";
151
+
152
+ /** The strip under a blank sticker printed WITHOUT its long code: link it by its number, never "type the code". */
153
+ export const BLANK_STRIP_NOTE_NUMBER = "Not linked yet - link it by its sticker number in Vehicles > Link QR sticker, or scan it with iMA365 / iSecure365";
154
+
155
+ /** One saved blank sticker in a pick-list (GET /api/vehicles/qr/blank-stickers/site/:site). */
156
+ export type BlankPick = { token: string; code: string; qr?: string; serialNo?: number | null; serialLabel?: string | null };
157
+
158
+ const serialOf = (i: Pick<BlankPick, "serialNo">) => {
159
+ const n = Number(i?.serialNo);
160
+ return Number.isInteger(n) && n > 0 ? n : 0;
161
+ };
162
+
163
+ /** The number a pick-list shows: "TLR002", "No. 2", or "" when the sticker has none. */
164
+ export function blankPickSerial(i: Pick<BlankPick, "serialNo" | "serialLabel">): string {
165
+ const n = serialOf(i);
166
+ return n ? String(i.serialLabel ?? "").trim() || `No. ${n}` : "";
167
+ }
168
+
169
+ /** "TLR002 - ABCD-EFGH-..." - or just the code for a sticker with no number. */
170
+ export function blankPickLabel(i: BlankPick): string {
171
+ const sn = blankPickSerial(i);
172
+ return sn ? `${sn} - ${i.code}` : i.code;
173
+ }
174
+
175
+ /** Ascending by sticker number; stickers with no number last, in the order they came. */
176
+ export function sortBlankBySerial<T extends Pick<BlankPick, "serialNo">>(items: T[]): T[] {
177
+ return items
178
+ .map((item, at) => ({ item, at, n: serialOf(item) }))
179
+ .sort((a, b) => (a.n && b.n ? a.n - b.n : a.n ? -1 : b.n ? 1 : 0) || a.at - b.at)
180
+ .map((x) => x.item);
181
+ }
182
+
183
+ /**
184
+ * The pick-list in sticker-number order with the NEXT sticker on top. A server
185
+ * that took `sort=serial` sends its order and `next`; an older one sends
186
+ * neither, so the list is sorted here and the lowest number is next.
187
+ */
188
+ export function orderedBlankPicks<T extends BlankPick>(res: { items?: T[] | null; next?: T | null } | null | undefined): { items: T[]; next: T | null } {
189
+ const raw = Array.isArray(res?.items) ? res!.items! : [];
190
+ const items = res?.next ? [...raw] : sortBlankBySerial(raw);
191
+ const next = res?.next ?? items[0] ?? null;
192
+ if (!next) return { items, next: null };
193
+ return { items: [next, ...items.filter((i) => i.token !== next.token)], next };
194
+ }
195
+
196
+ /**
197
+ * What a pick-list's text means as a code to link: a picked "TLR002 - ABCD-..."
198
+ * line, a sticker number typed on its own ("tlr002"), or a typed / scanned code
199
+ * (sent as is - the server reads it).
200
+ */
201
+ export function pickedStickerCode(text: unknown, items: BlankPick[] = []): string {
202
+ const t = String(text ?? "").trim();
203
+ if (!t) return "";
204
+ const byLabel = items.find((i) => blankPickLabel(i) === t);
205
+ if (byLabel) return byLabel.code;
206
+ const bySerial = items.find((i) => blankPickSerial(i) && blankPickSerial(i).toUpperCase() === t.toUpperCase());
207
+ if (bySerial) return bySerial.code;
208
+ const at = t.lastIndexOf(" - ");
209
+ return at >= 0 ? t.slice(at + 3).trim() : t;
210
+ }
@@ -48,8 +48,10 @@ export type LabelChoice = "app" | "verify" | "scanme" | "site" | "none";
48
48
  export type TextChoice = "below" | "none";
49
49
  /** Where the sticker's running number ("No. 12") is printed: not at all, on the sticker, on the cut-off strip, or both. */
50
50
  export type SerialChoice = "off" | "sticker" | "strip" | "both";
51
- /** The vehicle's plate number on the print-out: shown, or left off (a blank sticker's code is always printed). */
51
+ /** The vehicle's plate number on the print-out: shown, or left off (a blank sticker's code is set by `blankCode`). */
52
52
  export type PlateChoice = "show" | "hide";
53
+ /** Blank stickers: print the long 24-character code, or leave it off and print the sticker number in its place (one with no number keeps its code). */
54
+ export type BlankCodeChoice = "print" | "hide";
53
55
 
54
56
  export type StickerTheme = { id: string; title: string; ink: string; eye: string; paper: string };
55
57
 
@@ -68,6 +70,7 @@ export type StickerDesign = {
68
70
  cutLines?: boolean;
69
71
  serial?: SerialChoice;
70
72
  plate?: PlateChoice;
73
+ blankCode?: BlankCodeChoice;
71
74
  };
72
75
 
73
76
  export const DOT_OPTIONS: { value: DotShape; title: string }[] = [
@@ -154,6 +157,11 @@ export const PLATE_OPTIONS: { value: PlateChoice; title: string }[] = [
154
157
  { value: "hide", title: "Hide - QR and serial number only" },
155
158
  ];
156
159
 
160
+ export const BLANK_CODE_OPTIONS: { value: BlankCodeChoice; title: string }[] = [
161
+ { value: "print", title: "Print (default)" },
162
+ { value: "hide", title: "Hide - QR code and sticker number only" },
163
+ ];
164
+
157
165
  export const LABEL_OPTIONS: { value: LabelChoice; title: string }[] = [
158
166
  { value: "app", title: "Scan with iSecure365 / iMA365" },
159
167
  { value: "verify", title: "Scan to verify vehicle" },
@@ -185,6 +193,7 @@ export const DEFAULT_STICKER_DESIGN: StickerDesign = {
185
193
  cutLines: true,
186
194
  serial: "sticker",
187
195
  plate: "show",
196
+ blankCode: "print",
188
197
  };
189
198
 
190
199
  /** A saved or typed-in design with anything unknown replaced by the default. */
@@ -209,6 +218,7 @@ export function normalizeDesign(raw: unknown): StickerDesign {
209
218
  cutLines: typeof r.cutLines === "boolean" ? r.cutLines : true,
210
219
  serial: pick(r.serial, SERIAL_OPTIONS, d.serial),
211
220
  plate: pick(r.plate, PLATE_OPTIONS, d.plate!),
221
+ blankCode: pick(r.blankCode, BLANK_CODE_OPTIONS, d.blankCode!),
212
222
  };
213
223
  }
214
224
 
@@ -226,7 +236,7 @@ export function rememberedDesign(saved: unknown, savedSerial: unknown): StickerD
226
236
  * The design as printed. With the plate hidden on vehicle stickers, a shaped
227
237
  * code whose tab under the shape would be left empty (no serial or words on
228
238
  * it) is printed with no tab, so no bare paper tab hangs under the shape.
229
- * Blank stickers always print their code in the tab, so they keep it.
239
+ * Blank stickers always print their code or sticker number in the tab, so they keep it.
230
240
  */
231
241
  export function printedDesign(design: unknown, blank = false, siteName = ""): StickerDesign {
232
242
  const d = normalizeDesign(design);
@@ -18,7 +18,7 @@ import {
18
18
  stickerTheme,
19
19
  type StickerDesign,
20
20
  } from "./vehicle-qr-design.ts";
21
- import { BLANK_STRIP_NOTE, isBlankCode, plateLines } from "./vehicle-qr-blank.ts";
21
+ import { BLANK_STRIP_NOTE, BLANK_STRIP_NOTE_NUMBER, isBlankCode, plateLines } from "./vehicle-qr-blank.ts";
22
22
 
23
23
  /** The server's most vehicles per request (POST /api/vehicles/qr/stickers). */
24
24
  export const STICKER_MAX_PER_REQUEST = 500;
@@ -208,12 +208,27 @@ export function stickerSerial(item: Pick<StickerItem, "serialNo" | "serialLabel"
208
208
  return text(item?.serialLabel) || `No. ${n}`;
209
209
  }
210
210
 
211
- /** What a saved picture is named after: the plate - or, with the plate hidden, the sticker's number (the file name must not give the plate away either). */
212
- export function stickerFileLabel(item: StickerItem, design: Pick<StickerDesign, "plate">): string {
211
+ /**
212
+ * A blank sticker printed with its sticker number in place of the long code
213
+ * (design "Sticker code: Hide"). Only when it HAS a number - a sticker never
214
+ * goes out with neither the code nor a number on it.
215
+ */
216
+ export function blankCodeHidden(item: Pick<StickerItem, "blank" | "serialNo" | "serialLabel">, design: Pick<StickerDesign, "blankCode">): boolean {
217
+ return !!item.blank && design.blankCode === "hide" && !!stickerSerial(item);
218
+ }
219
+
220
+ /** The strip under a blank sticker: link by number when the code is not on it. */
221
+ export function blankStripNote(item: Pick<StickerItem, "blank" | "serialNo" | "serialLabel">, design: Pick<StickerDesign, "blankCode">): string {
222
+ return blankCodeHidden(item, design) ? BLANK_STRIP_NOTE_NUMBER : BLANK_STRIP_NOTE;
223
+ }
224
+
225
+ /** What a saved picture is named after: the plate - or, with the plate (or a blank's code) hidden, the sticker's number (the file name must not give the plate away either). */
226
+ export function stickerFileLabel(item: StickerItem, design: Pick<StickerDesign, "plate" | "blankCode">): string {
227
+ if (blankCodeHidden(item, design)) return stickerSerial(item);
213
228
  return shownPlateLines(item, design.plate === "hide").length ? text(item.plateNumber) : stickerSerial(item) || "sticker";
214
229
  }
215
230
 
216
- /** The plate lines printed on a sticker: none when the plate is hidden - but a blank sticker's code is always printed (it is typed to link it). */
231
+ /** The plate lines printed on a sticker: none when the plate is hidden - a blank sticker's code is printed unless `blankCodeHidden` (see `headLines`). */
217
232
  function shownPlateLines(item: StickerItem, hidePlate: boolean): string[] {
218
233
  const plate = text(item.plateNumber);
219
234
  return hidePlate && !item.blank && !isBlankCode(plate) ? [] : plateLines(plate);
@@ -222,9 +237,12 @@ function shownPlateLines(item: StickerItem, hidePlate: boolean): string[] {
222
237
  /**
223
238
  * The big line(s) on the sticker and the small serial under them. With the
224
239
  * plate hidden, the serial (when it is on the sticker) moves up into the
225
- * plate's place, so the sticker keeps its usual look with no hole in it.
240
+ * plate's place, so the sticker keeps its usual look with no hole in it. A
241
+ * blank sticker with its code hidden prints its number there whatever the
242
+ * serial choice - the number is how it is linked.
226
243
  */
227
244
  function headLines(item: StickerItem, c: CardContext): { lines: string[]; serialText: string } {
245
+ if (blankCodeHidden(item, c)) return { lines: [stickerSerial(item)], serialText: "" };
228
246
  const lines = shownPlateLines(item, c.hidePlate);
229
247
  const serialText = c.serial ? stickerSerial(item) : "";
230
248
  return lines.length || !serialText ? { lines, serialText } : { lines: [serialText], serialText: "" };
@@ -391,12 +409,24 @@ function plateSizeMm(plate: string, boxW: number, max = 4.6): number {
391
409
  return Math.round(Math.min(max, (boxW / Math.max(plate.length, 1) - 0.3) / 0.74) * 100) / 100;
392
410
  }
393
411
 
412
+ /**
413
+ * Plate size inside a shape's tag. With the serial printed under it (a blank
414
+ * sticker's two-line code + its number), the plate shrinks so both fit the tag:
415
+ * lines at 1.1 x size, the serial row 1.2 x 5.8 pt, 0.6 mm between.
416
+ */
417
+ export function tagPlateSizeMm(longest: string, tag: { w: number; h: number }, lines: number, withSerial: boolean, k = 1): number {
418
+ const size = plateSizeMm(longest, tag.w, 4.6 * k);
419
+ if (!withSerial || !lines) return size;
420
+ const room = (tag.h - 1.2 * 5.8 * PT - 0.6) / (1.1 * lines);
421
+ return Math.round(Math.max(0.5, Math.min(size, room)) * 100) / 100;
422
+ }
423
+
394
424
  /**
395
425
  * One full HTML document: A4 sheets of stickers. `faceSvgs` is parallel to
396
426
  * `items` (each sticker's frame + QR, already drawn for the chosen design).
397
427
  * Every value is HTML-escaped - an owner or site name is typed by a person.
398
428
  */
399
- type CardContext = { cardW: number; ink: string; label: string; layout: SheetLayout; k: number; shaped: boolean; bare: boolean; wordsTop: number; tag: { x: number; y: number; w: number; h: number } | null; serial: boolean; hidePlate: boolean };
429
+ type CardContext = { blankCode?: StickerDesign["blankCode"]; cardW: number; ink: string; label: string; layout: SheetLayout; k: number; shaped: boolean; bare: boolean; wordsTop: number; tag: { x: number; y: number; w: number; h: number } | null; serial: boolean; hidePlate: boolean };
400
430
 
401
431
  function cardContext(design: StickerDesign, siteName: string | undefined, n: number): CardContext {
402
432
  const g = stickerGeometry(design, n);
@@ -415,6 +445,7 @@ function cardContext(design: StickerDesign, siteName: string | undefined, n: num
415
445
  tag: g.band ? { x: mm(g.band.x * k), y: mm(g.band.y * k), w: mm(g.band.w * k), h: mm(g.band.h * k) } : null,
416
446
  serial: serialOnSticker(design),
417
447
  hidePlate: design.plate === "hide",
448
+ blankCode: design.blankCode,
418
449
  };
419
450
  }
420
451
 
@@ -425,18 +456,18 @@ function cardHtml(item: StickerItem, face: string, c: CardContext): string {
425
456
  const longest = lines.reduce((a, l) => (l.length > a.length ? l : a), "");
426
457
  // a two-line code has no room for the words under it inside the tag
427
458
  const label = c.label && !(c.tag && lines.length > 1) ? `<div class="hint">${escapeHtml(c.label)}</div>` : "";
428
- // the serial takes the words' place inside a shape's tag (no room for both)
459
+ // the serial takes the words' place inside a shape's tag; a two-line blank code shrinks to make room for it
429
460
  const serial = serialText ? `<div class="serial">${escapeHtml(serialText)}</div>` : "";
430
- const tagWords = serial && c.tag ? (lines.length > 1 ? "" : serial) : label;
461
+ const tagWords = serial && c.tag ? serial : label;
431
462
  const words = c.shaped && !c.tag
432
463
  ? ""
433
464
  : c.tag
434
465
  ? `<div class="words band" style="left:${c.tag.x}mm;right:auto;top:${c.tag.y}mm;width:${c.tag.w}mm;height:${c.tag.h}mm">` +
435
- (lines.length ? `<div class="plate" style="font-size:${plateSizeMm(longest, c.tag.w, 4.6 * c.k)}mm">${plate}</div>` : "") +
466
+ (lines.length ? `<div class="plate" style="font-size:${tagPlateSizeMm(longest, c.tag, lines.length, !!serial && lines.length > 1, c.k)}mm">${plate}</div>` : "") +
436
467
  tagWords +
437
468
  `</div>`
438
469
  : `<div class="words" style="top:${c.wordsTop}mm${!lines.length && !label ? ";justify-content:center" : ""}">` +
439
- (lines.length ? `<div class="plate"${lines.length > 1 ? ` style="font-size:${plateSizeMm(longest, c.cardW - 6, 4.6)}mm"` : ""}>${plate}</div>` : "") +
470
+ (lines.length ? `<div class="plate"${lines.length > 1 || blankCodeHidden(item, c) ? ` style="font-size:${plateSizeMm(longest, c.cardW - 6, 4.6)}mm"` : ""}>${plate}</div>` : "") +
440
471
  serial +
441
472
  label +
442
473
  `<div class="brand"><span class="mark" style="background:${c.ink}">7</span>Powered by Seven365</div>` +
@@ -457,13 +488,12 @@ export function buildStickerDocument(
457
488
  const design = opts.design ?? DEFAULT_STICKER_DESIGN;
458
489
  const n = opts.modules ?? STICKER_QR_MODULES;
459
490
  const c = cardContext(design, opts.siteName, n);
460
- // the strip carries the number when chosen - and when the sticker has no room for it
461
- // (a bare shape, or a two-line blank code filling a shape's tag)
462
- const noRoom = (item: StickerItem) => (c.shaped && !c.tag) || (!!c.tag && shownPlateLines(item, c.hidePlate).length > 1);
491
+ // the strip carries the number when chosen - and when the sticker has no words at all (a bare shape)
492
+ const noRoom = (_item: StickerItem) => c.shaped && !c.tag;
463
493
  const stripSerial = (item: StickerItem) => design.serial === "strip" || design.serial === "both" || (c.serial && noRoom(item));
464
494
  const cells = items.map((item, i) => {
465
495
  const { place, owner } = installerLine(item);
466
- const [noteHead, noteRest] = BLANK_STRIP_NOTE.split(" - ");
496
+ const [noteHead, noteRest] = blankStripNote(item, design).split(" - ");
467
497
  const sn = stripSerial(item) ? `<span class="sn">${escapeHtml(stickerSerial(item))}</span>` : "";
468
498
  const strip = item.blank
469
499
  ? `<div class="cut${c.bare ? " free" : ""} blank"><div>${sn}<b>${escapeHtml(noteHead)}</b></div><div>${escapeHtml(noteRest)}</div></div>`
@@ -500,8 +530,8 @@ function cardWordsSvg(item: StickerItem, c: CardContext): string {
500
530
  const longest = lines.reduce((a, l) => (l.length > a.length ? l : a), "");
501
531
  const box = c.tag ?? { x: 3, y: c.wordsTop, w: c.cardW - 6, h: c.layout.cardH - 2 - c.wordsTop };
502
532
  const plateSize = c.tag
503
- ? plateSizeMm(longest, c.tag.w, 4.6 * c.k)
504
- : lines.length > 1 ? plateSizeMm(longest, c.cardW - 6, 4.6) : 13 * PT;
533
+ ? tagPlateSizeMm(longest, c.tag, lines.length, !!serialText && lines.length > 1, c.k)
534
+ : lines.length > 1 || blankCodeHidden(item, c) ? plateSizeMm(longest, c.cardW - 6, 4.6) : 13 * PT;
505
535
  const small = 5.8 * PT;
506
536
  type Row = { h: number; draw: (top: number) => string };
507
537
  const rows: Row[] = [];
@@ -519,7 +549,7 @@ function cardWordsSvg(item: StickerItem, c: CardContext): string {
519
549
  });
520
550
  const label = c.label && !(c.tag && lines.length > 1) ? c.label : "";
521
551
  if (c.tag) {
522
- if (serialText && lines.length === 1) rows.push(word(serialText, true));
552
+ if (serialText) rows.push(word(serialText, true));
523
553
  else if (!serialText && label) rows.push(word(label, false));
524
554
  } else {
525
555
  if (serialText) rows.push(word(serialText, true));