@7365admin1/layer-common 4.180.1 → 4.181.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.181.0
4
+
5
+ ### Minor Changes
6
+
7
+ - fa8ed60: Daily Checklist and Extra Checks: "Download report" (PDF or Excel), the same reports as the five trade mobile apps
8
+
9
+ - Daily Checklist summary, area and item detail, items needing attention, extra checks, and a new "Tasks with photos" report (photos drawn in the PDF, linked in Excel)
10
+ - every report names who generated it: name and account email; task rows say who did each item
11
+ - date range presets (today, last 7 days, this month, custom, up to 92 days), Singapore days
12
+
13
+ ### Patch Changes
14
+
15
+ - fa8ed60: Inventory: store admins see My Stock and can record usage of stock they hold.
16
+
17
+ ## 4.180.2
18
+
19
+ ### Patch Changes
20
+
21
+ - c78dd50: Mobile table cards: keep StatusChip pills (role, status) on one line.
22
+
3
23
  ## 4.180.1
4
24
 
5
25
  ### Patch Changes
@@ -3972,11 +3992,11 @@ Monthly report: a month that had patrols opens the list of that month's patrol r
3972
3992
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
3973
3993
  own rule from two endpoints the console already calls, unprojected:
3974
3994
 
3975
- GET /api/members/user/:user/app/admin the Seven365 staff membership
3976
- GET /api/roles/id/:role that membership's role document
3995
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
3996
+ GET /api/roles/id/:role that membership's role document
3977
3997
 
3978
- owner = member.type === "admin" && role.type === "admin" && role.default === true
3979
- staff = member.type === "admin" && role.type === "admin"
3998
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
3999
+ staff = member.type === "admin" && role.type === "admin"
3980
4000
 
3981
4001
  `role.default` is the marker because it is the only property of a platform
3982
4002
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -1227,8 +1227,9 @@ select option {
1227
1227
  }
1228
1228
 
1229
1229
  /* Long values (emails, sync messages) wrap inside the card instead of
1230
- running off it; chips and buttons keep their one-line shape. */
1231
- .v-data-table__td-value :is(span, div, p, a):not(.v-chip):not(.v-chip *):not(.v-btn):not(.v-btn *) {
1230
+ running off it; chips (Vuetify's and our StatusChip) and buttons keep
1231
+ their one-line shape: a StatusChip role pill broke as "Range / r". */
1232
+ .v-data-table__td-value :is(span, div, p, a):not(.v-chip):not(.v-chip *):not(.status-chip):not(.status-chip *):not(.v-btn):not(.v-btn *) {
1232
1233
  white-space: normal !important;
1233
1234
  overflow: visible;
1234
1235
  text-overflow: clip;
@@ -0,0 +1,367 @@
1
+ <!--
2
+ "Download report" for the Daily Checklist and the Extra Checks, the same as
3
+ the five trade mobile apps (owner, 12-13 Nov 2026): pick the report, the
4
+ dates and PDF or Excel, then Generate. It reads the checklist through the
5
+ same calls the mobile apps make and builds the same report
6
+ (utils/checklist-report). Reports are always English (owner rule, 23 Oct).
7
+ The parent decides who sees the button (`canDownload`); the server still
8
+ limits every list it reads.
9
+ -->
10
+ <template>
11
+ <v-btn
12
+ v-if="canDownload"
13
+ class="text-none screen-btn-ghost"
14
+ variant="flat"
15
+ prepend-icon="mdi-download"
16
+ data-test="checklist-report-open"
17
+ @click="open = true"
18
+ >
19
+ Download report
20
+ </v-btn>
21
+
22
+ <v-dialog v-model="open" max-width="620" :persistent="busy" scrollable>
23
+ <v-card>
24
+ <v-card-title class="d-flex align-center">
25
+ Download report
26
+ <v-spacer />
27
+ <v-btn icon="mdi-close" variant="text" :disabled="busy" aria-label="Close" @click="open = false" />
28
+ </v-card-title>
29
+ <v-card-text>
30
+ <div class="cr-h">1. Which report?</div>
31
+ <v-radio-group v-model="kind" hide-details :disabled="busy" class="mb-2">
32
+ <v-radio v-for="k in REPORT_KINDS" :key="k.kind" :value="k.kind">
33
+ <template #label>
34
+ <div>
35
+ <div class="font-weight-bold">{{ k.name }}</div>
36
+ <div class="cr-help">{{ k.help }}</div>
37
+ </div>
38
+ </template>
39
+ </v-radio>
40
+ </v-radio-group>
41
+
42
+ <div class="cr-h">2. Which dates?</div>
43
+ <div class="d-flex flex-wrap ga-2 mb-3">
44
+ <v-chip
45
+ v-for="p in PRESETS"
46
+ :key="p.value"
47
+ :color="preset === p.value ? 'primary' : undefined"
48
+ :variant="preset === p.value ? 'flat' : 'outlined'"
49
+ :disabled="busy"
50
+ @click="pickPreset(p.value)"
51
+ >
52
+ {{ p.title }}
53
+ </v-chip>
54
+ </div>
55
+ <div class="d-flex flex-wrap ga-3">
56
+ <v-text-field
57
+ v-model="range.from"
58
+ type="date"
59
+ label="From"
60
+ density="compact"
61
+ hide-details
62
+ :disabled="busy"
63
+ style="min-width: 180px"
64
+ @update:model-value="preset = 'custom'"
65
+ />
66
+ <v-text-field
67
+ v-model="range.to"
68
+ type="date"
69
+ label="To"
70
+ density="compact"
71
+ hide-details
72
+ :disabled="busy"
73
+ style="min-width: 180px"
74
+ @update:model-value="preset = 'custom'"
75
+ />
76
+ </div>
77
+ <div class="cr-help mt-1 mb-3">Up to {{ MAX_RANGE_DAYS }} days in one report. Dates are Singapore days.</div>
78
+
79
+ <div class="cr-h">3. Which file?</div>
80
+ <v-radio-group v-model="format" inline hide-details :disabled="busy">
81
+ <v-radio value="pdf" label="PDF - easy to read and print" />
82
+ <v-radio value="excel" label="Excel - opens in Excel or Google Sheets" />
83
+ </v-radio-group>
84
+ <div v-if="kind === 'photos' && format === 'pdf'" class="cr-help mt-1">
85
+ The PDF shows up to {{ MAX_PDF_PHOTOS }} photos; the Excel file links every photo.
86
+ </div>
87
+
88
+ <v-alert v-if="message" :type="message.tone" variant="tonal" density="compact" class="mt-4">
89
+ {{ message.text }}
90
+ </v-alert>
91
+ <div v-if="busy" class="mt-4 d-flex align-center ga-3">
92
+ <v-progress-circular indeterminate size="20" width="2" />
93
+ <span>{{ progressText }}</span>
94
+ </div>
95
+ </v-card-text>
96
+ <v-card-actions>
97
+ <v-spacer />
98
+ <v-btn class="text-none screen-btn-ghost" variant="flat" :disabled="busy" @click="open = false">Close</v-btn>
99
+ <v-btn
100
+ class="text-none screen-btn-primary"
101
+ variant="flat"
102
+ :loading="busy"
103
+ data-test="checklist-report-generate"
104
+ @click="generate"
105
+ >
106
+ Generate report
107
+ </v-btn>
108
+ </v-card-actions>
109
+ </v-card>
110
+ </v-dialog>
111
+ </template>
112
+
113
+ <script setup lang="ts">
114
+ import type { PropType } from "vue";
115
+ import jsPDF from "jspdf";
116
+ import { useTheme } from "vuetify";
117
+ import {
118
+ MAX_RANGE_DAYS,
119
+ buildReport,
120
+ buildVisits,
121
+ presetRange,
122
+ rangeProblem,
123
+ reportFileName,
124
+ type DateRange,
125
+ type RangePreset,
126
+ type ReportFormat,
127
+ type ReportKind,
128
+ } from "../utils/checklist-report/checklist-report.ts";
129
+ import { loadChecklistData } from "../utils/checklist-report/checklist-report-load.ts";
130
+ import {
131
+ XLSX_MIME,
132
+ drawReportPdf,
133
+ reportToXlsx,
134
+ type PdfDoc,
135
+ type PdfImage,
136
+ } from "../utils/checklist-report/checklist-report-files.ts";
137
+ import { saveFile } from "../utils/vehicle-qr-export.ts";
138
+ import useCleaningSchedules from "../composables/useCleaningSchedules";
139
+
140
+ const props = defineProps({
141
+ orgId: { type: String, required: true },
142
+ site: { type: String, required: true },
143
+ serviceType: { type: String, required: true },
144
+ /** The report picked when the dialog opens: the Extra Checks list opens on "extra". */
145
+ report: { type: String as PropType<ReportKind>, default: "summary" },
146
+ canDownload: { type: Boolean, default: false },
147
+ });
148
+
149
+ const REPORT_KINDS: { kind: ReportKind; name: string; help: string }[] = [
150
+ { kind: "summary", name: "Daily Checklist summary", help: "One line per day: areas, visits done, items done, items needing attention and how complete the day was." },
151
+ { kind: "detail", name: "Area and item detail", help: "Every item in every area: Done or Needs attention, the time, who did it and the remark." },
152
+ { kind: "attention", name: "Items needing attention", help: "Only the items marked Needs attention: a follow-up list." },
153
+ { kind: "extra", name: "Extra checks", help: "Each extra check: area, scheduled time, whether it was done or missed, and who did it." },
154
+ { kind: "photos", name: "Tasks with photos", help: "Each task that has photos: area, time, status, who did it, the remark and the photos themselves." },
155
+ ];
156
+
157
+ const PRESETS: { value: RangePreset; title: string }[] = [
158
+ { value: "today", title: "Today" },
159
+ { value: "last7", title: "Last 7 days" },
160
+ { value: "month", title: "This month" },
161
+ { value: "custom", title: "Custom" },
162
+ ];
163
+
164
+ /** The trade app's own name on the report, as the mobile apps print it. */
165
+ const BRAND_NAMES: Record<string, string> = {
166
+ cleaning_services: "iClean365",
167
+ mechanical_electrical_services: "iM&E365",
168
+ pest_control_services: "iPest365",
169
+ pool_maintenance_services: "iPool365",
170
+ landscaping_services: "iGarden365",
171
+ };
172
+
173
+ // ponytail: photos are shrunk and embedded one by one; past this many the PDF
174
+ // gets slow and large, so the rest are linked boxes (Excel links all of them).
175
+ const MAX_PDF_PHOTOS = 300;
176
+ const PHOTO_EDGE = 640;
177
+
178
+ const open = ref(false);
179
+ const kind = ref<ReportKind>(props.report);
180
+ const preset = ref<RangePreset>("last7");
181
+ const range = ref<DateRange>(presetRange("last7"));
182
+ const format = ref<ReportFormat>("pdf");
183
+ const busy = ref(false);
184
+ const progress = ref<{ step: "reading" | "photos" | "building"; done: number; total: number } | null>(null);
185
+ const message = ref<{ tone: "error" | "info" | "success"; text: string } | null>(null);
186
+
187
+ watch(open, (isOpen) => {
188
+ if (isOpen) {
189
+ kind.value = props.report;
190
+ message.value = null;
191
+ }
192
+ });
193
+
194
+ function pickPreset(next: RangePreset) {
195
+ preset.value = next;
196
+ message.value = null;
197
+ if (next !== "custom") range.value = presetRange(next);
198
+ }
199
+
200
+ const progressText = computed(() => {
201
+ const p = progress.value;
202
+ if (!p) return "Reading the checklist...";
203
+ if (p.step === "building") return "Building the file...";
204
+ if (p.step === "photos") return `Adding photos: ${p.done} of ${p.total}`;
205
+ return p.total > 0 ? `Reading the checklist: day ${p.done} of ${p.total}` : "Reading the checklist...";
206
+ });
207
+
208
+ /** "2026-11-12" as the date the API reads: that day's midnight UTC, as the mobile apps send it. */
209
+ const apiDay = (day: string) => {
210
+ const [y, m, d] = day.split("-").map(Number);
211
+ return new Date(Date.UTC(y, m - 1, d)).toISOString();
212
+ };
213
+
214
+ const { getCleaningSchedules, getScheduleAreas, getUnitCleanerChecklist } = useCleaningSchedules();
215
+ const { getFileUrl } = useFile();
216
+ const { currentUser } = useLocalAuth();
217
+ const theme = useTheme();
218
+ // The same calls as useOrg().getById / useSite().getSiteById, without useOrg's
219
+ // side effect of resetting the shared "currentOrg".
220
+ const getOrg = (id: string) => useNuxtApp().$api<Record<string, any>>(`/api/organizations/id/${id}`);
221
+ const getSiteById = (id: string) => useNuxtApp().$api<Record<string, any>>(`/api/sites/${id}`);
222
+
223
+ /** The company and site names for the header; a blank one is printed as "-". */
224
+ async function names(): Promise<{ company: string; site: string }> {
225
+ const [org, site] = await Promise.allSettled([getOrg(props.orgId), getSiteById(props.site)]);
226
+ return {
227
+ company: org.status === "fulfilled" ? String(org.value?.name ?? "") : "",
228
+ site: site.status === "fulfilled" ? String(site.value?.name ?? "") : "",
229
+ };
230
+ }
231
+
232
+ /** One photo, shrunk to a JPEG for the PDF; null when it cannot be read. Same-origin (/api/public proxy), so no CORS. */
233
+ async function loadPhoto(id: string): Promise<PdfImage | null> {
234
+ try {
235
+ const res = await fetch(`/api/public/${encodeURIComponent(id)}`);
236
+ if (!res.ok) return null;
237
+ const bitmap = await createImageBitmap(await res.blob());
238
+ const k = Math.min(1, PHOTO_EDGE / Math.max(bitmap.width, bitmap.height));
239
+ const canvas = document.createElement("canvas");
240
+ canvas.width = Math.max(1, Math.round(bitmap.width * k));
241
+ canvas.height = Math.max(1, Math.round(bitmap.height * k));
242
+ const ctx = canvas.getContext("2d");
243
+ if (!ctx) return null;
244
+ ctx.fillStyle = "#fff";
245
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
246
+ ctx.drawImage(bitmap, 0, 0, canvas.width, canvas.height);
247
+ bitmap.close();
248
+ return { data: canvas.toDataURL("image/jpeg", 0.75), width: canvas.width, height: canvas.height };
249
+ } catch {
250
+ return null;
251
+ }
252
+ }
253
+
254
+ async function loadPhotos(ids: string[]): Promise<Map<string, PdfImage>> {
255
+ const list = [...new Set(ids)].slice(0, MAX_PDF_PHOTOS);
256
+ const out = new Map<string, PdfImage>();
257
+ let next = 0;
258
+ let done = 0;
259
+ progress.value = { step: "photos", done: 0, total: list.length };
260
+ const lane = async () => {
261
+ while (next < list.length) {
262
+ const id = list[next++];
263
+ const img = await loadPhoto(id);
264
+ if (img) out.set(id, img);
265
+ progress.value = { step: "photos", done: ++done, total: list.length };
266
+ }
267
+ };
268
+ await Promise.all(Array.from({ length: Math.min(6, list.length) }, lane));
269
+ return out;
270
+ }
271
+
272
+ async function generate() {
273
+ const problem = rangeProblem(range.value);
274
+ if (problem) {
275
+ message.value = {
276
+ tone: "error",
277
+ text:
278
+ problem === "order"
279
+ ? "The From date must be on or before the To date."
280
+ : problem === "tooLong"
281
+ ? `Please choose ${MAX_RANGE_DAYS} days or fewer.`
282
+ : "Please choose both dates.",
283
+ };
284
+ return;
285
+ }
286
+
287
+ busy.value = true;
288
+ message.value = null;
289
+ progress.value = null;
290
+ const chosen = { ...range.value };
291
+ try {
292
+ const serviceType = props.serviceType;
293
+ const [days, where] = await Promise.all([
294
+ loadChecklistData(
295
+ {
296
+ listDays: (page, limit) =>
297
+ getCleaningSchedules({
298
+ site: props.site,
299
+ page,
300
+ limit,
301
+ startDate: apiDay(chosen.from),
302
+ endDate: apiDay(chosen.to),
303
+ serviceType,
304
+ }),
305
+ listAreas: (dayId, page, limit) => getScheduleAreas({ scheduleAreaId: dayId, page, limit, serviceType }),
306
+ listVisits: (areaId, page, limit) => getUnitCleanerChecklist({ scheduleAreaId: areaId, page, limit, serviceType }),
307
+ },
308
+ { onProgress: (done, total) => (progress.value = { step: "reading", done, total }) },
309
+ ),
310
+ names(),
311
+ ]);
312
+
313
+ const now = new Date();
314
+ const user = currentUser.value;
315
+ const report = buildReport(kind.value, buildVisits(days, chosen, now), {
316
+ ...where,
317
+ range: chosen,
318
+ generatedAt: now,
319
+ generatedBy: [user?.name, user?.email ? `(${user.email})` : ""].filter(Boolean).join(" "),
320
+ });
321
+ if (report.empty) {
322
+ message.value = {
323
+ tone: "info",
324
+ text: kind.value === "extra" ? "No extra checks in these dates." : "No checklist records in these dates.",
325
+ };
326
+ return;
327
+ }
328
+
329
+ const brand = {
330
+ name: BRAND_NAMES[serviceType] ?? "iService365",
331
+ color: String(theme.current.value.colors.primary ?? "#E0241C"),
332
+ };
333
+ const fileName = reportFileName(report, chosen, format.value);
334
+ if (format.value === "excel") {
335
+ progress.value = { step: "building", done: 0, total: 0 };
336
+ saveFile(fileName, reportToXlsx(report, brand, getFileUrl), XLSX_MIME);
337
+ } else {
338
+ const ids = report.sections.flatMap((s) => (s.photos ?? []).flat());
339
+ const images = ids.length > 0 ? await loadPhotos(ids) : new Map<string, PdfImage>();
340
+ progress.value = { step: "building", done: 0, total: 0 };
341
+ const pdf = new jsPDF({ unit: "mm", format: "a4", orientation: "landscape" });
342
+ drawReportPdf(pdf as unknown as PdfDoc, report, brand, images, getFileUrl);
343
+ pdf.save(fileName);
344
+ }
345
+ message.value = { tone: "success", text: `Your report is ready: ${fileName} (check your Downloads folder).` };
346
+ } catch (error: any) {
347
+ message.value = {
348
+ tone: "error",
349
+ text: error?.data?.message || "We could not create the report. Please try again.",
350
+ };
351
+ } finally {
352
+ busy.value = false;
353
+ progress.value = null;
354
+ }
355
+ }
356
+ </script>
357
+
358
+ <style scoped>
359
+ .cr-h {
360
+ font-weight: 700;
361
+ margin: 4px 0 6px;
362
+ }
363
+ .cr-help {
364
+ font-size: 0.85rem;
365
+ color: rgba(var(--v-theme-on-surface), 0.7);
366
+ }
367
+ </style>
@@ -37,6 +37,12 @@
37
37
  Click a row to see its areas, then an area to see each unit,
38
38
  send a unit back (<strong>Needs redo</strong>) or add a remark.
39
39
  </li>
40
+ <li>
41
+ <strong>Download report</strong> (top right) makes a PDF or Excel
42
+ report for a range of dates: a summary by day, every item, the
43
+ items needing attention, the extra checks, or the tasks with their
44
+ photos.
45
+ </li>
40
46
  <li>
41
47
  <strong>Download PDF</strong> saves that day's report - every
42
48
  area, unit, who ticked it and when - to send to your client.
@@ -75,6 +81,13 @@
75
81
  </template>
76
82
 
77
83
  <template #actions>
84
+ <ChecklistReportButton
85
+ :org-id="orgId"
86
+ :site="site"
87
+ :service-type="serviceType"
88
+ report="summary"
89
+ :can-download="canDownloadSchedule"
90
+ />
78
91
  <v-btn
79
92
  v-if="showCreateToday"
80
93
  class="text-none screen-btn-primary"
@@ -941,6 +941,18 @@ const updateActionText = computed(() => {
941
941
  white-space: normal;
942
942
  max-width: 300px;
943
943
  }
944
+ /* Phone card layout: the cell is ~190 px, so the pill was squeezed to "Rang…".
945
+ Let the role pill keep its width and the site drop to the next line. */
946
+ @media (max-width: 599.98px) {
947
+ .member-access {
948
+ flex-wrap: wrap;
949
+ min-width: 0;
950
+ justify-content: flex-end;
951
+ }
952
+ .member-table :deep(.member-role-chip) {
953
+ flex-shrink: 0;
954
+ }
955
+ }
944
956
  .member-access__more,
945
957
  .member-access__scope {
946
958
  font-size: 12px;
@@ -74,6 +74,15 @@
74
74
  </button>
75
75
  </div>
76
76
 
77
+ <div v-if="tab === 'extra' && canDownloadExtraReport" class="d-flex justify-end mb-2">
78
+ <ChecklistReportButton
79
+ :org-id="orgId"
80
+ :site="siteId"
81
+ :service-type="serviceType"
82
+ report="extra"
83
+ can-download
84
+ />
85
+ </div>
77
86
  <TaskCalendarReadOnly
78
87
  v-if="tab === 'agent'"
79
88
  :site-id="siteId"
@@ -99,6 +108,7 @@
99
108
  </template>
100
109
 
101
110
  <script setup lang="ts">
111
+ import { useCleaningSchedulePermission } from "../composables/useCleaningSchedulePermission";
102
112
  import {
103
113
  pickTaskCalendarTab,
104
114
  taskCalendarWords,
@@ -117,8 +127,16 @@ const props = defineProps({
117
127
  canUpdateScheduleTask: { type: Boolean, default: false },
118
128
  canDeleteScheduleTask: { type: Boolean, default: false },
119
129
  canViewScheduleTaskDetails: { type: Boolean, default: false },
130
+ /**
131
+ * May download the Extra Checks report. Left out, it follows the role's
132
+ * "download-schedule" key, the one that gates the Daily Checklist downloads.
133
+ */
134
+ canDownloadReport: { type: Boolean, default: undefined },
120
135
  });
121
136
 
137
+ const { canDownloadSchedule } = useCleaningSchedulePermission();
138
+ const canDownloadExtraReport = computed(() => props.canDownloadReport ?? canDownloadSchedule.value);
139
+
122
140
  const route = useRoute();
123
141
  const router = useRouter();
124
142
 
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.180.1",
5
+ "version": "4.181.0",
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.",