@7365admin1/layer-common 4.97.1-staging.517 → 4.97.1-staging.519

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.
Files changed (28) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/assets/css/screens.css +11 -0
  3. package/components/Nfc/NFCPatrolReportMain.vue +61 -72
  4. package/components/Nfc/NFCPatrolRouteMain.vue +21 -31
  5. package/components/Nfc/NFCRouteScheduleTimes.vue +83 -0
  6. package/components/Nfc/PatrolReport/DailyReportTab.vue +24 -3
  7. package/components/Nfc/PatrolReport/MonthlyReportTab.vue +32 -3
  8. package/components/Nfc/PatrolReport/MonthlyReportTable.vue +29 -1
  9. package/components/Nfc/PatrolReport/PatrolActivityTable.vue +24 -2
  10. package/components/Nfc/PatrolReport/PatrolMonthDialog.vue +195 -0
  11. package/components/Nfc/PatrolReport/PatrolReportTab.vue +11 -2
  12. package/components/Nfc/PatrolReport/PatrolRouteDetailsDialog.vue +214 -0
  13. package/components/Nfc/PatrolReport/ReportLocationHeader.vue +4 -1
  14. package/components/Nfc/PatrolReport/SkipPhotoDetails.vue +137 -0
  15. package/components/Nfc/PatrolReport/SkipPhotoThumb.vue +132 -0
  16. package/components/Nfc/PatrolReport/SummaryReportTable.vue +42 -1
  17. package/composables/useCommonPermission.ts +10 -0
  18. package/composables/useNFCPatrolDailyReport.ts +4 -18
  19. package/composables/useNFCPatrolMonthlyReport.ts +34 -5
  20. package/composables/useReportPdf.ts +220 -0
  21. package/composables/useSecurityPermission.ts +38 -0
  22. package/composables/useSettingsPermission.ts +16 -1
  23. package/constants/permissions.ts +3 -0
  24. package/package.json +1 -1
  25. package/types/nfc-patrol-report.ts +14 -0
  26. package/utils/nfc-patrol-report.ts +239 -1
  27. package/utils/nfc-patrol-schedule.ts +73 -0
  28. package/utils/report-export.ts +120 -0
@@ -0,0 +1,132 @@
1
+ <!--
2
+ The photo a guard attached when skipping a checkpoint (`skippedPhotoFileId`
3
+ on the log's checkpoint): a thumbnail that opens the photo full size, with
4
+ the guard's remarks under it. Used by the Patrol Activity table and the
5
+ Patrol Route Details dialog.
6
+
7
+ The thumbnail's click stops at the button: in the Patrol Activity table the
8
+ whole skipped row already opens the remarks dialog.
9
+
10
+ The thumbnail is a cropped background, not a `v-img`: it crops the same in
11
+ html2canvas (which ignores `object-fit`) and loads without being scrolled
12
+ into view. The PDF itself leaves this column out and draws the photo full
13
+ size under its checkpoint (`SkipPhotoDetails`).
14
+ -->
15
+ <template>
16
+ <span class="skip-photo">
17
+ <button
18
+ v-if="activity.skippedPhotoFileId"
19
+ type="button"
20
+ class="skip-photo__thumb"
21
+ :aria-label="`View skip photo for ${activity.checkpoint}`"
22
+ @click.stop="open = true"
23
+ >
24
+ <span
25
+ class="skip-photo__img"
26
+ role="img"
27
+ :aria-label="`Skip photo for ${activity.checkpoint}`"
28
+ :style="{
29
+ width: `${size}px`,
30
+ height: `${size}px`,
31
+ backgroundImage: `url('${getFileUrl(activity.skippedPhotoFileId)}')`,
32
+ }"
33
+ />
34
+ </button>
35
+ <span v-else-if="activity.status === 'Skipped'" class="screen-hint">No photo</span>
36
+ <span v-else>-</span>
37
+
38
+ <v-dialog v-if="activity.skippedPhotoFileId" v-model="open" max-width="820">
39
+ <v-card class="screen-modal">
40
+ <div class="skip-photo__head">
41
+ <v-card-title class="pa-0">Skip Photo: {{ activity.checkpoint }}</v-card-title>
42
+ <v-btn
43
+ class="screen-modal__close"
44
+ icon="mdi-close"
45
+ variant="flat"
46
+ aria-label="Close"
47
+ @click="open = false"
48
+ />
49
+ </div>
50
+
51
+ <div class="screen-modal__body px-6 pb-6">
52
+ <v-img
53
+ :src="getFileUrl(activity.skippedPhotoFileId)"
54
+ :alt="`Skip photo for ${activity.checkpoint}`"
55
+ max-height="70vh"
56
+ contain
57
+ />
58
+ <p class="skip-photo__remarks">
59
+ <span class="skip-photo__label">Remarks</span>
60
+ {{ activity.remarks || "No remarks provided" }}
61
+ </p>
62
+ <a :href="getFileUrl(activity.skippedPhotoFileId)" target="_blank" rel="noopener">
63
+ Open full size
64
+ </a>
65
+ </div>
66
+ </v-card>
67
+ </v-dialog>
68
+ </span>
69
+ </template>
70
+
71
+ <script setup lang="ts">
72
+ import type { NFCPatrolActivity } from "../../../types/nfc-patrol-report";
73
+
74
+ withDefaults(
75
+ defineProps<{
76
+ activity: NFCPatrolActivity;
77
+ size?: number;
78
+ }>(),
79
+ { size: 56 },
80
+ );
81
+
82
+ const { getFileUrl } = useFile();
83
+
84
+ const open = ref(false);
85
+ </script>
86
+
87
+ <style scoped>
88
+ .skip-photo__thumb {
89
+ display: block;
90
+ padding: 0;
91
+ border: 1px solid var(--border);
92
+ border-radius: var(--r-inner);
93
+ overflow: hidden;
94
+ background: none;
95
+ cursor: zoom-in;
96
+ }
97
+
98
+ .skip-photo__img {
99
+ display: block;
100
+ background-size: cover;
101
+ background-position: center;
102
+ }
103
+
104
+ .skip-photo__thumb:focus-visible {
105
+ outline: 2px solid var(--accent);
106
+ outline-offset: 2px;
107
+ }
108
+
109
+ .skip-photo__head {
110
+ display: flex;
111
+ align-items: flex-start;
112
+ justify-content: space-between;
113
+ gap: 12px;
114
+ padding: 20px 24px;
115
+ }
116
+
117
+ .skip-photo__remarks {
118
+ margin: 16px 0 8px;
119
+ color: var(--text);
120
+ white-space: pre-line;
121
+ }
122
+
123
+ .skip-photo__label {
124
+ display: block;
125
+ margin-bottom: 4px;
126
+ font-size: var(--fs-section-label);
127
+ font-weight: var(--fw-section-label);
128
+ text-transform: uppercase;
129
+ letter-spacing: 0.04em;
130
+ color: var(--muted);
131
+ }
132
+ </style>
@@ -12,6 +12,10 @@
12
12
  swapping them to `StatusChip` would be a meaning change, not a restyle:
13
13
  `utils/status.ts` does not name "Missed", so the shared map would render it
14
14
  NEUTRAL and a missed patrol would stop being red. Raised, not decided here.
15
+
16
+ In the PDF each patrol run's skipped checkpoints - photo, time, remarks -
17
+ are drawn in a row of their own right under that run (`SkipPhotoDetails`),
18
+ so a day of many runs keeps every photo with the run it was taken on.
15
19
  -->
16
20
  <template>
17
21
  <div class="table-card table-card__shrink mb-6">
@@ -33,7 +37,15 @@
33
37
  </tr>
34
38
  </thead>
35
39
  <tbody>
36
- <tr v-for="row in rows" :key="row.id">
40
+ <template v-for="row in rows" :key="row.id">
41
+ <tr
42
+ :class="{ 'summary-table__row--link': row.detail }"
43
+ :data-pdf-keep-with-next="skipped(row).length > 0 || undefined"
44
+ :tabindex="row.detail ? 0 : undefined"
45
+ :title="row.detail ? 'View patrol route details' : undefined"
46
+ @click="row.detail && emit('select', row)"
47
+ @keydown.enter="row.detail && emit('select', row)"
48
+ >
37
49
  <td>{{ row.routeName }}</td>
38
50
  <td>
39
51
  <v-icon size="small" class="mr-1">mdi-clock-outline</v-icon>
@@ -47,6 +59,7 @@
47
59
  :alt="`${row.guardName || worker.one} signature`"
48
60
  class="guard-signature"
49
61
  contain
62
+ eager
50
63
  />
51
64
  <span v-else>-</span>
52
65
  </td>
@@ -58,6 +71,12 @@
58
71
  </span>
59
72
  </td>
60
73
  </tr>
74
+ <tr v-if="skipped(row).length" data-pdf-only>
75
+ <td colspan="7" class="summary-table__skips">
76
+ <SkipPhotoDetails :activities="skipped(row)" />
77
+ </td>
78
+ </tr>
79
+ </template>
61
80
  </tbody>
62
81
  </v-table>
63
82
  </div>
@@ -70,6 +89,7 @@ import type {
70
89
  NFCPatrolReportSummaryRow,
71
90
  NFCPatrolReportSummaryStatus,
72
91
  } from "../../../types/nfc-patrol-report";
92
+ import SkipPhotoDetails from "./SkipPhotoDetails.vue";
73
93
 
74
94
  const worker = useWorkerTerm();
75
95
  defineProps<{
@@ -77,8 +97,16 @@ defineProps<{
77
97
  rows: NFCPatrolReportSummaryRow[];
78
98
  }>();
79
99
 
100
+ const emit = defineEmits<{
101
+ select: [row: NFCPatrolReportSummaryRow];
102
+ }>();
103
+
80
104
  const { getFileUrl } = useFile();
81
105
 
106
+ function skipped(row: NFCPatrolReportSummaryRow) {
107
+ return row.detail?.activities.filter((activity) => activity.status === "Skipped") ?? [];
108
+ }
109
+
82
110
  function statusClass(status: NFCPatrolReportSummaryStatus) {
83
111
  return status === "Completed" ? "text-success" : "text-error";
84
112
  }
@@ -90,6 +118,19 @@ function statusClass(status: NFCPatrolReportSummaryStatus) {
90
118
  border-bottom: 1px solid var(--border);
91
119
  }
92
120
 
121
+ .summary-table__skips {
122
+ padding-top: 0 !important;
123
+ }
124
+
125
+ .summary-table__row--link {
126
+ cursor: pointer;
127
+ }
128
+
129
+ .summary-table__row--link:focus-visible {
130
+ outline: 2px solid var(--accent);
131
+ outline-offset: -2px;
132
+ }
133
+
93
134
  .guard-signature {
94
135
  width: 80px;
95
136
  height: 40px;
@@ -280,6 +280,16 @@ export function useCommonPermissions() {
280
280
  check: true,
281
281
  description: "Allows the user to manage work order settings.",
282
282
  },
283
+ // Security Ops site visits. The boundary is one half; the guardhouse
284
+ // code an Ops Executive scans to open a visit is the other, and it is the
285
+ // proof the whole module rests on - so this is the right that decides who
286
+ // may re-register it. In the COMMON catalogue because site settings are
287
+ // shared across verticals, not only security.
288
+ "manage-geofence": {
289
+ check: true,
290
+ description:
291
+ "Allows the user to set a site's boundary and register the guardhouse check-in code used for Security Ops site visits.",
292
+ },
283
293
  "manage-billing-and-soa-configuration": {
284
294
  check: true,
285
295
  description:
@@ -5,6 +5,7 @@ import type {
5
5
  } from "../types/nfc-patrol-report";
6
6
  import useNFCPatrolLog from "./useNFCPatrolLog";
7
7
  import useSite from "./useSite";
8
+ import { mapLogToSummaryRow } from "../utils/nfc-patrol-report";
8
9
 
9
10
  interface NFCPatrolLogListResponse {
10
11
  items?: Record<string, any>[];
@@ -25,23 +26,6 @@ function buildAddress(address?: Record<string, string>) {
25
26
  return parts.length ? parts.join(", ") : undefined;
26
27
  }
27
28
 
28
- function mapLogToSummaryRow(log: Record<string, any>, index: number): NFCPatrolSummaryRow {
29
- const checkpoints: Record<string, any>[] = log.checkPoints ?? [];
30
- const checked = checkpoints.filter((cp) => cp.status === "Completed").length;
31
- const missed = checkpoints.filter((cp) => cp.status === "Skipped").length;
32
-
33
- return {
34
- id: log._id,
35
- routeName: `${index + 1}. ${log.route?.name ?? "-"}`,
36
- securityCheckSchedule: log.route?.startTime ?? "-",
37
- guardName: log.sign?.guardName,
38
- guardSignatureFileId: log.sign?.guardSignatureFileId,
39
- checked,
40
- missed,
41
- status: missed === 0 ? "Completed" : "Incomplete",
42
- };
43
- }
44
-
45
29
  export function useNFCPatrolDailyReport(
46
30
  filters: NFCPatrolReportFilters,
47
31
  site: string,
@@ -94,7 +78,9 @@ export function useNFCPatrolDailyReport(
94
78
  address: buildAddress(siteInfo.address),
95
79
  },
96
80
  title: `Patrol Route Summary: ${routeName}`,
97
- rows: logs.map(mapLogToSummaryRow),
81
+ rows: logs.map((log, index) =>
82
+ mapLogToSummaryRow(log, index, (siteInfo as { timezone?: string }).timezone),
83
+ ),
98
84
  };
99
85
  } else {
100
86
  report.value = null;
@@ -6,7 +6,12 @@ import type {
6
6
  } from "../types/nfc-patrol-report";
7
7
  import useNFCPatrolLog from "./useNFCPatrolLog";
8
8
  import useSite from "./useSite";
9
- import { collectAllPages, mapLogsToMonthlyRows } from "../utils/nfc-patrol-report";
9
+ import {
10
+ collectAllPages,
11
+ mapLogsToMonthlyRows,
12
+ mapLogsToMonthRuns,
13
+ monthIndexOf,
14
+ } from "../utils/nfc-patrol-report";
10
15
 
11
16
  interface NFCPatrolLogListResponse {
12
17
  items?: Record<string, any>[];
@@ -48,9 +53,15 @@ export function useNFCPatrolMonthlyReport(
48
53
  */
49
54
  const failed = ref(false);
50
55
 
56
+ // The year's patrol logs, kept so a month's row can open its list without
57
+ // asking the server again. Not deep-reactive: nothing edits them.
58
+ const logs = shallowRef<Record<string, any>[]>([]);
59
+ let siteTimezone: string | undefined;
60
+
51
61
  async function fetchReport() {
52
62
  if (!site || !filters.route) {
53
63
  report.value = null;
64
+ logs.value = [];
54
65
  notFound.value = false;
55
66
  failed.value = false;
56
67
  return;
@@ -63,7 +74,7 @@ export function useNFCPatrolMonthlyReport(
63
74
  try {
64
75
  // The whole year, not page one of it. `collectAllPages` reads the page
65
76
  // count out of the first reply and walks the rest.
66
- const [logs, siteInfo] = await Promise.all([
77
+ const [yearLogs, siteInfo] = await Promise.all([
67
78
  collectAllPages((page) =>
68
79
  getPatrolLogs({
69
80
  page,
@@ -77,8 +88,16 @@ export function useNFCPatrolMonthlyReport(
77
88
  getSiteById(site),
78
89
  ]);
79
90
 
80
- if (logs.length) {
81
- const routeName = logs[0]?.route?.name ?? "-";
91
+ logs.value = yearLogs;
92
+ siteTimezone = (siteInfo as { timezone?: string }).timezone;
93
+
94
+ if (yearLogs.length) {
95
+ const routeName = yearLogs[0]?.route?.name ?? "-";
96
+ const runs = Array<number>(12).fill(0);
97
+ for (const log of yearLogs) {
98
+ const month = monthIndexOf(log);
99
+ if (!Number.isNaN(month)) runs[month]++;
100
+ }
82
101
 
83
102
  report.value = {
84
103
  location: {
@@ -86,7 +105,10 @@ export function useNFCPatrolMonthlyReport(
86
105
  address: buildAddress(siteInfo.address),
87
106
  },
88
107
  title: `Patrol Route Summary: ${routeName}`,
89
- rows: mapLogsToMonthlyRows(logs),
108
+ rows: mapLogsToMonthlyRows(yearLogs).map((row, month) => ({
109
+ ...row,
110
+ runs: runs[month],
111
+ })),
90
112
  };
91
113
  } else {
92
114
  report.value = null;
@@ -94,6 +116,7 @@ export function useNFCPatrolMonthlyReport(
94
116
  }
95
117
  } catch {
96
118
  report.value = null;
119
+ logs.value = [];
97
120
  notFound.value = false;
98
121
  failed.value = true;
99
122
  } finally {
@@ -101,8 +124,14 @@ export function useNFCPatrolMonthlyReport(
101
124
  }
102
125
  }
103
126
 
127
+ /** The patrol runs of one month (0-11), in the order they ran. */
128
+ function monthRuns(monthIndex: number) {
129
+ return mapLogsToMonthRuns(logs.value, monthIndex, siteTimezone);
130
+ }
131
+
104
132
  return {
105
133
  report,
134
+ monthRuns,
106
135
  loading,
107
136
  notFound,
108
137
  failed,
@@ -0,0 +1,220 @@
1
+ import html2canvas from "html2canvas";
2
+ import jsPDF from "jspdf";
3
+ import { formatGeneratedAt, planPdfPages, type PdfTable } from "../utils/report-export";
4
+
5
+ export type ReportPdfMeta = {
6
+ /** "Patrol Report" */
7
+ title: string;
8
+ site?: string;
9
+ address?: string;
10
+ /** Shown top right of every page: Route, Date, Time... */
11
+ details: Array<{ label: string; value: string }>;
12
+ fileName: string;
13
+ };
14
+
15
+ /**
16
+ * A report area (`.report-export`) as an A4 PDF.
17
+ *
18
+ * The area is drawn the way the old export drew it - html2canvas, one tall
19
+ * image - but onto a page rather than across it:
20
+ *
21
+ * - laid out at one width whatever the screen, so a PDF from a laptop and
22
+ * one from a 4K monitor read the same, and always in the light theme;
23
+ * - inside margins, under a header (report, site, route, date) and over a
24
+ * footer (when it was made, page X of Y) drawn as real text on every page;
25
+ * - cut only between rows, photos and sections (`planPdfPages`), repeating a
26
+ * table's header row on the page it carries on to;
27
+ * - without the on-screen site card and dividers: the header says it.
28
+ *
29
+ * Everything PDF-only happens on html2canvas's clone of the page, so the
30
+ * screen never changes. `report-export--pdf` marks that clone: under it
31
+ * `data-pdf-only` shows (hidden on screen by screens.css) and `data-pdf-hide`
32
+ * goes. A row marked `data-pdf-keep-with-next` is never the last on a page,
33
+ * so a checkpoint stays with the skip photo drawn under it.
34
+ */
35
+
36
+ const RENDER_WIDTH = 1000; // CSS px the report is laid out at for the PDF
37
+ const SCALE = 2;
38
+
39
+ // A4 portrait, in mm.
40
+ const PAGE_W = 210;
41
+ const PAGE_H = 297;
42
+ const MARGIN = 12;
43
+ const CONTENT_TOP = 38;
44
+ const CONTENT_BOTTOM = PAGE_H - MARGIN - 9;
45
+ const CONTENT_W = PAGE_W - MARGIN * 2;
46
+ const DETAILS_LABEL_X = 134;
47
+ const DETAILS_VALUE_X = 150;
48
+
49
+ const INK: [number, number, number] = [20, 22, 26];
50
+ const MUTED: [number, number, number] = [100, 104, 112];
51
+ const RULE: [number, number, number] = [220, 222, 226];
52
+
53
+ const PDF_CSS = `
54
+ .report-export--pdf { width: ${RENDER_WIDTH}px !important; max-width: none !important; background: #fff; }
55
+ .report-export--pdf > .v-divider, .report-export--pdf [data-pdf-hide] { display: none !important; }
56
+ .report-export--pdf tr[data-pdf-only] { display: table-row !important; }
57
+ .report-export--pdf [data-pdf-only]:not(tr) { display: block !important; }
58
+ .report-export--pdf tr[data-pdf-keep-with-next] > td { border-bottom-color: transparent !important; }
59
+ .report-export--pdf .table-card, .report-export--pdf .app-card { box-shadow: none !important; }
60
+ .report-export--pdf .v-table__wrapper { overflow: visible !important; }
61
+ .report-export--pdf tbody tr:hover > td { background: transparent !important; }
62
+ /* html2canvas draws digits at their plain widths but places them where the
63
+ page laid out tabular ones, so "10:33" came out "10 :33". */
64
+ .report-export--pdf * { font-variant-numeric: normal !important; }
65
+ `;
66
+
67
+ /** Where the report can be cut, and where its tables are, measured on the clone. */
68
+ function measure(clone: HTMLElement) {
69
+ const origin = clone.getBoundingClientRect().top;
70
+ const top = (el: Element) => el.getBoundingClientRect().top - origin;
71
+ const bottom = (el: Element) => el.getBoundingClientRect().bottom - origin;
72
+
73
+ // Between sections, between table rows (the last row ends with its card,
74
+ // and a row stays with the skip photos under it), and between lines of
75
+ // skip photos. Never right under a heading.
76
+ const breaks = [
77
+ ...Array.from(clone.children),
78
+ ...Array.from(clone.querySelectorAll("tbody tr:not(:last-child):not([data-pdf-keep-with-next])")),
79
+ ...Array.from(clone.querySelectorAll(".skip-details__item")),
80
+ ].map(bottom);
81
+
82
+ const tables: PdfTable[] = Array.from(clone.querySelectorAll("table")).flatMap((table) => {
83
+ const head = table.querySelector("thead");
84
+ return head
85
+ ? [{ top: top(table), bottom: bottom(table), head: { top: top(head), bottom: bottom(head) } }]
86
+ : [];
87
+ });
88
+
89
+ return { height: clone.getBoundingClientRect().height, breaks, tables };
90
+ }
91
+
92
+ function drawHeader(pdf: jsPDF, meta: ReportPdfMeta) {
93
+ pdf.setTextColor(...INK);
94
+ pdf.setFont("helvetica", "bold");
95
+ pdf.setFontSize(15);
96
+ pdf.text(meta.title, MARGIN, MARGIN + 5);
97
+
98
+ let y = MARGIN + 11.5;
99
+ if (meta.site) {
100
+ pdf.setFontSize(10);
101
+ pdf.text(pdf.splitTextToSize(meta.site, DETAILS_LABEL_X - MARGIN - 6)[0], MARGIN, y);
102
+ y += 4.5;
103
+ }
104
+ if (meta.address) {
105
+ pdf.setFont("helvetica", "normal");
106
+ pdf.setFontSize(8.5);
107
+ pdf.setTextColor(...MUTED);
108
+ pdf.text(pdf.splitTextToSize(meta.address, DETAILS_LABEL_X - MARGIN - 6).slice(0, 2), MARGIN, y);
109
+ }
110
+
111
+ let dy = MARGIN + 4;
112
+ for (const { label, value } of meta.details) {
113
+ pdf.setFont("helvetica", "normal");
114
+ pdf.setFontSize(8.5);
115
+ pdf.setTextColor(...MUTED);
116
+ pdf.text(label, DETAILS_LABEL_X, dy);
117
+
118
+ const lines: string[] = pdf.splitTextToSize(value || "-", PAGE_W - MARGIN - DETAILS_VALUE_X);
119
+ pdf.setFont("helvetica", "bold");
120
+ pdf.setTextColor(...INK);
121
+ pdf.text(lines.length > 1 ? `${lines[0].replace(/\s+$/, "")}…` : lines[0], DETAILS_VALUE_X, dy);
122
+ dy += 5;
123
+ }
124
+
125
+ pdf.setDrawColor(...RULE);
126
+ pdf.setLineWidth(0.3);
127
+ pdf.line(MARGIN, CONTENT_TOP - 4, PAGE_W - MARGIN, CONTENT_TOP - 4);
128
+ }
129
+
130
+ function drawFooter(pdf: jsPDF, page: number, pages: number, generatedAt: string) {
131
+ const y = PAGE_H - MARGIN;
132
+ pdf.setDrawColor(...RULE);
133
+ pdf.setLineWidth(0.3);
134
+ pdf.line(MARGIN, y - 5, PAGE_W - MARGIN, y - 5);
135
+
136
+ pdf.setFont("helvetica", "normal");
137
+ pdf.setFontSize(8);
138
+ pdf.setTextColor(...MUTED);
139
+ pdf.text(`Generated ${generatedAt}`, MARGIN, y);
140
+ pdf.text(`Page ${page} of ${pages}`, PAGE_W - MARGIN, y, { align: "right" });
141
+ }
142
+
143
+ export default function useReportPdf() {
144
+ async function exportReportPdf(report: HTMLElement, meta: ReportPdfMeta) {
145
+ let layout = { height: 0, breaks: [] as number[], tables: [] as PdfTable[] };
146
+
147
+ const canvas = await html2canvas(report, {
148
+ scale: SCALE,
149
+ useCORS: true,
150
+ backgroundColor: "#fff",
151
+ windowWidth: Math.max(window.innerWidth, RENDER_WIDTH + 200),
152
+ onclone: (doc, clone) => {
153
+ // A PDF is read on white: the dark theme's tokens hang off this class.
154
+ doc.querySelectorAll(".v-theme--dark").forEach((el) => {
155
+ el.classList.replace("v-theme--dark", "v-theme--light");
156
+ });
157
+ const style = doc.createElement("style");
158
+ style.textContent = PDF_CSS;
159
+ doc.head.appendChild(style);
160
+ clone.classList.add("report-export--pdf");
161
+ layout = measure(clone);
162
+ },
163
+ });
164
+
165
+ // Canvas px per report px, and report px per mm on the page.
166
+ const k = canvas.height / layout.height;
167
+ const pxPerMm = canvas.width / k / CONTENT_W;
168
+ const pages = planPdfPages(
169
+ layout.height,
170
+ (CONTENT_BOTTOM - CONTENT_TOP) * pxPerMm,
171
+ layout.breaks,
172
+ layout.tables,
173
+ );
174
+
175
+ const pdf = new jsPDF({ unit: "mm", format: "a4", orientation: "portrait" });
176
+
177
+ pages.forEach((page, index) => {
178
+ if (index > 0) pdf.addPage();
179
+
180
+ const headPx = page.head ? page.head.bottom - page.head.top : 0;
181
+ const bodyPx = page.bottom - page.top;
182
+ const part = document.createElement("canvas");
183
+ part.width = canvas.width;
184
+ part.height = Math.max(1, Math.round((headPx + bodyPx) * k));
185
+
186
+ const ctx = part.getContext("2d");
187
+ if (!ctx) return;
188
+ ctx.fillStyle = "#fff";
189
+ ctx.fillRect(0, 0, part.width, part.height);
190
+ if (page.head) {
191
+ const h = Math.round(headPx * k);
192
+ ctx.drawImage(canvas, 0, Math.round(page.head.top * k), canvas.width, h, 0, 0, canvas.width, h);
193
+ }
194
+ const bodyTop = Math.round(page.top * k);
195
+ const bodyH = Math.round(page.bottom * k) - bodyTop;
196
+ ctx.drawImage(canvas, 0, bodyTop, canvas.width, bodyH, 0, Math.round(headPx * k), canvas.width, bodyH);
197
+
198
+ pdf.addImage(
199
+ part.toDataURL("image/jpeg", 0.92),
200
+ "JPEG",
201
+ MARGIN,
202
+ CONTENT_TOP,
203
+ CONTENT_W,
204
+ part.height / k / pxPerMm,
205
+ );
206
+ });
207
+
208
+ const generatedAt = formatGeneratedAt();
209
+ const total = pdf.getNumberOfPages();
210
+ for (let page = 1; page <= total; page++) {
211
+ pdf.setPage(page);
212
+ drawHeader(pdf, meta);
213
+ drawFooter(pdf, page, total, generatedAt);
214
+ }
215
+
216
+ pdf.save(meta.fileName);
217
+ }
218
+
219
+ return { exportReportPdf };
220
+ }
@@ -735,6 +735,38 @@ export default function useSecurityPermission() {
735
735
  description: "Allows the user to delete routes.",
736
736
  },
737
737
  },
738
+ /**
739
+ * NEW. Security Ops - the site visit and its checklists.
740
+ *
741
+ * NO ROLE HOLDS THESE YET. The module is new, so every one of these strings
742
+ * has a count of zero today. API-core's `siteVisit` gate is therefore
743
+ * COUNTED, not enforcing (`SITE_VISIT_PERMISSION_MODE`, default `log`): it
744
+ * records who WOULD be refused and refuses nobody, the same way the NFC
745
+ * patrol and incident report gates shipped. Provision roles against that
746
+ * count before anyone sets it to `enforce`.
747
+ *
748
+ * THREE PLACES, BY HAND. These spellings have to match API-core
749
+ * (`SITE_VISIT_PERMISSIONS` in `site-authz.util.ts`) and the RN app
750
+ * (`permission.catalog.ts`), which does NOT import this file - it keeps a
751
+ * literal copy and compares strings exactly. `roles-picker-covers-mobile-gates`
752
+ * in web-app-security is the test that holds the three together.
753
+ *
754
+ * The geofence right is NOT here: it is a site setting, so it lives in
755
+ * `useCommonPermission.ts` as `site-settings:manage-geofence` beside the
756
+ * other panels.
757
+ */
758
+ "security-ops": {
759
+ "start-site-visit": {
760
+ check: true,
761
+ description:
762
+ "Allows the user to check in at a site, fill in the visit checklists and check out.",
763
+ },
764
+ "see-all-site-visits": {
765
+ check: true,
766
+ description:
767
+ "Allows the user to view site visits across the sites they can reach, including other executives' visits.",
768
+ },
769
+ },
738
770
  // NEW. Seeing the CCTV wall, as distinct from setting cameras up
739
771
  // (`site-settings:manage-cctv-camera`).
740
772
  "cctv-mgmt": {
@@ -768,6 +800,12 @@ export default function useSecurityPermission() {
768
800
  "manage-nfc-management": siteSettingsPermissions["manage-nfc-management"],
769
801
  "manage-nfc-patrol-settings":
770
802
  siteSettingsPermissions["manage-nfc-patrol-settings"],
803
+ // Security Ops geofencing. This block CHERRY-PICKS from
804
+ // `siteSettingsPermissions` rather than spreading it, so a new entry in
805
+ // the common catalogue does not reach the security role editor on its own
806
+ // - without this line no administrator on a security site could grant the
807
+ // right, and the Geofencing panel would be invisible to everyone.
808
+ "manage-geofence": siteSettingsPermissions["manage-geofence"],
771
809
  "manage-red-dot-settings": {
772
810
  check: true,
773
811
  description:
@@ -129,6 +129,20 @@ export function useSettingsPermission() {
129
129
  "update-vehicle": { check: true, description: "Allows the user to update vehicle details." },
130
130
  },
131
131
  };
132
+ /**
133
+ * The Geofencing panel - Security Ops site visits.
134
+ *
135
+ * MUST ALSO BE IN `canManageSiteSettings` BELOW. That computed is an OR of
136
+ * every panel gate and it is what decides whether the Settings page renders at
137
+ * all, so a role holding ONLY this right would otherwise be given a page it
138
+ * cannot open. Adding a panel is always two lines, never one.
139
+ */
140
+ const canManageGeofence = computed(() => {
141
+ if (!userAppRole.value) return false;
142
+ if (userAppRole.value.permissions.includes("*")) return true;
143
+ return hasPermission(userAppRole.value, permissions, "site-settings", "manage-geofence");
144
+ });
145
+
132
146
  const canManageVehicleQr = computed(() => {
133
147
  if (!userAppRole.value) return false;
134
148
  if (userAppRole.value.permissions.includes("*")) return true;
@@ -136,7 +150,7 @@ export function useSettingsPermission() {
136
150
  });
137
151
 
138
152
  const canManageSiteSettings = computed(() => {
139
- return canManageSiteInformation.value || canManageANPRCamera.value || canManageCCTVCamera.value || canManageDeliveryCompanies.value || canManageResidentVisitors.value || canManageWorkOrderSettings.value || canManageBillingAndSOAConfiguration.value || canManageNFCManagement.value || canManageNFCPatrolSettings.value || canManageEntryPass.value || canManageRedDotSettings.value
153
+ return canManageSiteInformation.value || canManageANPRCamera.value || canManageCCTVCamera.value || canManageDeliveryCompanies.value || canManageResidentVisitors.value || canManageWorkOrderSettings.value || canManageBillingAndSOAConfiguration.value || canManageNFCManagement.value || canManageNFCPatrolSettings.value || canManageEntryPass.value || canManageRedDotSettings.value || canManageGeofence.value
140
154
  })
141
155
 
142
156
  return {
@@ -151,6 +165,7 @@ export function useSettingsPermission() {
151
165
  canManageNFCPatrolSettings,
152
166
  canManageEntryPass,
153
167
  canManageRedDotSettings,
168
+ canManageGeofence,
154
169
  canManageVehicleQr,
155
170
  canManageSiteSettings
156
171