@7365admin1/layer-common 4.180.2 → 4.182.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 +31 -4
- package/components/BuildingForm.vue +22 -53
- package/components/BuildingManagement/buildings.vue +3 -9
- package/components/BuildingManagement/units.vue +6 -9
- package/components/ChecklistReportButton.vue +367 -0
- package/components/CleaningScheduleMain.vue +13 -0
- package/components/HidUserEnrollment.vue +1 -1
- package/components/PeopleForm.vue +3 -2
- package/components/RolePermissionMain.vue +11 -2
- package/components/SiteSettings.vue +5 -1
- package/components/TaskCalendarMain.vue +18 -0
- package/composables/usePropertyPermission.ts +8 -0
- package/composables/useSecurityUtils.ts +1 -1
- package/composables/useSiteSettings.ts +2 -2
- package/package.json +1 -1
- package/types/building.d.ts +2 -2
- package/utils/building-block.ts +19 -0
- package/utils/checklist-report/checklist-report-files.ts +458 -0
- package/utils/checklist-report/checklist-report-load.ts +99 -0
- package/utils/checklist-report/checklist-report.ts +723 -0
- package/utils/inventory-presets.ts +2 -1
- package/utils/module-routes.ts +55 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @iservice365/layer-common
|
|
2
2
|
|
|
3
|
+
## 4.182.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c015e55: Block No can now carry one letter (12A). Add Block is a text field (digits plus at most one letter) instead of a dropdown capped by the site's number of blocks. People form block lookups keep the letter. Types widened to number or string. Release after core and API-core.
|
|
8
|
+
- 08d0401: Building Management: remove the separate Block Name field. A block is now just its Block No (shown as "Blk N"); the stored name is derived from the number. Units table shows a Block column; the units import hint is updated to Block No, Level, Unit Number.
|
|
9
|
+
- b406923: Property-management role editor can grant incident report add and update rights; the ANPR Camera settings panel is hidden when the client has neither the Vehicle nor the Visitor module.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 9730f45: Module gate: typing the URL of a page whose module the Super Admin removed from a client no longer opens it. Added Pass & Key (keys), Cards and QR Tagging (access-mgmt), service providers, Property Management's Marketplace, CCTV Engine and Security Ops to the route map.
|
|
14
|
+
- Role editor: modules the client's list removed (including a list saved with nothing ticked) are no longer offered.
|
|
15
|
+
|
|
16
|
+
## 4.181.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- fa8ed60: Daily Checklist and Extra Checks: "Download report" (PDF or Excel), the same reports as the five trade mobile apps
|
|
21
|
+
|
|
22
|
+
- 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)
|
|
23
|
+
- every report names who generated it: name and account email; task rows say who did each item
|
|
24
|
+
- date range presets (today, last 7 days, this month, custom, up to 92 days), Singapore days
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- fa8ed60: Inventory: store admins see My Stock and can record usage of stock they hold.
|
|
29
|
+
|
|
3
30
|
## 4.180.2
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
|
@@ -3978,11 +4005,11 @@ Monthly report: a month that had patrols opens the list of that month's patrol r
|
|
|
3978
4005
|
`utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
|
|
3979
4006
|
own rule from two endpoints the console already calls, unprojected:
|
|
3980
4007
|
|
|
3981
|
-
|
|
3982
|
-
|
|
4008
|
+
GET /api/members/user/:user/app/admin the Seven365 staff membership
|
|
4009
|
+
GET /api/roles/id/:role that membership's role document
|
|
3983
4010
|
|
|
3984
|
-
|
|
3985
|
-
|
|
4011
|
+
owner = member.type === "admin" && role.type === "admin" && role.default === true
|
|
4012
|
+
staff = member.type === "admin" && role.type === "admin"
|
|
3986
4013
|
|
|
3987
4014
|
`role.default` is the marker because it is the only property of a platform
|
|
3988
4015
|
staff role no API caller can set - `role.controller.ts` validates create and
|
|
@@ -7,33 +7,14 @@
|
|
|
7
7
|
<v-card-text class="screen-modal__body pa-0">
|
|
8
8
|
<v-form v-model="validForm" :disabled="disable">
|
|
9
9
|
<v-row no-gutters class="px-6 pt-4">
|
|
10
|
-
<v-col cols="12" class="mt-2">
|
|
11
|
-
<v-row no-gutters>
|
|
12
|
-
<InputLabel class="text-capitalize font-weight-bold" title="Block Name" required />
|
|
13
|
-
<v-col cols="12">
|
|
14
|
-
<v-text-field v-model="building.name" class="filter-field" density="comfortable" :rules="[requiredRule]"></v-text-field>
|
|
15
|
-
</v-col>
|
|
16
|
-
</v-row>
|
|
17
|
-
</v-col>
|
|
18
|
-
|
|
19
10
|
<v-col v-if="prop.mode === 'add'" cols="12">
|
|
20
11
|
<v-row>
|
|
21
12
|
<v-col cols="6" class="mt-2">
|
|
22
13
|
<v-row no-gutters>
|
|
23
14
|
<InputLabel class="text-capitalize font-weight-bold" title="Block No." required />
|
|
24
15
|
<v-col cols="12">
|
|
25
|
-
<v-
|
|
26
|
-
|
|
27
|
-
requiredRule,
|
|
28
|
-
() =>
|
|
29
|
-
(building.block && building.block > 0) ||
|
|
30
|
-
'Block is required',
|
|
31
|
-
]" type="number">
|
|
32
|
-
<template v-slot:item="{ props: itemProps, item }">
|
|
33
|
-
<v-list-item v-bind="itemProps" :disabled="item?.raw?.disabled"></v-list-item>
|
|
34
|
-
</template>
|
|
35
|
-
|
|
36
|
-
</v-select>
|
|
16
|
+
<v-text-field v-model.trim="building.block" class="filter-field" density="comfortable"
|
|
17
|
+
placeholder="e.g. 12 or 12A" maxlength="5" :rules="[requiredRule, blockRule]"></v-text-field>
|
|
37
18
|
</v-col>
|
|
38
19
|
</v-row>
|
|
39
20
|
</v-col>
|
|
@@ -206,6 +187,7 @@
|
|
|
206
187
|
|
|
207
188
|
<script setup lang="ts">
|
|
208
189
|
import InputLabel from './InputLabel.vue';
|
|
190
|
+
import { blockLabel, normaliseBlock, BLOCK_NO_MESSAGE } from "../utils/building-block";
|
|
209
191
|
|
|
210
192
|
const prop = defineProps({
|
|
211
193
|
site: {
|
|
@@ -232,40 +214,11 @@ const prop = defineProps({
|
|
|
232
214
|
},
|
|
233
215
|
});
|
|
234
216
|
|
|
235
|
-
const { getSiteById } = useSite();
|
|
236
217
|
const { getFileById } = useFile();
|
|
237
218
|
const { deleteById, batchUpdateLevels } = useBuildingLevel();
|
|
238
219
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const { data: getSiteReq } = useLazyAsyncData(
|
|
242
|
-
"get-site-by-id-" + prop.site,
|
|
243
|
-
async () => getSiteById(prop.site)
|
|
244
|
-
);
|
|
245
|
-
|
|
246
|
-
watchEffect(() => {
|
|
247
|
-
if (getSiteReq.value) {
|
|
248
|
-
site.value = getSiteReq.value;
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
const blocks = computed(() => {
|
|
253
|
-
if (!site.value) return [];
|
|
254
|
-
// return
|
|
255
|
-
// return [ { label: "1", value: 1, disabled: true }, { label: "2", value: 2 }, { label: "3", value: 3 } ];
|
|
256
|
-
const array = Array.from({ length: site.value?.metadata?.block || 0 }, (_, i) => i + 1);
|
|
257
|
-
|
|
258
|
-
const formattedArray = array.map((num) => {
|
|
259
|
-
const isDisabled = prop.blocks.some((block) => block.block === num)
|
|
260
|
-
return {
|
|
261
|
-
label: num.toString(),
|
|
262
|
-
value: num,
|
|
263
|
-
disabled: isDisabled
|
|
264
|
-
};
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
return formattedArray;
|
|
268
|
-
});
|
|
220
|
+
// Block No: digits with at most one letter (12, 12A). The site's "number of blocks" no longer caps it.
|
|
221
|
+
const blockRule = (v: unknown) => normaliseBlock(v) !== null || BLOCK_NO_MESSAGE;
|
|
269
222
|
|
|
270
223
|
const emit = defineEmits(["cancel", "success", "success:create-more", "refresh"]);
|
|
271
224
|
|
|
@@ -400,10 +353,26 @@ async function submit() {
|
|
|
400
353
|
try {
|
|
401
354
|
if (prop.mode === "add") {
|
|
402
355
|
const buildingPayload = { ...building.value };
|
|
356
|
+
// One block field only: the stored name is derived from the number ("Blk 3").
|
|
357
|
+
const blockNo = normaliseBlock(buildingPayload.block);
|
|
358
|
+
if (blockNo === null) {
|
|
359
|
+
message.value = BLOCK_NO_MESSAGE;
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
buildingPayload.block = blockNo;
|
|
363
|
+
if (prop.blocks.some((b) => normaliseBlock(b.block) === blockNo)) {
|
|
364
|
+
message.value = `Block ${blockNo} already exists. Choose a different Block No.`;
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const name = blockLabel(blockNo);
|
|
368
|
+
if (prop.blocks.some((b) => b.name?.trim().toLowerCase() === name.toLowerCase() && b.block !== blockNo)) {
|
|
369
|
+
message.value = `Another block is already named "${name}". Rename it first, or choose a different Block No.`;
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
403
372
|
|
|
404
373
|
let payload: TBuildingPayload = {
|
|
405
374
|
site: buildingPayload.site,
|
|
406
|
-
name
|
|
375
|
+
name,
|
|
407
376
|
block: buildingPayload.block,
|
|
408
377
|
levels: [...newLevelsArray.value],
|
|
409
378
|
buildingFiles: (building.value.buildingFiles as string[] || []).map((id) => ({ id, name: buildingFilesNames.value[id] ?? "" }))
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
<template #prepend-additional>
|
|
23
23
|
<AppField v-model="searchInput" search compact placeholder="Search" klass="app-toolbar__search" />
|
|
24
24
|
</template>
|
|
25
|
+
<template #item.block="{ value }">{{ value ? blockLabel(value) : "" }}</template>
|
|
25
26
|
<template #item.createdAt="{ value }">
|
|
26
27
|
{{ new Date(value).toLocaleDateString() }}
|
|
27
28
|
</template>
|
|
@@ -52,13 +53,9 @@
|
|
|
52
53
|
<v-card width="100%">
|
|
53
54
|
<v-card-text style="max-height: 100vh; overflow-y: auto" class="pb-0">
|
|
54
55
|
<v-row no-gutters class="mb-4">
|
|
55
|
-
<v-col cols="12">
|
|
56
|
-
<strong>Name:</strong> {{ selectedBuilding?.name ?? "N/A" }}
|
|
57
|
-
</v-col>
|
|
58
|
-
|
|
59
56
|
<v-col cols="12">
|
|
60
57
|
<strong>Block:</strong>
|
|
61
|
-
{{ selectedBuilding?.block
|
|
58
|
+
{{ selectedBuilding?.block ? blockLabel(selectedBuilding.block) : "N/A" }}
|
|
62
59
|
</v-col>
|
|
63
60
|
|
|
64
61
|
<v-col cols="12">
|
|
@@ -161,16 +158,13 @@
|
|
|
161
158
|
// Relative import, never Nuxt auto-import: this layer's `utils/` are auto-imported
|
|
162
159
|
// into the consuming apps but not reliably into the layer's own components.
|
|
163
160
|
import { levelCount } from "../../utils/data";
|
|
161
|
+
import { blockLabel } from "../../utils/building-block";
|
|
164
162
|
|
|
165
163
|
|
|
166
164
|
const props = defineProps({
|
|
167
165
|
headers: {
|
|
168
166
|
type: Array as PropType<Array<Record<string, any>>>,
|
|
169
167
|
default: () => [
|
|
170
|
-
{
|
|
171
|
-
title: "Name",
|
|
172
|
-
value: "name",
|
|
173
|
-
},
|
|
174
168
|
{
|
|
175
169
|
title: "Block",
|
|
176
170
|
value: "block",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
v-model="showImport"
|
|
31
31
|
title="Import Blocks, Levels and Units from Excel"
|
|
32
32
|
noun="rows"
|
|
33
|
-
name-label="
|
|
34
|
-
fill-hint="One row per unit:
|
|
33
|
+
name-label="Block / Level / Unit"
|
|
34
|
+
fill-hint="One row per unit: Block No, Level and Unit Number. Pick Level from the dropdown where it already exists. A new Block No creates a new block (Blk 1, Blk 2 ...); an existing block keeps its name."
|
|
35
35
|
duplicate-note="Units already on that level are skipped and left unchanged."
|
|
36
36
|
template-file-name="units-import-template.xlsx"
|
|
37
37
|
:download-template="() => downloadTemplate('building-units', { site })"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
<AppField v-model="searchInput" search compact placeholder="Search" klass="app-toolbar__search" />
|
|
51
51
|
</template>
|
|
52
52
|
<template #item.block="{ value, item }">
|
|
53
|
-
{{ value ?
|
|
53
|
+
{{ value ? blockLabel(value) : "" }}
|
|
54
54
|
</template>
|
|
55
55
|
</TableMain>
|
|
56
56
|
|
|
@@ -174,6 +174,7 @@
|
|
|
174
174
|
|
|
175
175
|
<script setup lang="ts">
|
|
176
176
|
import useImportTemplates from "../../composables/useImportTemplates";
|
|
177
|
+
import { blockLabel } from "../../utils/building-block";
|
|
177
178
|
import { saveBlob } from "../../composables/useInventory";
|
|
178
179
|
import { useDisplay } from 'vuetify/lib/composables/display.mjs';
|
|
179
180
|
|
|
@@ -189,13 +190,9 @@ const props = defineProps({
|
|
|
189
190
|
title: "Level",
|
|
190
191
|
value: "level.name",
|
|
191
192
|
},
|
|
192
|
-
// {
|
|
193
|
-
// title: "Block",
|
|
194
|
-
// value: "block",
|
|
195
|
-
// },
|
|
196
193
|
{
|
|
197
|
-
title: "Block
|
|
198
|
-
value: "
|
|
194
|
+
title: "Block",
|
|
195
|
+
value: "block",
|
|
199
196
|
},
|
|
200
197
|
|
|
201
198
|
// {
|
|
@@ -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"
|
|
@@ -1489,7 +1489,7 @@ type OccupiedLevel = { _id: string; name: string; units?: OccupiedUnit[] };
|
|
|
1489
1489
|
type OccupiedBlock = {
|
|
1490
1490
|
_id: string;
|
|
1491
1491
|
name: string;
|
|
1492
|
-
block: number | null;
|
|
1492
|
+
block: number | string | null;
|
|
1493
1493
|
levels?: OccupiedLevel[];
|
|
1494
1494
|
};
|
|
1495
1495
|
type UnitPerson = {
|