@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.
@@ -59,6 +59,8 @@
59
59
  density="comfortable"
60
60
  :rules="[requiredRule]"
61
61
  no-filter
62
+ clearable
63
+ persistent-clear
62
64
  hint="Everyone at this property who can take stock: your staff and the service providers' people."
63
65
  persistent-hint
64
66
  @update:search="searchPeople"
@@ -122,6 +124,8 @@
122
124
  placeholder="Type to search"
123
125
  density="comfortable"
124
126
  :rules="[requiredRule]"
127
+ clearable
128
+ persistent-clear
125
129
  class="flex-grow-1"
126
130
  style="min-width: 220px"
127
131
  @update:search="(q: string) => typedSearch(line, q)"
@@ -148,10 +152,33 @@
148
152
  min="1"
149
153
  label="Qty"
150
154
  density="comfortable"
151
- style="max-width: 110px"
152
- :rules="[qtyRule(line)]"
155
+ clearable
156
+ persistent-clear
157
+ style="max-width: 140px"
158
+ :rules="[qtyRule(line), serialQtyRule(line)]"
153
159
  :suffix="unitWord(line.qty, line.newItem ? line.newItem.unit : unitOf(line.item))"
154
160
  />
161
+ <!-- DV-1787: an item with serial numbers - choose which units are issued; Qty follows -->
162
+ <v-autocomplete
163
+ v-if="hasSerials(line)"
164
+ v-model="line.serials"
165
+ :items="serialOptions[line.item!] ?? []"
166
+ item-title="serial"
167
+ item-value="_id"
168
+ label="Serial numbers (optional)"
169
+ placeholder="Pick the units you are issuing by serial"
170
+ multiple
171
+ chips
172
+ closable-chips
173
+ clearable
174
+ persistent-clear
175
+ density="comfortable"
176
+ class="w-100"
177
+ :hint="serialHint(line)"
178
+ persistent-hint
179
+ :no-data-text="'No serial numbers on the shelf'"
180
+ @update:model-value="(v: string[] | null) => serialsPicked(line, v)"
181
+ />
155
182
  <v-text-field
156
183
  v-if="mode === 'receive' && receivingType !== 'CASH'"
157
184
  v-model.number="line.ordered"
@@ -244,12 +271,45 @@
244
271
  label="For which property"
245
272
  density="comfortable"
246
273
  />
247
- <InputLabel title="Work order / reference no. (optional)" class="mb-1" />
248
- <v-text-field v-model="reference" density="comfortable" placeholder="e.g. EE202507-0002" />
274
+ <!-- DV-1787: Issue Stock picks a real work order of the site, kept apart from the free-text reference. -->
275
+ <template v-if="mode === 'issue'">
276
+ <InputLabel title="Work order (optional)" class="mb-1" />
277
+ <v-text-field
278
+ :model-value="workOrder ? [workOrder.number, workOrder.subject].filter(Boolean).join(' · ') : ''"
279
+ density="comfortable"
280
+ readonly
281
+ placeholder="Select the work order this stock is for"
282
+ append-inner-icon="mdi-clipboard-text-search-outline"
283
+ :clearable="Boolean(workOrder)"
284
+ persistent-clear
285
+ @click="workOrderPicker = true"
286
+ @click:append-inner="workOrderPicker = true"
287
+ @click:clear="workOrder = null"
288
+ />
289
+ <InputLabel title="Reference no. (optional)" class="mb-1" />
290
+ <v-text-field v-model="reference" density="comfortable" placeholder="e.g. EE202507-0002" clearable persistent-clear />
291
+ <InputLabel title="Return date (optional)" class="mb-1" />
292
+ <!-- the apps standard date field: DD/MM/YYYY, the value stays YYYY-MM-DD -->
293
+ <InputDatePicker
294
+ v-model="returnDate"
295
+ :min="today"
296
+ :rules="[returnDateRule]"
297
+ placeholder="DD/MM/YYYY"
298
+ density="comfortable"
299
+ clearable
300
+ persistent-clear
301
+ hint="When they should give it back. Leave empty if it is not coming back."
302
+ persistent-hint
303
+ />
304
+ </template>
305
+ <template v-else>
306
+ <InputLabel title="Work order / reference no. (optional)" class="mb-1" />
307
+ <v-text-field v-model="reference" density="comfortable" placeholder="e.g. EE202507-0002" />
308
+ </template>
249
309
  </template>
250
310
 
251
311
  <InputLabel title="Remarks (optional)" class="mb-1 mt-2" />
252
- <v-textarea v-model="remarks" rows="2" auto-grow density="comfortable" />
312
+ <v-textarea v-model="remarks" rows="2" auto-grow density="comfortable" clearable persistent-clear />
253
313
  </v-form>
254
314
  </v-card-text>
255
315
 
@@ -258,6 +318,14 @@
258
318
  <v-btn class="screen-btn-primary" variant="flat" :loading="saving" @click="submit">{{ copy.button }}</v-btn>
259
319
  </div>
260
320
  </v-card>
321
+ <InventoryWorkOrderPicker
322
+ v-if="mode === 'issue'"
323
+ v-model="workOrderPicker"
324
+ :site-id="site || siteId"
325
+ :technicians="people"
326
+ :default-assignee="holder"
327
+ @picked="(w: TPickedWorkOrder) => (workOrder = w)"
328
+ />
261
329
  </v-dialog>
262
330
  </template>
263
331
 
@@ -271,7 +339,7 @@ import { notListedText } from "../utils/inventory-request-text";
271
339
 
272
340
  type TMode = "receive" | "issue" | "request" | "return" | "transfer";
273
341
  type TNewItem = { name: string; unit: string; category: string; note: string };
274
- type TRow = { item: string; qty: number | null; unitCost?: number | null; ordered?: number | null; typed?: string; newItem?: TNewItem | null };
342
+ type TRow = { serials?: string[]; item: string | null; qty: number | null; unitCost?: number | null; ordered?: number | null; typed?: string; newItem?: TNewItem | null };
275
343
 
276
344
  const show = defineModel<boolean>({ default: false });
277
345
  const props = defineProps({
@@ -346,8 +414,16 @@ const copy = computed(() => {
346
414
  });
347
415
 
348
416
  const form = ref();
417
+ /** DV-1787: serials picked - Qty covers them, and its message is checked again (not left stale). */
418
+ function serialsPicked(line: TRow, v: string[] | null) {
419
+ line.qty = Math.max(Number(line.qty) || 0, v?.length ?? 0) || null;
420
+ nextTick(() => {
421
+ const qtyField = (form.value?.items ?? []).find((i: any) => i.errorMessages?.length && /serial/i.test(String(i.errorMessages)));
422
+ qtyField?.validate?.();
423
+ });
424
+ }
349
425
  const saving = ref(false);
350
- const blank = (): TRow => ({ item: "", qty: null, unitCost: null, ordered: null, typed: "", newItem: null });
426
+ const blank = (): TRow => ({ item: null, qty: null, unitCost: null, ordered: null, typed: "", newItem: null });
351
427
  /** Receive: only store managers may add items to the list (the API says 403 otherwise). Request: anyone may ask. */
352
428
  const canAddNew = computed(() => (props.mode === "receive" ? props.store.access.canManage : props.mode === "request"));
353
429
  function typedSearch(line: TRow, q: string) {
@@ -356,7 +432,7 @@ function typedSearch(line: TRow, q: string) {
356
432
  }
357
433
  function addNew(line: TRow) {
358
434
  line.newItem = { name: line.typed || "", unit: "pcs", category: "", note: "" };
359
- line.item = "";
435
+ line.item = null;
360
436
  }
361
437
  const rows = ref<TRow[]>([blank()]);
362
438
  const chosenCount = computed(() => rows.value.filter((r) => r.item || r.newItem?.name?.trim()).length);
@@ -366,8 +442,62 @@ const remarks = ref("");
366
442
  const photos = ref<string[]>([]);
367
443
  const today = new Date().toLocaleDateString("en-CA");
368
444
  const date = ref(today);
369
- const holder = ref("");
445
+ // null (not ""): an empty field, so its clear button shows only once someone is picked.
446
+ const holder = ref<string | null>(null);
370
447
  const site = ref(props.siteId);
448
+ // DV-1787: Issue Stock - the work order it is for, and when it should come back (both optional).
449
+ const workOrder = ref<TPickedWorkOrder | null>(null);
450
+ const workOrderPicker = ref(false);
451
+ const returnDate = ref<string | null>("");
452
+ const returnDateRule = (v: string | null) => !v || v >= today || "The return date cannot be in the past";
453
+ // Another property: its work orders differ, so a picked one no longer applies.
454
+ watch(site, () => (workOrder.value = null));
455
+ // DV-1787: serial numbers of the chosen items (issue only), loaded when an item with serials is picked.
456
+ const serialOptions = reactive<Record<string, { _id: string; serial: string }[]>>({});
457
+ const hasSerials = (line: TRow) =>
458
+ props.mode === "issue" && !!line.item && (itemChoices.value.find((c) => c._id === line.item)?.serialsInStore ?? 0) > 0;
459
+ /** Units of the item on the shelf without a serial number (mixed stock: serials are optional). */
460
+ const withoutSerial = (line: TRow) => {
461
+ const c = itemChoices.value.find((x) => x._id === line.item);
462
+ return c ? Math.max(0, Number(c.onHand ?? 0) - Number(c.serialsInStore ?? 0)) : 0;
463
+ };
464
+ const serialHint = (line: TRow) => {
465
+ const n = withoutSerial(line);
466
+ const picked = line.serials?.length ?? 0;
467
+ const rest = Math.max(0, Number(line.qty || 0) - picked);
468
+ return `${picked} by serial${rest ? `, ${rest} without a serial` : ""}. ${n} on the shelf without a serial.`;
469
+ };
470
+ /** Qty = units by serial + units without one; no more without one than the shelf has. */
471
+ function serialQtyRule(line: TRow) {
472
+ return (v: number | null) => {
473
+ if (!hasSerials(line)) return true;
474
+ const picked = line.serials?.length ?? 0;
475
+ const q = Number(v || 0);
476
+ if (q < picked) return `At least ${picked} (the serials chosen)`;
477
+ const n = withoutSerial(line);
478
+ if (q - picked > n) return n ? `Only ${n} without a serial: pick serials for the rest` : "Pick a serial number for each unit";
479
+ return true;
480
+ };
481
+ }
482
+ watch(
483
+ () => rows.value.map((r) => r.item),
484
+ async () => {
485
+ for (const r of rows.value) {
486
+ if (!hasSerials(r)) {
487
+ if (r.serials?.length) r.serials = [];
488
+ continue;
489
+ }
490
+ if (serialOptions[r.item!]) continue;
491
+ try {
492
+ serialOptions[r.item!] = (await api.getSerials(r.item!, "in_store")).items.map((s) => ({ _id: s._id, serial: s.serial }));
493
+ } catch {
494
+ serialOptions[r.item!] = [];
495
+ }
496
+ }
497
+ },
498
+ );
499
+ // Another person (or none): the work order was picked for the previous one, so it goes too.
500
+ watch(holder, () => (workOrder.value = null));
371
501
  // Receiving (client 2026-10-02): PO / DO / cash, each with its own paperwork.
372
502
  const receivingType = ref<TReceivingType>("PO");
373
503
  const doNumber = ref("");
@@ -397,7 +527,7 @@ async function loadTargets() {
397
527
  const receivingHelp = computed(() => RECEIVING_TYPES.find((t) => t.value === receivingType.value)?.help ?? "");
398
528
  const hasOrdered = (r: TRow) => r.ordered !== null && r.ordered !== undefined && r.ordered !== ("" as any);
399
529
  const receivingCheck = () =>
400
- receivingProblem({ type: receivingType.value, poNumber: reference.value, doNumber: doNumber.value, doDate: doDate.value, anyOrdered: receivingType.value !== "CASH" && rows.value.some(hasOrdered) });
530
+ receivingProblem({ type: receivingType.value, poNumber: reference.value || "", doNumber: doNumber.value, doDate: doDate.value, anyOrdered: receivingType.value !== "CASH" && rows.value.some(hasOrdered) });
401
531
  /** Shown once they have tried to save, so the form does not open with a warning. */
402
532
  const receivingError = computed(() => (props.mode === "receive" && tried.value ? receivingCheck() : ""));
403
533
  const orderedRule = (v: number | null | string) => v === null || v === "" || (Number.isInteger(Number(v)) && Number(v) >= 1) || "Whole number";
@@ -410,8 +540,8 @@ const choices = computed<any[]>(() =>
410
540
  );
411
541
  const siteChoices = computed(() => (props.sites.length ? props.sites : props.store.sites.map((_id) => ({ _id, name: _id === props.siteId ? "This property" : "Other property" }))));
412
542
 
413
- const unitOf = (id: string) => choices.value.find((c) => c._id === id)?.unit ?? "";
414
- const availableOf = (id: string) => {
543
+ const unitOf = (id: string | null) => choices.value.find((c) => c._id === id)?.unit ?? "";
544
+ const availableOf = (id: string | null) => {
415
545
  const c = choices.value.find((x) => x._id === id);
416
546
  return c && (props.mode === "request" || props.mode === "issue" || props.mode === "transfer") ? availableQty(c) : c?.onHand;
417
547
  };
@@ -499,7 +629,7 @@ async function submit() {
499
629
  supplier: supplier.value,
500
630
  ...receivingFields({
501
631
  type: receivingType.value,
502
- poNumber: reference.value,
632
+ poNumber: reference.value || "",
503
633
  doNumber: doNumber.value,
504
634
  // The server refuses a future time: today's DO date is "now", an earlier one noon that day.
505
635
  doDateIso: doDate.value ? (pickedDate(doDate.value) ?? new Date().toISOString()) : undefined,
@@ -507,7 +637,7 @@ async function submit() {
507
637
  }),
508
638
  date: pickedDate(date.value),
509
639
  photos: photos.value,
510
- remarks: remarks.value,
640
+ remarks: remarks.value || "",
511
641
  });
512
642
  } else if (props.mode === "request") {
513
643
  const newItems = fresh.map((r) => ({
@@ -521,15 +651,27 @@ async function submit() {
521
651
  lines,
522
652
  ...(newItems.length ? { newItems } : {}),
523
653
  ...(deliverChoice.value && deliverTo.value === "store" ? { deliverTo: { store: ownStore.value!._id } } : {}),
524
- reference: reference.value,
525
- remarks: remarks.value,
654
+ reference: reference.value || "",
655
+ remarks: remarks.value || "",
526
656
  });
527
657
  } else if (props.mode === "transfer") {
528
- await api.transferToStore(props.store._id, { to: transferTo.value, site: props.siteId, lines, reference: reference.value, remarks: remarks.value });
658
+ await api.transferToStore(props.store._id, { to: transferTo.value, site: props.siteId, lines, reference: reference.value || "", remarks: remarks.value || "" });
529
659
  } else if (props.mode === "issue") {
530
- await api.issue(props.store._id, { holder: holder.value, site: site.value || props.siteId, lines, reference: reference.value, remarks: remarks.value });
660
+ await api.issue(props.store._id, {
661
+ holder: holder.value,
662
+ site: site.value || props.siteId,
663
+ // DV-1787: the chosen serial numbers go with their item.
664
+ lines: lines.map((l) => {
665
+ const row = rows.value.find((r) => r.item === l.item && r.serials?.length);
666
+ return row ? { ...l, serials: row.serials } : l;
667
+ }),
668
+ reference: reference.value || "",
669
+ remarks: remarks.value || "",
670
+ ...(workOrder.value ? { workOrder: workOrder.value._id } : {}),
671
+ ...(returnDate.value ? { returnDate: returnDate.value } : {}),
672
+ });
531
673
  } else {
532
- await api.receiveReturn(props.store._id, { holder: props.holderId, lines, remarks: remarks.value });
674
+ await api.receiveReturn(props.store._id, { holder: props.holderId, lines, remarks: remarks.value || "" });
533
675
  }
534
676
  notify(copy.value.success);
535
677
  show.value = false;
@@ -545,13 +687,17 @@ watch(show, (open) => {
545
687
  if (!open) return;
546
688
  form.value?.resetValidation();
547
689
  rows.value = [blank()];
690
+ // serial numbers change with every issue / return: load them fresh
691
+ for (const k of Object.keys(serialOptions)) delete serialOptions[k];
548
692
  supplier.value = "";
549
693
  reference.value = "";
550
694
  remarks.value = "";
551
695
  photos.value = [];
552
696
  date.value = today;
553
- holder.value = "";
697
+ holder.value = null;
554
698
  site.value = props.siteId;
699
+ workOrder.value = null;
700
+ returnDate.value = "";
555
701
  receivingType.value = "PO";
556
702
  doNumber.value = "";
557
703
  doDate.value = "";
@@ -169,6 +169,10 @@
169
169
  <v-window-item v-if="ctl.tabs.mine" value="mine">
170
170
  <InventoryMyStockTab :store="store" :site-id="siteId" :sites="storeSites" @changed="refreshCounts" />
171
171
  </v-window-item>
172
+ <!-- DV-1787: what is checked out (issued for a work order / to come back by a date), overdue first. -->
173
+ <v-window-item v-if="seesCheckouts" value="checkouts">
174
+ <InventoryCheckoutsTab :store="store" :refresh="refreshTick" @counts="(c: { out: number; overdue: number }) => (overdueCount = c.overdue)" @changed="refreshCounts" />
175
+ </v-window-item>
172
176
  <v-window-item v-if="ctl.tabs.requests" value="requests">
173
177
  <InventoryRequestsTab :store="store" :site-id="siteId" :focus-request="focusRequest" @changed="refreshCounts" />
174
178
  </v-window-item>
@@ -303,6 +307,21 @@ const worker = useWorkerTerm({ providers: true });
303
307
 
304
308
  const ctl = computed(() => inventoryControls(store.value?.access));
305
309
 
310
+ // DV-1787: the store's keepers, approvers, managers and report readers see everyone's checkouts.
311
+ const seesCheckouts = computed(() => {
312
+ const a = store.value?.access;
313
+ return Boolean(a && (a.canHandle || a.canApprove || a.canManage || a.canReports));
314
+ });
315
+ const overdueCount = ref(0);
316
+ async function refreshOverdue() {
317
+ if (!store.value || !seesCheckouts.value) return (overdueCount.value = 0);
318
+ try {
319
+ overdueCount.value = (await useInventory().getCheckouts(store.value._id, { limit: 1 })).counts.overdue;
320
+ } catch {
321
+ overdueCount.value = 0;
322
+ }
323
+ }
324
+
306
325
  const tabs = computed(() => {
307
326
  const a = store.value?.access;
308
327
  if (!a) return [];
@@ -310,6 +329,7 @@ const tabs = computed(() => {
310
329
  { value: "stock", label: "Stock" },
311
330
  // Hide, never grey: each tab only for the job that uses it (API-core decides `access`).
312
331
  ...(ctl.value.tabs.mine ? [{ value: "mine", label: "My Stock" }] : []),
332
+ ...(seesCheckouts.value ? [{ value: "checkouts", label: "Checked out", badge: overdueCount.value }] : []),
313
333
  ...(ctl.value.tabs.requests ? [{ value: "requests", label: a.canApprove ? "Requests" : "My Requests", badge: a.canApprove ? pendingCount.value : 0 }] : []),
314
334
  ...(ctl.value.tabs.people ? [{ value: "technicians", label: worker.many, badge: returnsWaiting.value }] : []),
315
335
  ...(ctl.value.tabs.reports ? [{ value: "reports", label: a.canReports ? "Reports" : "Usage check" }] : []),
@@ -396,9 +416,13 @@ async function refreshReturns() {
396
416
  }
397
417
  }
398
418
 
419
+ /** DV-1787: tells the Checked out list to reload after stock changed on another tab. */
420
+ const refreshTick = ref(0);
399
421
  async function refreshCounts() {
422
+ refreshTick.value++;
400
423
  refreshToConfirm();
401
424
  refreshReturns();
425
+ refreshOverdue();
402
426
  if (!store.value?.access.canApprove) return (pendingCount.value = 0);
403
427
  try {
404
428
  pendingCount.value = (await getRequests(store.value._id, { status: "pending", limit: 1 }))?.pendingCount ?? 0;
@@ -103,6 +103,12 @@
103
103
  </v-col>
104
104
  </v-row>
105
105
 
106
+ <!-- DV-1787: what was issued to me for a work order / to give back by a date, flagged when overdue. -->
107
+ <div v-show="checkedOut > 0" class="mt-6">
108
+ <div class="text-subtitle-2 mb-2">Checked out to me</div>
109
+ <InventoryCheckoutsTab ref="checkoutsList" :store="store" mine @counts="(c: { out: number; overdue: number }) => (checkedOut = c.out)" @changed="changed" />
110
+ </div>
111
+
106
112
  <div class="d-flex align-center mt-6 mb-2">
107
113
  <div class="text-subtitle-2">My recent activity</div>
108
114
  <v-spacer />
@@ -126,7 +132,7 @@
126
132
  <td>{{ activityText(t) }}</td>
127
133
  <td class="text-right">{{ t.qty }}</td>
128
134
  <td class="text-caption">
129
- {{ [t.location?.type === "tenant_unit" ? `${t.location.unitName} ${t.location.tenantName || ""}` : t.location?.area, t.type === "handover" ? t.remarks : t.reference].filter(Boolean).join(" · ") }}
135
+ {{ [t.location?.type === "tenant_unit" ? `${t.location.unitName} ${t.location.tenantName || ""}` : t.location?.area, t.type === "handover" ? t.remarks : t.reference, t.type === "issue" && t.workOrderNumber ? `WO ${t.workOrderNumber}` : "", t.type === "issue" && t.returnDate ? `Return by ${returnDayText(t.returnDate)}` : ""].filter(Boolean).join(" · ") }}
130
136
  </td>
131
137
  <td class="text-right">{{ t.holderBalance }}</td>
132
138
  </tr>
@@ -205,6 +211,17 @@
205
211
  style="max-width: 200px"
206
212
  :rules="[retQtyRule]"
207
213
  />
214
+ <!-- DV-1787: which serial numbers come back; the rest are units without a serial -->
215
+ <InventorySerialPick
216
+ v-model="ret.serials"
217
+ :item="String(ret.holding.item)"
218
+ source="mine"
219
+ :qty="Number(ret.qty || 0)"
220
+ :units="freeOf(ret.holding)"
221
+ :open="ret.show"
222
+ label="Which serial numbers? (optional)"
223
+ @update:model-value="(v: string[] | null) => (ret.qty = Math.max(Number(ret.qty) || 0, v?.length ?? 0) || null)"
224
+ />
208
225
  <InputLabel title="Note (optional)" class="mb-1" />
209
226
  <v-text-field v-model="ret.note" density="comfortable" maxlength="500" placeholder="e.g. job cancelled, not needed" />
210
227
  </v-form>
@@ -281,14 +298,14 @@ async function loadToReceive() {
281
298
  }
282
299
 
283
300
  const retForm = ref();
284
- const ret = reactive({ show: false, holding: null as TInventoryHolding | null, qty: 1 as number | null, note: "", saving: false });
301
+ const ret = reactive({ show: false, holding: null as TInventoryHolding | null, qty: 1 as number | null, note: "", serials: [] as string[], saving: false });
285
302
  const retQtyRule = (v: any) => {
286
303
  if (!Number.isInteger(Number(v)) || Number(v) < 1) return "Enter a whole number";
287
304
  const max = ret.holding ? freeOf(ret.holding) : 0;
288
305
  return Number(v) <= max || `You can return up to ${max}`;
289
306
  };
290
307
  function openReturn(h: TInventoryHolding) {
291
- Object.assign(ret, { show: true, holding: h, qty: freeOf(h), note: "", saving: false });
308
+ Object.assign(ret, { show: true, holding: h, qty: freeOf(h), note: "", serials: [], saving: false });
292
309
  }
293
310
  async function submitReturn() {
294
311
  const { valid } = await retForm.value.validate();
@@ -296,7 +313,13 @@ async function submitReturn() {
296
313
  ret.saving = true;
297
314
  try {
298
315
  const site = props.store.sites.includes(props.siteId) ? props.siteId : props.store.sites[0];
299
- await api.requestReturn(props.store._id, { site, item: String(ret.holding.item), qty: Number(ret.qty), note: ret.note });
316
+ await api.requestReturn(props.store._id, {
317
+ site,
318
+ item: String(ret.holding.item),
319
+ qty: Number(ret.qty),
320
+ note: ret.note,
321
+ ...(ret.serials.length ? { serials: ret.serials } : {}),
322
+ });
300
323
  notify("Return requested. Bring the items to the store keeper; they leave your stock once the keeper accepts them.");
301
324
  ret.show = false;
302
325
  changed();
@@ -369,6 +392,14 @@ const toConfirm = computed(() => handovers.value.filter((h) => h.status === "pen
369
392
  const waiting = computed(() => handovers.value.filter((h) => h.status === "pending" && String(h.from) === me.value));
370
393
  const acting = ref("");
371
394
 
395
+ // DV-1787: checked out to me (shown only when something is), and the return date as its calendar day.
396
+ const checkedOut = ref(0);
397
+ const checkoutsList = ref<{ load: () => void } | null>(null);
398
+ const returnDayText = (d: string) => {
399
+ const [y, m, day] = d.slice(0, 10).split("-").map(Number);
400
+ return standardFormatDate(new Date(y, m - 1, day));
401
+ };
402
+
372
403
  function activityText(t: TInventoryTransaction) {
373
404
  if (t.type === "issue") return "Taken from store";
374
405
  if (t.type === "return") return "Given back to store";
@@ -475,6 +506,7 @@ function use(h: TInventoryHolding) {
475
506
 
476
507
  function changed() {
477
508
  load();
509
+ checkoutsList.value?.load();
478
510
  loadHandovers();
479
511
  loadDrafts();
480
512
  loadColleagueDrafts();
@@ -0,0 +1,85 @@
1
+ <template>
2
+ <!--
3
+ DV-1787: which serial numbers go (write-off, usage) for an item with serials. Optional: the rest
4
+ of the quantity goes as units without a serial. Shows nothing when there are no serials to choose.
5
+ -->
6
+ <v-autocomplete
7
+ v-if="choices.length"
8
+ v-model="picked"
9
+ :items="choices"
10
+ item-title="serial"
11
+ item-value="_id"
12
+ :label="label"
13
+ placeholder="Pick the units by serial"
14
+ density="comfortable"
15
+ multiple
16
+ chips
17
+ closable-chips
18
+ clearable
19
+ persistent-clear
20
+ :hint="hint"
21
+ persistent-hint
22
+ :rules="[rule]"
23
+ class="mb-2"
24
+ />
25
+ </template>
26
+
27
+ <script setup lang="ts">
28
+ import useInventory from "../composables/useInventory";
29
+
30
+ const picked = defineModel<string[]>({ default: () => [] });
31
+ const props = defineProps({
32
+ item: { type: String, default: "" },
33
+ /** `store`: serials on the shelf. `mine`: serials out with the signed-in person. */
34
+ source: { type: String as PropType<"store" | "mine">, default: "mine" },
35
+ qty: { type: Number, default: 0 },
36
+ /** Units of the item in this stock (the shelf, or the person's hand). */
37
+ units: { type: Number, default: 0 },
38
+ label: { type: String, default: "Serial numbers (optional)" },
39
+ /** Whether the dialog is open (reloads the choices each time). */
40
+ open: { type: Boolean, default: true },
41
+ /** Serials chosen before (a draft) that are still the person's. */
42
+ initial: { type: Array as PropType<string[]>, default: () => [] },
43
+ });
44
+
45
+ const api = useInventory();
46
+ const choices = ref<{ _id: string; serial: string }[]>([]);
47
+
48
+ const without = computed(() => Math.max(0, props.units - choices.value.length));
49
+ const hint = computed(() => {
50
+ const n = picked.value?.length ?? 0;
51
+ const rest = Math.max(0, Number(props.qty || 0) - n);
52
+ return `${n} by serial${rest ? `, ${rest} without a serial` : ""}. Choose the exact units so each serial's history is right.`;
53
+ });
54
+ /** No more serials than the quantity; on the shelf, no more units without a serial than it has. */
55
+ function rule() {
56
+ const n = picked.value?.length ?? 0;
57
+ const q = Number(props.qty || 0);
58
+ if (n > q) return `You chose ${n} serial numbers for ${q}`;
59
+ if (props.source === "store" && q - n > without.value) {
60
+ return without.value ? `Only ${without.value} without a serial: pick serials for the rest` : "Pick a serial number for each unit";
61
+ }
62
+ return true;
63
+ }
64
+
65
+ async function load() {
66
+ choices.value = [];
67
+ if (!props.item) return;
68
+ try {
69
+ const res = await api.getSerials(props.item, props.source === "store" ? "in_store" : "mine");
70
+ choices.value = res.items.map((s) => ({ _id: s._id, serial: s.serial }));
71
+ const ok = new Set(choices.value.map((c) => c._id));
72
+ picked.value = props.initial.filter((id) => ok.has(String(id))).map(String);
73
+ } catch {
74
+ choices.value = [];
75
+ }
76
+ }
77
+
78
+ watch(
79
+ () => [props.open, props.item],
80
+ ([open]) => {
81
+ if (open) load();
82
+ },
83
+ { immediate: true },
84
+ );
85
+ </script>