@7365admin1/layer-common 4.97.1-staging.737 → 4.97.1-staging.738

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,288 @@
1
+ <template>
2
+ <!--
3
+ DV-1787: the details of issued items (one item's issues on a work order / feedback, or one row of
4
+ Checked out): totals, then each issue with a table of its serial numbers and the units without one,
5
+ and for the holder Received / Not Received / Ask to Return.
6
+ -->
7
+ <v-dialog v-model="show" max-width="600" scrollable>
8
+ <v-card v-if="rows.length" class="screen-modal">
9
+ <v-card-title class="d-flex align-center">
10
+ {{ rows[0].itemName }}
11
+ <span v-if="subtitle" class="text-body-2 text-medium-emphasis ml-2">{{ subtitle }}</span>
12
+ <v-spacer />
13
+ <v-btn icon="mdi-close" variant="text" class="screen-modal__close" aria-label="Close" @click="show = false" />
14
+ </v-card-title>
15
+ <v-card-text class="screen-modal__body">
16
+ <div class="cd__stats mb-3">
17
+ <div v-for="st in totals" :key="st.label" class="cd__stat">
18
+ <div class="cd__stat-num" :class="st.cls">{{ st.n }}</div>
19
+ <div class="cd__stat-label">{{ st.label }}</div>
20
+ </div>
21
+ </div>
22
+ <div v-for="c in rows" :key="c._id" class="cd__issue">
23
+ <div class="cd__top">
24
+ <span class="cd__name">
25
+ {{ qtyUnit(c.qty, c.unit) }} issued to {{ c.holderName }}
26
+ <span v-if="c.workOrderNumber && mixedWo" class="text-medium-emphasis font-weight-regular">· {{ c.workOrderNumber }}</span>
27
+ </span>
28
+ <span class="d-flex flex-wrap ga-1">
29
+ <!-- only what needs attention: overdue / due today, or how it ended -->
30
+ <v-tooltip v-if="chipShown(c)" :text="checkoutChip(c).info" location="top" max-width="280">
31
+ <template #activator="{ props: tip }">
32
+ <v-chip v-bind="tip" size="small" variant="tonal" :color="checkoutChip(c).color" :prepend-icon="checkoutChip(c).icon">{{ checkoutChip(c).text }}</v-chip>
33
+ </template>
34
+ </v-tooltip>
35
+ <v-tooltip v-if="c.status === 'out' && c.returnRequest && !c.returnAsked" :text="RETURN_ASKED_INFO" location="top" max-width="280">
36
+ <template #activator="{ props: tip }">
37
+ <v-chip v-bind="tip" size="small" variant="tonal" color="primary" prepend-icon="mdi-keyboard-return">Return Asked</v-chip>
38
+ </template>
39
+ </v-tooltip>
40
+ </span>
41
+ </div>
42
+ <div class="cd__dates">
43
+ <span><span class="cd__label">Issued</span> {{ standardFormatDateTime(c.createdAt) }}</span>
44
+ <span><span class="cd__label">Return by</span> {{ c.returnDate ? returnDayText(c.returnDate) : "—" }}</span>
45
+ <span v-if="c.status !== 'out' && c.closedAt"><span class="cd__label">{{ c.status === "returned" ? "Returned" : "Closed" }}</span> {{ standardFormatDateTime(c.closedAt) }}</span>
46
+ </div>
47
+ <!-- this issue's own totals (when the dialog shows more than one) -->
48
+ <div v-if="rows.length > 1" class="cd__mini mt-2">
49
+ <span v-for="st in checkoutStats([c])" :key="st.label" class="cd__mini-pill">
50
+ <b :class="st.cls">{{ st.n }}</b> {{ st.label }}
51
+ </span>
52
+ </div>
53
+ <v-table v-if="serialRows(c).length" density="compact" class="cd__table mt-2">
54
+ <thead>
55
+ <tr>
56
+ <th>S/N / Qty</th>
57
+ <th>Status</th>
58
+ <th>When</th>
59
+ </tr>
60
+ </thead>
61
+ <tbody>
62
+ <tr v-for="(r, i) in serialRows(c)" :key="i">
63
+ <td>
64
+ <span class="font-weight-medium">{{ r.serial }}</span>
65
+ <span v-if="r.plain" class="text-body-2 text-medium-emphasis"> · no S/N</span>
66
+ </td>
67
+ <td><v-chip size="small" variant="tonal" :color="r.color">{{ r.label }}</v-chip></td>
68
+ <td class="text-body-2 text-medium-emphasis">{{ r.at ? standardFormatDateTime(r.at) : "—" }}</td>
69
+ </tr>
70
+ </tbody>
71
+ </v-table>
72
+ <!-- not received yet: the holder taps Received first (then Ask to Return shows) -->
73
+ <template v-if="c.status === 'out' && c.received === false">
74
+ <v-alert v-if="c.ackStatus === 'not_received'" type="error" variant="tonal" density="compact" class="mt-2 cd__note" icon="mdi-alert-circle-outline">
75
+ {{ isMine(c) ? "You said you did not get it." : `${c.holderName} said they did not get it.` }} The store keeper checks and takes it back.
76
+ <template v-if="isMine(c)"> If it turns up, tap Received.</template>
77
+ </v-alert>
78
+ <div v-if="isMine(c)" class="d-flex flex-wrap align-center ga-2 mt-2">
79
+ <v-btn variant="flat" color="primary" class="text-none cd__btn" prepend-icon="mdi-check" :loading="receiving === c._id" @click="markReceived(c)">Received</v-btn>
80
+ <v-btn v-if="c.ackStatus !== 'not_received'" variant="outlined" color="error" class="text-none cd__btn" prepend-icon="mdi-close" @click="openNotReceived(c)">
81
+ Not Received
82
+ </v-btn>
83
+ </div>
84
+ <div v-if="isMine(c) && c.ackStatus !== 'not_received'" class="cd__meta text-medium-emphasis mt-1">
85
+ Tap Received once it is in your hands (then you can ask to return it), or Not Received if you did not get it.
86
+ </div>
87
+ </template>
88
+ <v-btn v-if="isMine(c) && askLeft(c) > 0" variant="tonal" color="primary" class="text-none mt-2 cd__btn" prepend-icon="mdi-keyboard-return" @click="openAsk(c)">
89
+ {{ c.returnAsked?.qty ? `Ask to Return the Other ${askLeft(c)}` : "Ask to Return" }}
90
+ </v-btn>
91
+ </div>
92
+ </v-card-text>
93
+ </v-card>
94
+ </v-dialog>
95
+
96
+ <InventoryCheckoutReturnDialog v-model="ask.show" :row="ask.row" mode="ask" @done="emit('changed')" />
97
+
98
+ <!-- Not Received: why, so the store keeper can check -->
99
+ <v-dialog v-model="nr.show" max-width="440">
100
+ <v-card class="screen-modal">
101
+ <v-card-title class="d-flex align-center">
102
+ Not Received
103
+ <v-spacer />
104
+ <v-btn icon="mdi-close" variant="text" class="screen-modal__close" aria-label="Close" @click="nr.show = false" />
105
+ </v-card-title>
106
+ <v-card-text class="screen-modal__body">
107
+ <p class="text-body-1 mb-3">Tell the store keeper you did not get {{ nr.row ? `${qtyUnit(nr.row.qty, nr.row.unit)} of ${nr.row.itemName}` : "it" }}. It stays out until they check and take it back.</p>
108
+ <InputLabel title="Why?" required class="mb-1" />
109
+ <v-text-field v-model="nr.reason" density="comfortable" placeholder="e.g. nothing was handed to me" hide-details="auto" :rules="[(v) => !!String(v || '').trim() || 'Required']" />
110
+ </v-card-text>
111
+ <div class="screen-modal__footer">
112
+ <v-btn class="screen-btn-ghost" variant="outlined" :disabled="nr.saving" @click="nr.show = false">Cancel</v-btn>
113
+ <v-btn class="screen-btn-primary" variant="flat" color="error" :loading="nr.saving" :disabled="!nr.reason.trim()" @click="saveNotReceived">Not Received</v-btn>
114
+ </div>
115
+ </v-card>
116
+ </v-dialog>
117
+ </template>
118
+
119
+ <script setup lang="ts">
120
+ import useInventory from "../composables/useInventory";
121
+ import useUtils from "../composables/useUtils";
122
+ import { qtyUnit } from "../utils/inventory-ack";
123
+ import { askLeft, checkoutChip, checkoutStats, returnDayKey, RETURN_ASKED_INFO } from "../utils/inventory-checkout";
124
+
125
+ const show = defineModel<boolean>({ default: false });
126
+ const props = defineProps({
127
+ /** The issues to show (one item's issues, or one checked-out row). */
128
+ rows: { type: Array as PropType<TInventoryCheckout[]>, default: () => [] },
129
+ /** Shown next to the item name, e.g. the work order number. */
130
+ subtitle: { type: String, default: "" },
131
+ });
132
+ /** Something changed (Received, Not Received, Ask to Return): the list reloads; the dialog follows its rows. */
133
+ const emit = defineEmits<{ changed: [] }>();
134
+
135
+ const { standardFormatDate, standardFormatDateTime } = useUtils();
136
+ const returnDayText = (d: string) => standardFormatDate(returnDayKey(d));
137
+ const totals = computed(() => checkoutStats(props.rows));
138
+ // Each issue names its work order only when they differ (the title has it otherwise).
139
+ const mixedWo = computed(() => new Set(props.rows.map((c) => c.workOrderNumber ?? "")).size > 1);
140
+
141
+ const { currentUser } = useLocalAuth();
142
+ const me = computed(() => String(currentUser.value?._id ?? ""));
143
+ const isMine = (c: TInventoryCheckout) => c.status === "out" && !!me.value && String(c.holder) === me.value;
144
+
145
+ // The plain "Not returned yet" / "Out" chip says nothing the totals don't; Pending Receipt / Not Received are in the table.
146
+ const chipShown = (c: TInventoryCheckout) => !["Not returned yet", "Out", "Pending Receipt", "Not Received"].includes(checkoutChip(c).text);
147
+ const ENDED_LABEL: Record<string, [string, string]> = {
148
+ returned: ["Returned", "success"],
149
+ written_off: ["Written Off", "error"],
150
+ used: ["Used", "grey"],
151
+ handed_over: ["Handed Over", "secondary"],
152
+ closed: ["Closed", "grey"],
153
+ };
154
+ const waitLabel = (c: TInventoryCheckout) => (c.ackStatus === "not_received" ? "Not Received" : "Pending Receipt");
155
+ const waitColor = (c: TInventoryCheckout) => (c.ackStatus === "not_received" ? "error" : "grey");
156
+ const endedLabel = (e: { type: string; toName?: string }) => (e.type === "handed_over" && e.toName ? `Handed Over to ${e.toName}` : (ENDED_LABEL[e.type]?.[0] ?? e.type));
157
+ type TRow = { serial: string; label: string; color: string; at: string | null; plain: boolean };
158
+ function serialRows(c: TInventoryCheckout): TRow[] {
159
+ const asked = new Set(c.returnAsked?.serials ?? []);
160
+ const holding = (): Omit<TRow, "serial" | "plain"> =>
161
+ c.received === false ? { label: waitLabel(c), color: waitColor(c), at: null } : { label: `With ${c.holderName}`, color: "warning", at: null };
162
+ const withSerial: TRow[] = [
163
+ ...(c.serials ?? []).map((x) => ({ serial: x.serial, plain: false, ...(asked.has(String(x._id)) ? { label: "Return Asked", color: "primary", at: null } : holding()) })),
164
+ ...(c.endedSerials ?? []).map((e) => ({ serial: e.serial, plain: false, label: endedLabel(e), color: ENDED_LABEL[e.type]?.[1] ?? "grey", at: e.at })),
165
+ ].sort((x, y) => x.serial.localeCompare(y.serial, undefined, { numeric: true }));
166
+ // Units without a serial number: one line per state, with how many.
167
+ const unit = c.unit || "pcs";
168
+ const plainOut = c.status === "out" ? Math.max(0, c.outQty - (c.serials?.length ?? 0)) : 0;
169
+ const plainAsked = c.status === "out" && c.returnAsked ? Math.max(0, c.returnAsked.qty - c.returnAsked.serials.length) : 0;
170
+ const plain: TRow[] = [];
171
+ if (plainOut - plainAsked > 0) plain.push({ serial: qtyUnit(plainOut - plainAsked, unit), plain: true, ...holding() });
172
+ if (plainAsked) plain.push({ serial: qtyUnit(plainAsked, unit), plain: true, label: "Return Asked", color: "primary", at: null });
173
+ for (const e of c.endedPlain ?? []) plain.push({ serial: qtyUnit(e.qty, unit), plain: true, label: endedLabel(e), color: ENDED_LABEL[e.type]?.[1] ?? "grey", at: e.at });
174
+ return [...withSerial, ...plain];
175
+ }
176
+
177
+ // Ask to Return / Received / Not Received for the holder.
178
+ const ask = reactive({ show: false, row: null as TInventoryCheckout | null });
179
+ const openAsk = (row: TInventoryCheckout) => Object.assign(ask, { show: true, row });
180
+ const receiving = ref("");
181
+ async function markReceived(c: TInventoryCheckout) {
182
+ if (!c.request) return;
183
+ receiving.value = c._id;
184
+ try {
185
+ await useInventory().acknowledgeRequest(String(c.request));
186
+ emit("changed");
187
+ } finally {
188
+ receiving.value = "";
189
+ }
190
+ }
191
+ const nr = reactive({ show: false, row: null as TInventoryCheckout | null, reason: "", saving: false });
192
+ const openNotReceived = (c: TInventoryCheckout) => Object.assign(nr, { show: true, row: c, reason: "" });
193
+ async function saveNotReceived() {
194
+ if (!nr.row?.request || !nr.reason.trim()) return;
195
+ nr.saving = true;
196
+ try {
197
+ await useInventory().notReceived(String(nr.row.request), nr.reason.trim());
198
+ nr.show = false;
199
+ emit("changed");
200
+ } finally {
201
+ nr.saving = false;
202
+ }
203
+ }
204
+ </script>
205
+
206
+ <style scoped>
207
+ .cd__stats {
208
+ display: flex;
209
+ flex-wrap: wrap;
210
+ gap: 8px;
211
+ }
212
+ .cd__stat {
213
+ flex: 1 1 90px;
214
+ border: 1px solid rgba(var(--v-border-color), var(--v-border-opacity));
215
+ border-radius: 8px;
216
+ padding: 8px 10px;
217
+ }
218
+ .cd__stat-num {
219
+ font-size: 1.5rem;
220
+ font-weight: 600;
221
+ line-height: 1.2;
222
+ }
223
+ .cd__stat-label {
224
+ font-size: 0.875rem;
225
+ color: rgba(var(--v-theme-on-surface), var(--v-medium-emphasis-opacity));
226
+ }
227
+ .cd__issue {
228
+ padding: 10px 0;
229
+ border-top: 1px solid rgba(var(--v-border-color), var(--v-border-opacity));
230
+ }
231
+ .cd__top {
232
+ display: flex;
233
+ flex-wrap: wrap;
234
+ align-items: center;
235
+ justify-content: space-between;
236
+ gap: 4px 8px;
237
+ }
238
+ .cd__name {
239
+ font-weight: 500;
240
+ min-width: 0;
241
+ overflow-wrap: anywhere;
242
+ }
243
+ .cd__dates {
244
+ display: flex;
245
+ flex-wrap: wrap;
246
+ gap: 2px 16px;
247
+ font-size: 0.875rem;
248
+ margin-top: 2px;
249
+ color: rgba(var(--v-theme-on-surface), var(--v-medium-emphasis-opacity));
250
+ }
251
+ .cd__label {
252
+ font-weight: 500;
253
+ }
254
+ .cd__meta {
255
+ font-size: 0.875rem;
256
+ }
257
+ .cd__mini {
258
+ display: flex;
259
+ flex-wrap: wrap;
260
+ gap: 6px;
261
+ }
262
+ .cd__mini-pill {
263
+ font-size: 0.875rem;
264
+ border: 1px solid rgba(var(--v-border-color), var(--v-border-opacity));
265
+ border-radius: 14px;
266
+ padding: 2px 10px;
267
+ color: rgba(var(--v-theme-on-surface), var(--v-medium-emphasis-opacity));
268
+ }
269
+ .cd__mini-pill b {
270
+ font-size: 0.9375rem;
271
+ }
272
+ .cd__table {
273
+ font-size: 0.9375rem;
274
+ border: 1px solid rgba(var(--v-border-color), var(--v-border-opacity));
275
+ border-radius: 6px;
276
+ }
277
+ .cd__table :deep(.v-chip) {
278
+ font-size: 0.875rem;
279
+ font-weight: 500;
280
+ }
281
+ .cd__btn {
282
+ font-size: 1rem;
283
+ font-weight: 500;
284
+ }
285
+ .cd__note {
286
+ font-size: 0.9375rem;
287
+ }
288
+ </style>
@@ -18,12 +18,16 @@
18
18
  <template v-if="mode === 'return'"> from {{ row.holderName }}</template>
19
19
  <template v-if="row.returnDate"> · return by {{ returnDayText(row.returnDate) }}</template>
20
20
  </p>
21
+ <!-- DV-1787: part of it already asked to return - say what, and that only the rest is offered. -->
22
+ <v-alert v-if="row.returnAsked?.qty" type="success" variant="tonal" density="compact" class="mb-3" icon="mdi-keyboard-return">
23
+ Already asked to return: {{ askedText(row) }}.<template v-if="mode === 'ask'"> You can ask for the other {{ qtyUnit(available, row.unit) }}.</template>
24
+ </v-alert>
21
25
 
22
26
  <v-alert type="info" variant="tonal" density="compact" class="mb-3" icon="mdi-information-outline">
23
27
  <template v-if="mode === 'ask'">
24
28
  <div class="font-weight-medium mb-1">How Ask to return works</div>
25
29
  <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>
30
+ <li>The store keeper is told you are bringing this back.</li>
27
31
  <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
32
  <li>When they accept, it goes back into the store and shows Returned with the date and time.</li>
29
33
  <li>Only then can the work order (or its feedback) be completed, if Work Order Settings ask for items to be returned first.</li>
@@ -37,27 +41,44 @@
37
41
  </template>
38
42
  </v-alert>
39
43
 
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" />
44
+ <!-- DV-1787: more than one unit out on it - return all of it, or only some: chosen serial
45
+ numbers and/or a number of the units without one. -->
46
+ <template v-if="available > 1 && !(mode === 'return' && row.returnRequest)">
47
+ <InputLabel title="What comes back" class="mb-1" />
43
48
  <v-radio-group v-model="which" inline hide-details density="compact" class="mb-1">
44
- <v-radio :label="`All ${serials.length}`" value="all" />
49
+ <v-radio :label="`All ${partial ? 'the other ' : ''}${qtyUnit(available, row.unit)}`" value="all" />
45
50
  <v-radio label="Choose which" value="some" />
46
51
  </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>
52
+ <div v-if="which === 'all'" class="text-caption text-medium-emphasis mb-3">{{ allText }}</div>
53
+ <template v-else>
54
+ <div v-if="serials.length" class="d-flex flex-wrap ga-2 mb-2">
55
+ <v-checkbox
56
+ v-for="s in serials"
57
+ :key="s._id"
58
+ v-model="picked"
59
+ :value="s._id"
60
+ :label="s.serial"
61
+ density="compact"
62
+ hide-details
63
+ />
64
+ </div>
65
+ <div v-if="plain > 0" class="d-flex align-center ga-3 mb-3">
66
+ <v-text-field
67
+ v-model.number="plainQty"
68
+ type="number"
69
+ :min="0"
70
+ :max="plain"
71
+ density="comfortable"
72
+ hide-details="auto"
73
+ :rules="[plainRule]"
74
+ style="max-width: 140px"
75
+ :suffix="row.unit || 'pcs'"
76
+ />
77
+ <span class="text-body-2 text-medium-emphasis">without serial number (of {{ plain }})</span>
78
+ </div>
79
+ </template>
59
80
  </template>
60
- <div v-else-if="serials.length === 1" class="text-caption text-medium-emphasis mb-3">Serial number: {{ serials[0].serial }}</div>
81
+ <div v-else-if="allText && (serials.length || partial)" class="text-caption text-medium-emphasis mb-3">{{ allText }}</div>
61
82
  <template v-if="!(mode === 'return' && row.returnRequest)">
62
83
  <InputLabel title="Note (optional)" class="mb-1" />
63
84
  <v-text-field v-model="note" density="comfortable" placeholder="e.g. job done, left at the store counter" hide-details />
@@ -65,8 +86,8 @@
65
86
  </v-card-text>
66
87
  <div class="screen-modal__footer">
67
88
  <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})` : "" }}
89
+ <v-btn class="screen-btn-primary" variant="flat" :loading="saving" :disabled="which === 'some' && !someOk" @click="confirm">
90
+ {{ title }}{{ which === "some" && someCount ? ` (${someCount})` : "" }}
70
91
  </v-btn>
71
92
  </div>
72
93
  </v-card>
@@ -78,7 +99,7 @@
78
99
  import useInventory from "../composables/useInventory";
79
100
  import useUtils from "../composables/useUtils";
80
101
  import { qtyUnit } from "../utils/inventory-ack";
81
- import { returnDayKey } from "../utils/inventory-checkout";
102
+ import { askedText, returnDayKey } from "../utils/inventory-checkout";
82
103
 
83
104
  const show = defineModel<boolean>({ default: false });
84
105
  const props = defineProps({
@@ -97,10 +118,33 @@ const notify = (text: string, color = "success") => (injected ? injected(text, c
97
118
  const note = ref("");
98
119
  const saving = ref(false);
99
120
  // DV-1787: serial numbers still out on it; return all, or the chosen ones.
100
- const serials = computed(() => props.row?.serials ?? []);
121
+ // Asking again on a row asked for in parts: only what is not asked yet is offered.
122
+ const asked = computed(() => (props.mode === "ask" ? props.row?.returnAsked ?? null : null));
123
+ const partial = computed(() => Boolean(asked.value?.qty));
124
+ const allSerials = computed(() => [...(props.row?.serials ?? [])].sort((a, b) => a.serial.localeCompare(b.serial, undefined, { numeric: true })));
125
+ const serials = computed(() => allSerials.value.filter((s) => !asked.value?.serials.includes(String(s._id))));
101
126
  const which = ref<"all" | "some">("all");
102
127
  const picked = ref<string[]>([]);
103
- const chosenSerials = () => (which.value === "some" ? picked.value : undefined);
128
+ // ...and units without a serial number: how many are out on it, and how many come back.
129
+ const plain = computed(() => {
130
+ const all = Math.max(0, (props.row?.outQty ?? 0) - allSerials.value.length);
131
+ const askedPlain = asked.value ? Math.max(0, asked.value.qty - asked.value.serials.length) : 0;
132
+ return Math.max(0, all - askedPlain);
133
+ });
134
+ const available = computed(() => serials.value.length + plain.value);
135
+ const plainQty = ref(0);
136
+ const plainRule = (v: number) => (Number.isInteger(Number(v)) && v >= 0 && v <= plain.value) || `0 to ${plain.value}`;
137
+ const someCount = computed(() => picked.value.length + (plain.value ? Number(plainQty.value) || 0 : 0));
138
+ const someOk = computed(() => someCount.value > 0 && plainRule(Number(plainQty.value) || 0) === true);
139
+ const allText = computed(() => {
140
+ const parts = [];
141
+ if (serials.value.length) parts.push(`S/N ${serials.value.map((s) => s.serial).join(", ")}`);
142
+ if (plain.value) parts.push(`${qtyUnit(plain.value, props.row?.unit)} without serial number`);
143
+ return parts.join(" + ");
144
+ });
145
+ // "All" on a row asked for in parts is the rest, spelled out (the serials not asked yet + the units without one).
146
+ const chosenSerials = () => (which.value === "some" ? picked.value : partial.value ? serials.value.map((s) => s._id) : undefined);
147
+ const chosenPlain = () => (which.value === "some" ? (plain.value ? Number(plainQty.value) || 0 : 0) : partial.value ? plain.value : undefined);
104
148
 
105
149
  const title = computed(() => (props.mode === "ask" ? "Ask to return" : props.row?.returnRequest ? "Accept return" : "Return to store"));
106
150
  const returnDayText = (d: string) => standardFormatDate(returnDayKey(d));
@@ -110,10 +154,10 @@ async function confirm() {
110
154
  saving.value = true;
111
155
  try {
112
156
  if (props.mode === "ask") {
113
- await api.requestCheckoutReturn(props.row._id, note.value, chosenSerials());
157
+ await api.requestCheckoutReturn(props.row._id, note.value, chosenSerials(), chosenPlain());
114
158
  notify("Return asked. The store keeper accepts it when they have it.");
115
159
  } else {
116
- await api.returnCheckout(props.row._id, note.value, chosenSerials());
160
+ await api.returnCheckout(props.row._id, note.value, chosenSerials(), chosenPlain());
117
161
  notify("Returned to the store.");
118
162
  }
119
163
  show.value = false;
@@ -130,6 +174,7 @@ watch(show, (open) => {
130
174
  note.value = "";
131
175
  which.value = "all";
132
176
  picked.value = [];
177
+ plainQty.value = 0;
133
178
  });
134
179
  </script>
135
180
 
@@ -37,6 +37,9 @@
37
37
  :items-per-page-options="[10, 25, 50]"
38
38
  density="comfortable"
39
39
  :no-data-text="mine ? 'Nothing checked out to you.' : 'Nothing here.'"
40
+ hover
41
+ class="co-table"
42
+ @click:row="(_e: unknown, r: { item: TInventoryCheckout }) => openDetail(r.item)"
40
43
  @update:page="(p: number) => ((page = p), load())"
41
44
  @update:items-per-page="(n: number) => ((limit = n), (page = 1), load())"
42
45
  >
@@ -68,32 +71,42 @@
68
71
  <span class="text-no-wrap">{{ item.status !== "out" && item.closedAt ? standardFormatDateTime(item.closedAt) : "—" }}</span>
69
72
  </template>
70
73
  <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>
74
+ <!-- DV-1787: how much is where (Not Returned, Return Asked, Returned, ...); tap the row for the serials -->
75
+ <div class="d-flex flex-wrap align-center ga-1 py-1">
76
+ <v-tooltip v-if="chipShown(item)" :text="chip(item).info" location="top" max-width="280">
77
+ <template #activator="{ props: tip }">
78
+ <v-chip v-bind="tip" size="small" variant="tonal" :color="chip(item).color" :prepend-icon="chip(item).icon">{{ chip(item).text }}</v-chip>
79
+ </template>
80
+ </v-tooltip>
81
+ <v-tooltip v-if="item.status === 'out' && item.returnRequest && !item.returnAsked" :text="RETURN_ASKED_INFO" location="top" max-width="280">
82
+ <template #activator="{ props: tip }">
83
+ <v-chip v-bind="tip" size="small" variant="tonal" color="primary" prepend-icon="mdi-keyboard-return">Return Asked</v-chip>
84
+ </template>
85
+ </v-tooltip>
86
+ <span v-for="st in rowStats(item)" :key="st.label" class="co-pill">
87
+ <b :class="st.cls">{{ st.n }}</b> {{ st.label }}
88
+ </span>
89
+ </div>
82
90
  </template>
83
91
  <!-- DV-1787: return THIS checkout (its work order), not the earliest one of the item. -->
84
92
  <template #item.actions="{ item }">
85
93
  <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)">
94
+ <!-- DV-1787: not received yet - Received (then Ask to return), or Not Received -->
95
+ <div v-if="mine && item.received === false" class="d-flex ga-1 justify-end">
96
+ <v-btn size="small" variant="flat" color="primary" class="text-none" prepend-icon="mdi-check" :loading="recv.busy === item._id" @click.stop="markReceived(item)">Received</v-btn>
97
+ <v-btn v-if="item.ackStatus !== 'not_received'" size="small" variant="outlined" color="error" class="text-none" prepend-icon="mdi-close" @click.stop="openNotReceived(item)">Not Received</v-btn>
98
+ </div>
99
+ <v-btn v-else-if="mine && askLeft(item) > 0" size="small" variant="tonal" color="primary" class="text-none" prepend-icon="mdi-keyboard-return" @click.stop="openReturn(item)">
87
100
  Ask to return
88
101
  </v-btn>
89
102
  <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)">
103
+ <v-btn size="small" variant="tonal" color="primary" class="text-none" prepend-icon="mdi-keyboard-return" @click.stop="openReturn(item)">
91
104
  {{ item.returnRequest ? "Accept return" : "Return" }}
92
105
  </v-btn>
93
106
  <!-- DV-1787: set, change or clear the return date (forgotten at the issue, or more time given) -->
94
107
  <v-tooltip text="Change return date" location="top">
95
108
  <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)" />
109
+ <v-btn v-bind="tip" size="small" variant="tonal" icon="mdi-calendar-edit" aria-label="Change return date" @click.stop="openDate(item)" />
97
110
  </template>
98
111
  </v-tooltip>
99
112
  </div>
@@ -101,8 +114,31 @@
101
114
  </template>
102
115
  </v-data-table-server>
103
116
 
117
+ <!-- DV-1787: the row's details - the same as on the feedback / work order -->
118
+ <InventoryCheckoutDetail v-model="det.show" :rows="det.row ? [det.row] : []" :subtitle="det.row?.workOrderNumber || ''" @changed="afterDetail" />
119
+
104
120
  <InventoryCheckoutReturnDialog v-model="ret.show" :row="ret.row" :mode="mine ? 'ask' : 'return'" @done="afterReturn" />
105
121
 
122
+ <!-- DV-1787: Not Received - why, so the store keeper can check -->
123
+ <v-dialog v-model="recv.show" max-width="440">
124
+ <v-card class="screen-modal">
125
+ <v-card-title class="d-flex align-center">
126
+ Not Received
127
+ <v-spacer />
128
+ <v-btn icon="mdi-close" variant="text" class="screen-modal__close" aria-label="Close" @click="recv.show = false" />
129
+ </v-card-title>
130
+ <v-card-text class="screen-modal__body">
131
+ <p class="text-body-1 mb-3">Tell the store keeper you did not get {{ recv.row ? `${qtyUnit(recv.row.qty, recv.row.unit)} of ${recv.row.itemName}` : "it" }}. It stays out until they check and take it back.</p>
132
+ <InputLabel title="Why?" required class="mb-1" />
133
+ <v-text-field v-model="recv.reason" density="comfortable" placeholder="e.g. nothing was handed to me" hide-details="auto" :rules="[(v) => !!String(v || '').trim() || 'Required']" />
134
+ </v-card-text>
135
+ <div class="screen-modal__footer">
136
+ <v-btn class="screen-btn-ghost" variant="outlined" :disabled="recv.saving" @click="recv.show = false">Cancel</v-btn>
137
+ <v-btn class="screen-btn-primary" variant="flat" color="error" :loading="recv.saving" :disabled="!recv.reason.trim()" @click="saveNotReceived">Not Received</v-btn>
138
+ </div>
139
+ </v-card>
140
+ </v-dialog>
141
+
106
142
  <v-dialog v-model="date.show" max-width="440">
107
143
  <v-card v-if="date.row" class="screen-modal">
108
144
  <v-card-title class="d-flex align-center">
@@ -144,7 +180,7 @@ import useInventory from "../composables/useInventory";
144
180
  import useUtils from "../composables/useUtils";
145
181
  import { qtyUnit } from "../utils/inventory-ack";
146
182
  import { workOrderLinkTarget } from "../utils/work-order-link";
147
- import { checkoutChip, returnDayKey, RETURN_ASKED_INFO } from "../utils/inventory-checkout";
183
+ import { askLeft, checkoutChip, checkoutStats, returnDayKey, RETURN_ASKED_INFO } from "../utils/inventory-checkout";
148
184
 
149
185
  const props = defineProps({
150
186
  store: { type: Object as PropType<TInventoryStore>, required: true },
@@ -157,6 +193,32 @@ const emit = defineEmits<{ counts: [{ out: number; overdue: number }]; changed:
157
193
  /** Store keepers take items back (the API checks too). */
158
194
  const canTakeBack = computed(() => Boolean(props.store.access?.canHandle));
159
195
 
196
+ // DV-1787: Received / Not Received on a row not received yet (its issue's request).
197
+ const recv = reactive({ show: false, row: null as TInventoryCheckout | null, reason: "", saving: false, busy: "" });
198
+ async function markReceived(row: TInventoryCheckout) {
199
+ if (!row.request) return;
200
+ recv.busy = row._id;
201
+ try {
202
+ await useInventory().acknowledgeRequest(String(row.request));
203
+ await load();
204
+ emit("changed");
205
+ } finally {
206
+ recv.busy = "";
207
+ }
208
+ }
209
+ const openNotReceived = (row: TInventoryCheckout) => Object.assign(recv, { show: true, row, reason: "" });
210
+ async function saveNotReceived() {
211
+ if (!recv.row?.request || !recv.reason.trim()) return;
212
+ recv.saving = true;
213
+ try {
214
+ await useInventory().notReceived(String(recv.row.request), recv.reason.trim());
215
+ recv.show = false;
216
+ await load();
217
+ emit("changed");
218
+ } finally {
219
+ recv.saving = false;
220
+ }
221
+ }
160
222
  // DV-1787: Return / Ask to return on one row - closes that checkout (its work order).
161
223
  const ret = reactive({ show: false, row: null as TInventoryCheckout | null });
162
224
  function openReturn(row: TInventoryCheckout) {
@@ -185,6 +247,19 @@ async function saveDate() {
185
247
  }
186
248
  }
187
249
 
250
+ // DV-1787: Status shows the quantities; the plain "Not returned yet" / "Out" chip says nothing more.
251
+ const rowStats = (c: TInventoryCheckout) => checkoutStats([c]).filter((x) => x.n > 0);
252
+ const chipShown = (c: TInventoryCheckout) => !["Not returned yet", "Out"].includes(checkoutChip(c).text);
253
+ // DV-1787: tap a row for its details (serial table, Received / Not Received / Ask to Return).
254
+ const det = reactive({ show: false, row: null as TInventoryCheckout | null });
255
+ const openDetail = (row: TInventoryCheckout) => Object.assign(det, { show: true, row });
256
+ async function afterDetail() {
257
+ await load();
258
+ // keep the dialog on the same row, now refreshed
259
+ det.row = rows.value.find((r) => r._id === det.row?._id) ?? det.row;
260
+ emit("changed");
261
+ }
262
+
188
263
  async function afterReturn() {
189
264
  await load();
190
265
  emit("changed");
@@ -258,3 +333,17 @@ onMounted(load);
258
333
  watch(() => props.refresh, () => load());
259
334
  defineExpose({ load });
260
335
  </script>
336
+
337
+ <style scoped>
338
+ .co-table :deep(tbody tr) {
339
+ cursor: pointer;
340
+ }
341
+ .co-pill {
342
+ font-size: 0.875rem;
343
+ border: 1px solid rgba(var(--v-border-color), var(--v-border-opacity));
344
+ border-radius: 14px;
345
+ padding: 1px 9px;
346
+ white-space: nowrap;
347
+ color: rgba(var(--v-theme-on-surface), var(--v-medium-emphasis-opacity));
348
+ }
349
+ </style>
@@ -60,7 +60,12 @@
60
60
  <template #item.person="{ item }">{{ item.holderLabel || item.holderName || "—" }}</template>
61
61
  <template #item.qty="{ item }">{{ qtyUnit(item.qty, item.unit) }}</template>
62
62
  <template #item.where="{ item }">{{ whereText(item.location) || (item.type === "handover" ? item.remarks : "") || "—" }}</template>
63
- <template #item.reference="{ item }">{{ item.type === "handover" ? "—" : item.reference || "—" }}</template>
63
+ <template #item.reference="{ item }">
64
+ <!-- DV-1787: a work order is a link; never a raw id -->
65
+ <NuxtLink v-if="item.workOrder && item.workOrderNumber && workOrderRoute(item)" :to="workOrderRoute(item)!" class="history-wo-link" @click="show = false">{{ item.workOrderNumber }}</NuxtLink>
66
+ <span v-else-if="item.workOrderNumber">{{ item.workOrderNumber }}</span>
67
+ <span v-else>{{ item.type === "handover" || /^[a-f0-9]{24}$/i.test(item.reference || "") ? "—" : item.reference || "—" }}</span>
68
+ </template>
64
69
  <template #item.photos="{ item }">
65
70
  <InventoryPhotoThumbs :photos="item.photos" :before-at="item.photosBeforeAt" :after-at="item.photosAfterAt" />
66
71
  </template>
@@ -81,6 +86,7 @@
81
86
  import useInventory from "../composables/useInventory";
82
87
  import useUtils from "../composables/useUtils";
83
88
  import useLocalAuth from "../composables/useLocalAuth";
89
+ import { workOrderLinkTarget } from "../utils/work-order-link";
84
90
  import { historyText, whereText } from "../utils/inventory-usage";
85
91
  import { inventoryStepsLive, qtyUnit } from "../utils/inventory-ack";
86
92
 
@@ -90,6 +96,9 @@ import { inventoryStepsLive, qtyUnit } from "../utils/inventory-ack";
90
96
  * store, hand-overs in and out, usage with where + work order + photos, and returns. Drafts are not history.
91
97
  */
92
98
  const show = defineModel<boolean>({ default: false });
99
+ const route = useRoute();
100
+ const router = useRouter();
101
+ const workOrderRoute = (t: TInventoryTransaction) => workOrderLinkTarget(t, route, router);
93
102
  const props = defineProps({
94
103
  store: { type: Object as PropType<TInventoryStore>, required: true },
95
104
  holder: { type: String, default: "" },
@@ -218,3 +227,15 @@ watch(show, async (open) => {
218
227
  }
219
228
  });
220
229
  </script>
230
+
231
+ <style scoped>
232
+ /* DV-1787: work order link (as in item History) */
233
+ .history-wo-link {
234
+ color: var(--accent);
235
+ font-weight: 600;
236
+ text-decoration: none;
237
+ }
238
+ .history-wo-link:hover {
239
+ text-decoration: underline;
240
+ }
241
+ </style>
@@ -131,8 +131,14 @@
131
131
  <td>{{ t.itemName }}</td>
132
132
  <td>{{ activityText(t) }}</td>
133
133
  <td class="text-right">{{ t.qty }}</td>
134
- <td class="text-caption">
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(" · ") }}
134
+ <td class="text-body-2">
135
+ <!-- DV-1787: the work order as a link (issue, return, use for a work order), then the rest -->
136
+ <template v-if="t.workOrder && t.workOrderNumber">
137
+ <NuxtLink v-if="workOrderRoute(t)" :to="workOrderRoute(t)!" class="history-wo-link">WO {{ t.workOrderNumber }}</NuxtLink>
138
+ <span v-else>WO {{ t.workOrderNumber }}</span>
139
+ <span v-if="activityWhere(t)"> · </span>
140
+ </template>
141
+ {{ activityWhere(t) }}
136
142
  </td>
137
143
  <td class="text-right">{{ t.holderBalance }}</td>
138
144
  </tr>
@@ -253,6 +259,7 @@ import useFile from "../composables/useFile";
253
259
  import useUtils from "../composables/useUtils";
254
260
  import useLocalAuth from "../composables/useLocalAuth";
255
261
  import { inventoryControls } from "../utils/inventory-presets";
262
+ import { workOrderLinkTarget } from "../utils/work-order-link";
256
263
  import { colleagueDraftText, draftCardText } from "../utils/inventory-usage";
257
264
  import { ackText, holdText, inventoryStepsLive, qtyUnit, unitWord } from "../utils/inventory-ack";
258
265
 
@@ -272,6 +279,19 @@ const { currentUser } = useLocalAuth();
272
279
 
273
280
  const holdings = ref<TInventoryHolding[]>([]);
274
281
  const activity = ref<TInventoryTransaction[]>([]);
282
+ // DV-1787: My recent activity - the work order is a link; never show a raw id as the reference.
283
+ const route = useRoute();
284
+ const router = useRouter();
285
+ const workOrderRoute = (t: TInventoryTransaction) => workOrderLinkTarget(t, route, router);
286
+ const isId = (v?: string) => /^[a-f0-9]{24}$/i.test(v ?? "");
287
+ const activityWhere = (t: TInventoryTransaction) =>
288
+ [
289
+ t.location?.type === "tenant_unit" ? `${t.location.unitName} ${t.location.tenantName || ""}` : t.location?.area,
290
+ t.type === "handover" ? t.remarks : t.workOrder || isId(t.reference) ? "" : t.reference,
291
+ t.type === "issue" && t.returnDate ? `Return by ${returnDayText(t.returnDate)}` : "",
292
+ ]
293
+ .filter(Boolean)
294
+ .join(" · ");
275
295
  const loading = ref(false);
276
296
  const showRequest = ref(false);
277
297
  const usage = reactive({ show: false, holding: null as TInventoryHolding | null, draft: null as TInventoryUsageDraft | null });
@@ -518,3 +538,15 @@ watch(() => props.store._id, () => (load(), loadHandovers(), loadDrafts(), loadC
518
538
  watch(stepsLive, () => (loadToReceive(), loadColleagueDrafts()));
519
539
  onMounted(() => (load(), loadHandovers(), loadDrafts(), loadColleagueDrafts(), loadToReceive()));
520
540
  </script>
541
+
542
+ <style scoped>
543
+ /* DV-1787: work order link (as in item History) */
544
+ .history-wo-link {
545
+ color: var(--accent);
546
+ font-weight: 600;
547
+ text-decoration: none;
548
+ }
549
+ .history-wo-link:hover {
550
+ text-decoration: underline;
551
+ }
552
+ </style>
@@ -5,65 +5,40 @@
5
5
  -->
6
6
  <div v-if="items.length" class="issued-items">
7
7
  <div class="text-subtitle-2 mb-2">Issued items</div>
8
- <!-- The holder sees this right above Submit: hand the tools back so management can complete it. -->
9
- <v-alert v-if="mineOut.length" type="info" variant="tonal" density="compact" class="mb-2" icon="mdi-keyboard-return">
10
- {{ mineOut.length === 1 ? "1 item is with you." : `${mineOut.length} items are with you.` }} Ask to return when you hand {{ mineOut.length === 1 ? "it" : "them" }} back.
11
- </v-alert>
12
8
  <v-alert v-if="blocking" type="warning" variant="tonal" density="compact" class="mb-2" icon="mdi-lock-outline">
13
9
  {{ blockingCount === 1 ? "1 item not returned yet." : `${blockingCount} items not returned yet.` }} Return {{ blockingCount === 1 ? "it" : "them" }} before completing.
14
10
  </v-alert>
15
- <!-- Stacked rows, not a table: the Information panel and the work order dialog are narrow. -->
11
+ <!-- DV-1787: one short line per item (what is with whom, what came back); tap it for the details
12
+ and the return options, so the narrow Information panel stays light. -->
16
13
  <div class="issued-items__list">
17
- <div v-for="c in items" :key="c._id" class="issued-items__row">
18
- <div class="issued-items__top">
14
+ <button v-for="g in groups" :key="g.key" type="button" class="issued-items__sum" @click="openGroup(g.key)">
15
+ <span class="issued-items__sum-text">
19
16
  <span class="issued-items__name">
20
- {{ c.itemName }}
21
- <span v-if="showNumber && c.workOrderNumber" class="text-caption text-medium-emphasis">· {{ c.workOrderNumber }}</span>
17
+ {{ g.itemName }}
18
+ <span v-if="showNumber && g.workOrderNumber" class="text-caption text-medium-emphasis">· {{ g.workOrderNumber }}</span>
22
19
  </span>
23
- <span class="d-flex flex-wrap ga-1">
24
- <!-- hover: what the status means -->
25
- <v-tooltip :text="checkoutChip(c).info" location="top" max-width="280">
26
- <template #activator="{ props: tip }">
27
- <v-chip v-bind="tip" size="small" variant="tonal" :color="checkoutChip(c).color" :prepend-icon="checkoutChip(c).icon">{{ checkoutChip(c).text }}</v-chip>
28
- </template>
29
- </v-tooltip>
30
- <v-tooltip v-if="c.status === 'out' && c.returnRequest" :text="RETURN_ASKED_INFO" location="top" max-width="280">
31
- <template #activator="{ props: tip }">
32
- <v-chip v-bind="tip" size="small" variant="tonal" color="primary" prepend-icon="mdi-keyboard-return">Return asked</v-chip>
33
- </template>
34
- </v-tooltip>
20
+ <span class="issued-items__meta d-block">
21
+ <template v-for="(p, i) in g.parts" :key="i">
22
+ <span v-if="i" class="text-medium-emphasis"> · </span>
23
+ <span :class="p.cls" class="font-weight-medium">{{ p.text }}</span>
24
+ </template>
25
+ <span v-if="!g.parts.length" class="text-medium-emphasis">Closed</span>
35
26
  </span>
36
- </div>
37
- <div class="issued-items__meta">{{ qtyUnit(c.status === "out" ? c.outQty : c.qty, c.unit) }} · with {{ c.holderName }}</div>
38
- <div v-if="c.serials?.length" class="issued-items__meta text-medium-emphasis">S/N {{ c.serials.map((x) => x.serial).join(", ") }}</div>
39
- <div class="issued-items__dates">
40
- <span><span class="issued-items__label">Issued</span> {{ standardFormatDateTime(c.createdAt) }}</span>
41
- <span><span class="issued-items__label">Return by</span> {{ c.returnDate ? returnDayText(c.returnDate) : "—" }}</span>
42
- <span v-if="c.status !== 'out' && c.closedAt"><span class="issued-items__label">{{ c.status === "returned" ? "Returned" : "Closed" }}</span> {{ standardFormatDateTime(c.closedAt) }}</span>
43
- </div>
44
- <!-- DV-1787: the holder asks to return their own item from here (e.g. before Submit for review). -->
45
- <v-btn
46
- v-if="isMine(c) && !c.returnRequest"
47
- size="small"
48
- variant="tonal"
49
- color="primary"
50
- class="text-none mt-1"
51
- prepend-icon="mdi-keyboard-return"
52
- @click="openAsk(c)"
53
- >
54
- Ask to return
55
- </v-btn>
56
- </div>
27
+ </span>
28
+ <v-icon v-if="g.overdue" icon="mdi-alarm" color="error" size="18" class="mr-1" />
29
+ <v-icon v-else-if="g.asked" icon="mdi-keyboard-return" color="primary" size="18" class="mr-1" />
30
+ <v-icon icon="mdi-chevron-right" size="20" class="text-medium-emphasis" />
31
+ </button>
57
32
  </div>
58
- <InventoryCheckoutReturnDialog v-model="ask.show" :row="ask.row" mode="ask" @done="load" />
33
+
34
+ <!-- DV-1787: the item's details (totals, serial table, Received / Not Received / Ask to Return) -->
35
+ <InventoryCheckoutDetail v-model="detail.show" :rows="openRows" :subtitle="openRows[0]?.workOrderNumber || ''" @changed="load" />
59
36
  </div>
60
37
  </template>
61
38
 
62
39
  <script setup lang="ts">
63
40
  import useInventory from "../../composables/useInventory";
64
- import useUtils from "../../composables/useUtils";
65
41
  import { qtyUnit } from "../../utils/inventory-ack";
66
- import { checkoutChip, returnDayKey, RETURN_ASKED_INFO } from "../../utils/inventory-checkout";
67
42
 
68
43
  const props = defineProps({
69
44
  /** One of the two: the work order, or the feedback whose attached work orders are shown. */
@@ -76,7 +51,6 @@ const props = defineProps({
76
51
  showCompletionBlock: { type: Boolean, default: false },
77
52
  });
78
53
 
79
- const { standardFormatDate, standardFormatDateTime } = useUtils();
80
54
  const items = ref<TInventoryCheckout[]>([]);
81
55
  const requireReturn = ref(false);
82
56
  // A feedback can have more than one work order (re-opened): say which one each item was for.
@@ -87,15 +61,50 @@ const blocking = computed(() => props.showCompletionBlock && requireReturn.value
87
61
  const emit = defineEmits<{ blocking: [boolean] }>();
88
62
  watch(() => requireReturn.value && blockingCount.value > 0, (v) => emit("blocking", v), { immediate: true });
89
63
 
90
- const returnDayText = (d: string) => standardFormatDate(returnDayKey(d));
91
-
92
- // The signed-in person's own items still out: they can ask to return them here.
93
- const { currentUser } = useLocalAuth();
94
- const me = computed(() => String(currentUser.value?._id ?? ""));
95
- const isMine = (c: TInventoryCheckout) => c.status === "out" && !!me.value && String(c.holder) === me.value;
96
- const mineOut = computed(() => items.value.filter((c) => isMine(c) && !c.returnRequest));
97
- const ask = reactive({ show: false, row: null as TInventoryCheckout | null });
98
- const openAsk = (row: TInventoryCheckout) => Object.assign(ask, { show: true, row });
64
+ // DV-1787: one line per item (and work order, when the feedback has several).
65
+ // colour per status, as in the details: with the person amber, return asked blue, returned green, written off red
66
+ const ENDED_WORDS: [string, string, string][] = [
67
+ ["returned", "returned", "text-success"],
68
+ ["written_off", "written off", "text-error"],
69
+ ["used", "used", "text-medium-emphasis"],
70
+ ];
71
+ const n = (v: unknown) => Number(v) || 0;
72
+ const groups = computed(() => {
73
+ const map = new Map<string, TInventoryCheckout[]>();
74
+ for (const c of items.value) {
75
+ const key = `${c.item}:${showNumber.value ? c.workOrder ?? "" : ""}`;
76
+ map.set(key, [...(map.get(key) ?? []), c]);
77
+ }
78
+ return [...map.entries()].map(([key, rows]) => {
79
+ const unit = rows[0].unit;
80
+ const withWhom = new Map<string, number>();
81
+ // With whom (not counting what is already asked to return), then asked, then what ended - they add up to what was issued.
82
+ for (const c of rows) {
83
+ const held = c.status === "out" ? Math.max(0, c.outQty - (c.returnAsked?.qty ?? 0)) : 0;
84
+ if (held > 0) withWhom.set(c.holderName, (withWhom.get(c.holderName) ?? 0) + held);
85
+ }
86
+ const parts = [...withWhom.entries()].map(([who, q]) => ({ text: `${qtyUnit(q, unit)} with ${who}`, cls: "text-warning" }));
87
+ const askedQty = rows.reduce((t, c) => t + (c.status === "out" ? (c.returnAsked?.qty ?? 0) : 0), 0);
88
+ if (askedQty) parts.push({ text: `${askedQty} return asked`, cls: "text-primary" });
89
+ for (const [k, word, cls] of ENDED_WORDS) {
90
+ const q = rows.reduce((s, c) => s + n(c.ended?.[k]), 0);
91
+ if (q) parts.push({ text: `${q} ${word}`, cls });
92
+ }
93
+ return {
94
+ key,
95
+ itemName: rows[0].itemName,
96
+ workOrderNumber: rows[0].workOrderNumber,
97
+ parts,
98
+ overdue: rows.some((c) => c.status === "out" && c.overdue),
99
+ asked: rows.some((c) => c.status === "out" && c.returnRequest),
100
+ rows,
101
+ };
102
+ });
103
+ });
104
+ const detail = reactive({ show: false, key: "" });
105
+ const openGroup = (key: string) => Object.assign(detail, { show: true, key });
106
+ const openGroupRow = computed(() => groups.value.find((g) => g.key === detail.key));
107
+ const openRows = computed(() => openGroupRow.value?.rows ?? []);
99
108
 
100
109
  async function load() {
101
110
  if (!props.workOrderId && !props.feedbackId) return;
@@ -116,19 +125,24 @@ defineExpose({ load });
116
125
  .issued-items {
117
126
  margin-top: 16px;
118
127
  }
119
- .issued-items__row {
120
- padding: 8px 0;
128
+ .issued-items__sum {
129
+ display: flex;
130
+ align-items: center;
131
+ width: 100%;
132
+ text-align: left;
133
+ padding: 8px 4px;
121
134
  border-bottom: 1px solid rgba(var(--v-border-color), var(--v-border-opacity));
135
+ border-radius: 4px;
122
136
  }
123
- .issued-items__row:last-child {
137
+ .issued-items__sum:last-child {
124
138
  border-bottom: 0;
125
139
  }
126
- .issued-items__top {
127
- display: flex;
128
- flex-wrap: wrap;
129
- align-items: center;
130
- justify-content: space-between;
131
- gap: 4px 8px;
140
+ .issued-items__sum:hover {
141
+ background: rgba(var(--v-theme-on-surface), 0.04);
142
+ }
143
+ .issued-items__sum-text {
144
+ flex: 1;
145
+ min-width: 0;
132
146
  }
133
147
  .issued-items__name {
134
148
  font-weight: 500;
@@ -136,18 +150,7 @@ defineExpose({ load });
136
150
  overflow-wrap: anywhere;
137
151
  }
138
152
  .issued-items__meta {
139
- font-size: 0.8125rem;
153
+ font-size: 0.875rem;
140
154
  margin-top: 2px;
141
155
  }
142
- .issued-items__dates {
143
- display: flex;
144
- flex-wrap: wrap;
145
- gap: 2px 16px;
146
- font-size: 0.75rem;
147
- margin-top: 2px;
148
- color: rgba(var(--v-theme-on-surface), var(--v-medium-emphasis-opacity));
149
- }
150
- .issued-items__label {
151
- color: rgba(var(--v-theme-on-surface), var(--v-disabled-opacity));
152
- }
153
156
  </style>
@@ -62,8 +62,9 @@ export default function useInventory() {
62
62
  api(`/stores/${store}/counts`, { method: "POST", body }),
63
63
  issue: (store: string, body: Record<string, any>) => api(`/stores/${store}/issue`, { method: "POST", body }),
64
64
  /** DV-1787: a store keeper takes back one checked-out item (or accepts the holder's request for it). */
65
- returnCheckout: (checkout: string, note = "", serials?: string[]) =>
66
- api(`/checkouts/${checkout}/return`, { method: "POST", body: { note, ...(serials?.length ? { serials } : {}) } }),
65
+ /** `noSerialQty` given: only the chosen serials plus that many units without a serial come back. */
66
+ returnCheckout: (checkout: string, note = "", serials?: string[], noSerialQty?: number) =>
67
+ api(`/checkouts/${checkout}/return`, { method: "POST", body: { note, ...(serials?.length ? { serials } : {}), ...(noSerialQty !== undefined ? { noSerialQty } : {}) } }),
67
68
  /** DV-1787: an item's serial numbers with their history, and adding serials to units on the shelf. */
68
69
  getSerials: (item: string, status: "in_store" | "out" | "written_off" | "used" | "all" | "mine" = "all") =>
69
70
  api<{ items: TInventorySerial[]; inStore: number; onHand: number }>(`/items/${item}/serials`, { query: status === "mine" ? { mine: true } : { status } }),
@@ -72,8 +73,8 @@ export default function useInventory() {
72
73
  changeReturnDate: (checkout: string, returnDate: string | null, reason = "") =>
73
74
  api(`/checkouts/${checkout}/return-date`, { method: "POST", body: { returnDate, reason } }),
74
75
  /** DV-1787: the holder asks to return one checked-out item. */
75
- requestCheckoutReturn: (checkout: string, note = "", serials?: string[]) =>
76
- api(`/checkouts/${checkout}/return-request`, { method: "POST", body: { note, ...(serials?.length ? { serials } : {}) } }),
76
+ requestCheckoutReturn: (checkout: string, note = "", serials?: string[], noSerialQty?: number) =>
77
+ api(`/checkouts/${checkout}/return-request`, { method: "POST", body: { note, ...(serials?.length ? { serials } : {}), ...(noSerialQty !== undefined ? { noSerialQty } : {}) } }),
77
78
  /** DV-1787: the items issued for a work order (or a feedback's work orders), and whether they block completing it. */
78
79
  getWorkOrderCheckouts: (query: { workOrder?: string; feedback?: string }) =>
79
80
  api<{ items: TInventoryCheckout[]; requireReturn: boolean }>(`/work-order-checkouts`, { query }),
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.737",
5
+ "version": "4.97.1-staging.738",
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.",
@@ -280,6 +280,20 @@ declare type TInventoryCheckout = {
280
280
  daysOverdue: number;
281
281
  /** A return the holder asked for, waiting for a store keeper (its id), or null. */
282
282
  returnRequest?: string | null;
283
+ /** The issue (request) it came from: Received / Not received act on it. */
284
+ request?: string;
285
+ /** DV-1787: false while the person has not tapped Received for its issue yet (no Ask to return until then). */
286
+ received?: boolean;
287
+ /** DV-1787: its issue's Received step - awaiting, not_received (the person said they did not get it), or received. */
288
+ ackStatus?: "awaiting" | "not_received" | "received";
289
+ /** DV-1787: what is asked to return on it so far (requests naming it): how many, and which serial ids. */
290
+ returnAsked?: { qty: number; serials: string[] } | null;
291
+ /** DV-1787 (work order / feedback list): how much of it ended so far, by how (returned, written_off, used, handed_over). */
292
+ ended?: Partial<Record<"returned" | "written_off" | "used" | "handed_over" | "closed", number>>;
293
+ /** DV-1787 (work order / feedback list): serial numbers that left it - how and when. */
294
+ endedSerials?: { serial: string; type: "returned" | "written_off" | "used" | "handed_over" | "closed"; at: string; toName?: string }[];
295
+ /** DV-1787 (work order / feedback list): units without a serial that left it, per step. */
296
+ endedPlain?: { type: "returned" | "written_off" | "used" | "handed_over" | "closed"; qty: number; at: string; toName?: string }[];
283
297
  /** Serial numbers still out on it. */
284
298
  serials?: { _id: string; serial: string }[];
285
299
  /** Return date set, changed or cleared after the issue (newest last). */
@@ -30,8 +30,15 @@ const ENDED: Record<string, TChip> = {
30
30
  };
31
31
 
32
32
  /** Out / Due today / Overdue N days, or how it ended - with `info`, what the status means (hover). */
33
- export function checkoutChip(c: { status: string; overdue?: boolean; daysOverdue?: number; returnDate?: string | null }): TChip {
33
+ export function checkoutChip(c: { status: string; overdue?: boolean; daysOverdue?: number; returnDate?: string | null; received?: boolean; ackStatus?: string }): TChip {
34
34
  if (c.status !== "out") return ENDED[c.status] ?? ENDED.closed;
35
+ // DV-1787: not received yet - it is not with the person until they tap Received.
36
+ if (c.received === false && c.ackStatus === "not_received") {
37
+ return { text: "Not Received", color: "error", icon: "mdi-alert-circle-outline", info: "The person tapped Not Received: they say they did not get it. The store keeper checks and takes it back; if it turns up, they tap Received." };
38
+ }
39
+ if (c.received === false) {
40
+ return { text: "Pending Receipt", color: "grey", icon: "mdi-timer-sand", info: "Issued, but the person has not tapped Received or Not Received yet. They can ask to return it only after Received." };
41
+ }
35
42
  if (c.overdue) {
36
43
  const n = c.daysOverdue ?? 0;
37
44
  return {
@@ -62,3 +69,45 @@ export function checkoutChip(c: { status: string; overdue?: boolean; daysOverdue
62
69
 
63
70
  /** "Return asked": the holder asked to return it; a store keeper accepts it when they have it. */
64
71
  export const RETURN_ASKED_INFO = "The person asked to return it. It stays with them until a store keeper accepts the return.";
72
+
73
+ /**
74
+ * DV-1787: how much of a checked-out row can still be asked to return. A row asked for in parts
75
+ * (returnAsked) has the rest left; a row marked by a Return to store from My Stock counts as asked.
76
+ */
77
+ export function askLeft(c: { status: string; outQty: number; received?: boolean; returnRequest?: string | null; returnAsked?: { qty: number } | null }): number {
78
+ // Not received yet: it is not with them, so nothing to ask to return.
79
+ if (c.status !== "out" || c.received === false) return 0;
80
+ if (c.returnAsked) return Math.max(0, c.outQty - c.returnAsked.qty);
81
+ return c.returnRequest ? 0 : c.outQty;
82
+ }
83
+
84
+ /** DV-1787: what is asked to return on a row, e.g. "2 pcs · S/N AG-0001 + 1 without serial number". */
85
+ export function askedText(c: { unit: string; serials?: { _id: string; serial: string }[]; returnAsked?: { qty: number; serials: string[] } | null }): string {
86
+ const a = c.returnAsked;
87
+ if (!a?.qty) return "";
88
+ const names = (c.serials ?? [])
89
+ .filter((s) => a.serials.includes(String(s._id)))
90
+ .map((s) => s.serial)
91
+ .sort((x, y) => x.localeCompare(y, undefined, { numeric: true }));
92
+ const plain = Math.max(0, a.qty - a.serials.length);
93
+ const what = [names.length ? `S/N ${names.join(", ")}` : "", plain ? `${plain} without serial number` : ""].filter(Boolean).join(" + ");
94
+ return `${a.qty} ${c.unit || "pcs"}${what ? ` · ${what}` : ""}`;
95
+ }
96
+
97
+ /**
98
+ * DV-1787: totals of checked-out rows by state (Not Returned, Return Asked, Returned, Written Off,
99
+ * Used) - Not Returned and Returned always, the others when there are any.
100
+ */
101
+ export function checkoutStats(rows: { status: string; outQty: number; returnAsked?: { qty: number } | null; ended?: Partial<Record<string, number>> }[]) {
102
+ const n = (v: unknown) => Number(v) || 0;
103
+ const sum = (f: (c: (typeof rows)[number]) => number) => rows.reduce((t, c) => t + f(c), 0);
104
+ const list = [
105
+ // Not Returned leaves out what is already asked to return, so the totals add up to what was issued.
106
+ { label: "Not Returned", n: sum((c) => (c.status === "out" ? Math.max(0, c.outQty - (c.returnAsked?.qty ?? 0)) : 0)), cls: "text-warning" },
107
+ { label: "Return Asked", n: sum((c) => (c.status === "out" ? (c.returnAsked?.qty ?? 0) : 0)), cls: "text-primary" },
108
+ { label: "Returned", n: sum((c) => n(c.ended?.returned)), cls: "text-success" },
109
+ { label: "Written Off", n: sum((c) => n(c.ended?.written_off)), cls: "text-error" },
110
+ { label: "Used", n: sum((c) => n(c.ended?.used)), cls: "" },
111
+ ];
112
+ return list.filter((x, i) => i === 0 || i === 2 || x.n > 0);
113
+ }