@7365admin1/layer-common 4.168.2 → 4.168.4

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,128 @@
1
+ <template>
2
+ <div v-if="groups.length" class="mat-groups">
3
+ <div v-for="group in groups" :key="group.key" class="mat-group">
4
+ <div v-if="!hideHead" class="mat-group__head">
5
+ <span class="mat-group__title">{{ group.title }}</span>
6
+ <span v-if="group.note" class="mat-group__note">{{ group.note }}</span>
7
+ </div>
8
+ <div v-for="line in group.lines" :key="line.key" class="mat-group__row">
9
+ <div class="mat-group__main">
10
+ <div class="mat-group__name">{{ line.name }}</div>
11
+ <div class="mat-group__meta">{{ line.qty }} × {{ money(line.unitCost) }}</div>
12
+ </div>
13
+ <span class="mat-group__amount">{{ money(line.total) }}</span>
14
+ </div>
15
+ <div class="mat-group__total">
16
+ <span>Total</span>
17
+ <span>{{ money(group.total) }}</span>
18
+ </div>
19
+ </div>
20
+ <div v-if="showGrandTotal && groups.length > 1" class="mat-groups__grand">
21
+ <span>Grand Total</span>
22
+ <span>{{ money(groups.reduce((sum, g) => sum + g.total, 0)) }}</span>
23
+ </div>
24
+ </div>
25
+ </template>
26
+
27
+ <script setup lang="ts">
28
+ /**
29
+ * Materials listed per work order (or per "to use on submit" group), each
30
+ * with its total, and - when there are several - a grand total.
31
+ */
32
+ type TMaterialsGroup = {
33
+ key: string;
34
+ title: string;
35
+ /** Beside the title, e.g. the work order's status. */
36
+ note?: string;
37
+ lines: { key: string; name: string; qty: number; unitCost: number; total: number }[];
38
+ total: number;
39
+ };
40
+
41
+ defineProps<{
42
+ groups: TMaterialsGroup[];
43
+ /** Add a Grand Total row when there is more than one group. */
44
+ showGrandTotal?: boolean;
45
+ /** No title row per group - where the work order is named already (its own dialog). */
46
+ hideHead?: boolean;
47
+ }>();
48
+
49
+ const money = (n?: number) => `S$${Number(n ?? 0).toFixed(2)}`;
50
+ </script>
51
+
52
+ <style scoped>
53
+ .mat-groups {
54
+ display: flex;
55
+ flex-direction: column;
56
+ gap: 10px;
57
+ margin-top: 10px;
58
+ font-size: 13px;
59
+ }
60
+ .mat-group {
61
+ border: 1px solid var(--border);
62
+ border-radius: 10px;
63
+ overflow: hidden;
64
+ }
65
+ .mat-group__head {
66
+ display: flex;
67
+ justify-content: space-between;
68
+ gap: 8px;
69
+ padding: 7px 12px;
70
+ background: var(--thead);
71
+ border-bottom: 1px solid var(--border);
72
+ }
73
+ .mat-group__title {
74
+ font-size: 11.5px;
75
+ font-weight: 800;
76
+ letter-spacing: 0.03em;
77
+ text-transform: uppercase;
78
+ color: var(--text2);
79
+ }
80
+ .mat-group__note {
81
+ font-size: 11.5px;
82
+ color: var(--muted);
83
+ }
84
+ .mat-group__row {
85
+ display: flex;
86
+ align-items: center;
87
+ justify-content: space-between;
88
+ gap: 12px;
89
+ padding: 9px 12px;
90
+ border-bottom: 1px solid var(--border);
91
+ }
92
+ .mat-group__main {
93
+ min-width: 0;
94
+ }
95
+ .mat-group__name {
96
+ font-weight: 600;
97
+ color: var(--text);
98
+ }
99
+ .mat-group__meta {
100
+ font-size: 12px;
101
+ color: var(--muted);
102
+ margin-top: 1px;
103
+ font-variant-numeric: tabular-nums;
104
+ }
105
+ .mat-group__amount {
106
+ font-weight: 700;
107
+ flex: 0 0 auto;
108
+ font-variant-numeric: tabular-nums;
109
+ }
110
+ .mat-group__total {
111
+ display: flex;
112
+ justify-content: space-between;
113
+ padding: 9px 12px;
114
+ font-weight: 800;
115
+ font-variant-numeric: tabular-nums;
116
+ }
117
+ .mat-groups__grand {
118
+ display: flex;
119
+ justify-content: space-between;
120
+ padding: 10px 12px;
121
+ border-radius: 10px;
122
+ background: var(--accent-soft);
123
+ color: var(--accent);
124
+ font-size: 14px;
125
+ font-weight: 800;
126
+ font-variant-numeric: tabular-nums;
127
+ }
128
+ </style>
@@ -127,8 +127,22 @@ export function useCommonPermissions() {
127
127
  * providers' role editors no longer offer the box. Property keeps
128
128
  * `workOrderPermissions` as it is.
129
129
  */
130
- const { "delete-work-order": _propertyOnly, ...tradeWorkOrderPermissions } =
130
+ const { "delete-work-order": _propertyOnly, ...tradeWorkOrderBase } =
131
131
  workOrderPermissions;
132
+ /*
133
+ * ...plus "Add Work Order Materials" (2026-11): the service providers pick
134
+ * parts from inventory on a work order, taken from stock when it is
135
+ * submitted. Its own right, separate from the Inventory module's. Property
136
+ * Management does not submit, so its editor does not offer it.
137
+ */
138
+ const tradeWorkOrderPermissions: Record<string, TPermission> = {
139
+ ...tradeWorkOrderBase,
140
+ "add-work-order-materials": {
141
+ check: true,
142
+ description:
143
+ "Allows the user to add materials (parts) from inventory to a work order; they are taken from stock when it is submitted.",
144
+ },
145
+ };
132
146
 
133
147
  /** Feedback the same way: "delete-feedback" is Property Management's only. */
134
148
  const { "delete-feedback": _propertyOnlyFeedback, ...tradeFeedbackPermissions } =
@@ -31,8 +31,17 @@ export default function useInventory() {
31
31
  ((await api<TInventoryStore[]>("/stores", { query: { site } })) ?? []).map((s) => ({ ...s, access: inventoryCaps(s.access) })),
32
32
  createStore: (body: { org: string; sites: string[]; name: string }) =>
33
33
  api<TInventoryStore>("/stores", { method: "POST", body }),
34
- updateStore: (id: string, body: Partial<Pick<TInventoryStore, "name" | "sites" | "showInResidentApp" | "showCostInResidentApp" | "lowStockReminderDays">>) =>
34
+ updateStore: (id: string, body: Partial<Pick<TInventoryStore, "name" | "sites" | "showInResidentApp" | "showCostInResidentApp" | "lowStockReminderDays" | "workOrderMaterials">>) =>
35
35
  api<TInventoryStore>(`/stores/${id}`, { method: "PATCH", body }),
36
+ /**
37
+ * The work order materials picker (2026-11): items from the stores at `site` that are switched
38
+ * on for work orders and this person may use; needs "Add Work Order Materials", not an Inventory right.
39
+ */
40
+ getWorkOrderItems: (site: string, search = "") =>
41
+ api<{ stores: { _id: string; name: string; orgName: string; ownerType: string }[]; items: (TInventoryItem & { storeName: string })[] }>(
42
+ "/work-order-items",
43
+ { query: { site, ...(search ? { search } : {}) } },
44
+ ),
36
45
  /** One store with its settings (`lowStockReminderDays` only from an API that sends reminders). */
37
46
  getStore: (id: string) => api<TInventoryStore>(`/stores/${id}`),
38
47
 
@@ -31,5 +31,12 @@ export default function useInventoryPermission() {
31
31
  );
32
32
  });
33
33
 
34
- return { canSeeInventory };
34
+ /** May set up a store for this organisation (the API checks again; this only decides whether to offer the button). */
35
+ const canManageInventory = computed(() => {
36
+ const role = userAppRole.value;
37
+ if (!role || permissionsDenied(["inventory"], userAppModulesDenied?.value)) return false;
38
+ return role.permissions.includes("*") || hasPermission(role, permissions, "inventory", "manage-inventory");
39
+ });
40
+
41
+ return { canSeeInventory, canManageInventory };
35
42
  }
@@ -87,6 +87,12 @@ export default function useSecurityPermission() {
87
87
  check: true,
88
88
  description: "Allows the user to update work-order details.",
89
89
  },
90
+ // 2026-11: parts from inventory on a work order, taken from stock on submit.
91
+ "add-work-order-materials": {
92
+ check: true,
93
+ description:
94
+ "Allows the user to add materials (parts) from inventory to a work order; they are taken from stock when it is submitted.",
95
+ },
90
96
  // No "delete-work-order": deleting a work order is for Property
91
97
  // Management and the work order's creator only (Harris, 2026-09-23).
92
98
  },
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.168.2",
5
+ "version": "4.168.4",
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.",
@@ -32,6 +32,8 @@ declare type TInventoryStore = {
32
32
  ownerServiceLabel?: string;
33
33
  /** Low-stock reminders every N days until a PO is recorded (0 = off). Only from GET /stores/:id of an API that sends them. */
34
34
  lowStockReminderDays?: number;
35
+ /** "Use for work order materials" (2026-11): technicians may pick its items on a work order. Missing = off. */
36
+ workOrderMaterials?: boolean;
35
37
  };
36
38
 
37
39
  declare type TInventoryItem = {
@@ -134,6 +136,15 @@ declare type TInventoryTransaction = {
134
136
  site?: string;
135
137
  location?: { type: "common_area" | "tenant_unit"; area?: string; unit?: string; unitName?: string; tenantName?: string };
136
138
  reference?: string;
139
+ /**
140
+ * Used by a work order's submit (2026-11): its id, its number as it is now ("#ME0209"; the saved
141
+ * `reference` when it no longer exists) and whether it still exists, for History to link to it.
142
+ */
143
+ workOrder?: string;
144
+ workOrderNumber?: string;
145
+ workOrderExists?: boolean;
146
+ /** The feedback the work order is tied to (2026-11): its link goes there. */
147
+ workOrderFeedback?: string | null;
137
148
  supplier?: string;
138
149
  /** Receiving (2026-10): missing on older rows = PO. */
139
150
  receivingType?: "PO" | "DO" | "CASH";
@@ -0,0 +1,15 @@
1
+ /** A material (part) taken from the site's inventory store for a work order. */
2
+ declare type TWorkOrderMaterial = {
3
+ /** Inventory item id. */
4
+ item: string;
5
+ /** The inventory store it comes from, and that store's owner name. */
6
+ store: string;
7
+ storeName?: string;
8
+ name: string;
9
+ code?: string;
10
+ unit?: string;
11
+ unitCost: number;
12
+ /** Stock when it was picked (the most that can be taken). */
13
+ stock: number;
14
+ qty: number;
15
+ };
@@ -68,3 +68,39 @@ export function inventoryItemMeta(item: TItemLike) {
68
68
  .filter(Boolean)
69
69
  .join(" · ");
70
70
  }
71
+
72
+ /**
73
+ * "How inventory works" (owner 2026-11-05): the three ways clients run stock, in the words the screens use.
74
+ * The mobile apps carry the same sentences; change both together.
75
+ */
76
+ export const INVENTORY_HOW_IT_WORKS = {
77
+ title: "How inventory works",
78
+ intro:
79
+ "A store is the stock one company keeps. The company that owns a store runs it: adds items, receives deliveries, approves requests and issues stock. Everyone else can only request from it.",
80
+ setups: [
81
+ {
82
+ title: "1. One company store for many sites",
83
+ text: "For example a security agency: one store supplies every site the company serves. When you set it up, tick all those sites. Staff at each site request from it; issues, usage and reports are recorded per site.",
84
+ },
85
+ {
86
+ title: "2. One store per property",
87
+ text: "For example Winsland House 1 and Winsland House 2: each property keeps its own stock, so each gets its own store. Set up the store at each property and tick only that property. Use Switch property to move between them; stock never mixes.",
88
+ },
89
+ {
90
+ title: "3. Main store and service providers",
91
+ text: "The property manager's Main store supplies the service providers at the property: their staff request, the store keeper issues to the person. A provider can also keep its own store (Our store) for stock it buys itself. Stock does not move between stores.",
92
+ },
93
+ ],
94
+ where: "Stores are set up on the web (Inventory, by a person allowed to manage inventory). The mobile apps request, receive and record usage.",
95
+ };
96
+
97
+ /**
98
+ * Two stores at one property for the same person: say which is which, so a request goes to the right one.
99
+ * Empty unless the person sees both their own company's store and another company's main store.
100
+ */
101
+ export function inventoryTwoStoresText(stores: TStoreLike[]) {
102
+ const ours = stores.some((s) => s.owner === true);
103
+ const theirs = stores.some((s) => s.owner === false && s.main);
104
+ if (!ours || !theirs) return "";
105
+ return "Two stores supply this property. Our store is your company's own stock. Main store is the property manager's stock: you can only request from it.";
106
+ }
@@ -0,0 +1,24 @@
1
+ import type { RouteLocationNormalizedLoaded, Router } from "vue-router";
2
+
3
+ /**
4
+ * Where a work order number in Inventory (History, reports) links to (2026-11): the
5
+ * feedback's details when the work order is tied to a feedback (its work is done there), else
6
+ * the work order's details - in this app, at the page's organisation and site. Null (shown as
7
+ * text) when there is no work order, it no longer exists, or the app has no such page.
8
+ */
9
+ export function workOrderLinkTarget(
10
+ row: { workOrder?: unknown; workOrderExists?: boolean; workOrderFeedback?: string | null },
11
+ route: RouteLocationNormalizedLoaded,
12
+ router: Router,
13
+ ) {
14
+ if (!row.workOrder || row.workOrderExists === false) return null;
15
+ const { org, site } = route.params;
16
+ if (!org || !site) return null;
17
+ if (row.workOrderFeedback && router.hasRoute("org-site-feedbacks-id")) {
18
+ return { name: "org-site-feedbacks-id", params: { org, site, id: String(row.workOrderFeedback) } };
19
+ }
20
+ if (router.hasRoute("org-site-work-orders-id")) {
21
+ return { name: "org-site-work-orders-id", params: { org, site, id: String(row.workOrder) } };
22
+ }
23
+ return null;
24
+ }