@7365admin1/layer-common 4.168.3 → 4.169.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.
@@ -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 } =
@@ -29,10 +29,22 @@ export default function useInventory() {
29
29
 
30
30
  getStores: async (site: string) =>
31
31
  ((await api<TInventoryStore[]>("/stores", { query: { site } })) ?? []).map((s) => ({ ...s, access: inventoryCaps(s.access) })),
32
+ /** Which store of the organisation supplies each property (for the picker). */
33
+ getSiteOwners: async (org: string) => (await api<{ site: string; store: string; name: string }[]>("/stores/site-owners", { query: { org } })) ?? [],
34
+ deleteStore: (id: string) => api<{ deleted: boolean }>(`/stores/${id}`, { method: "DELETE" }),
32
35
  createStore: (body: { org: string; sites: string[]; name: string }) =>
33
36
  api<TInventoryStore>("/stores", { method: "POST", body }),
34
- updateStore: (id: string, body: Partial<Pick<TInventoryStore, "name" | "sites" | "showInResidentApp" | "showCostInResidentApp" | "lowStockReminderDays">>) =>
37
+ updateStore: (id: string, body: Partial<Pick<TInventoryStore, "name" | "sites" | "showInResidentApp" | "showCostInResidentApp" | "lowStockReminderDays" | "workOrderMaterials">>) =>
35
38
  api<TInventoryStore>(`/stores/${id}`, { method: "PATCH", body }),
39
+ /**
40
+ * The work order materials picker (2026-11): items from the stores at `site` that are switched
41
+ * on for work orders and this person may use; needs "Add Work Order Materials", not an Inventory right.
42
+ */
43
+ getWorkOrderItems: (site: string, search = "") =>
44
+ api<{ stores: { _id: string; name: string; orgName: string; ownerType: string }[]; items: (TInventoryItem & { storeName: string })[] }>(
45
+ "/work-order-items",
46
+ { query: { site, ...(search ? { search } : {}) } },
47
+ ),
36
48
  /** One store with its settings (`lowStockReminderDays` only from an API that sends reminders). */
37
49
  getStore: (id: string) => api<TInventoryStore>(`/stores/${id}`),
38
50
 
@@ -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.3",
5
+ "version": "4.169.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.",
@@ -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
+ };
@@ -104,3 +104,21 @@ export function inventoryTwoStoresText(stores: TStoreLike[]) {
104
104
  if (!ours || !theirs) return "";
105
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
106
  }
107
+
108
+ export type TSiteOwner = { site: string; store: string; name: string };
109
+
110
+ /**
111
+ * The picker rows: a property already supplied by ANOTHER store of the organisation is disabled with
112
+ * the reason as its subtitle; the current store's own properties stay selectable.
113
+ */
114
+ export function inventorySitePickerItems(
115
+ options: { _id: string; name: string }[],
116
+ owners: TSiteOwner[],
117
+ currentStore?: string,
118
+ ) {
119
+ const taken = new Map(owners.filter((o) => o.store !== currentStore).map((o) => [o.site, o.name]));
120
+ return options.map((o) => {
121
+ const by = taken.get(o._id);
122
+ return by ? { ...o, props: { disabled: true, subtitle: `Already supplied by ${by}` } } : { ...o };
123
+ });
124
+ }
@@ -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
+ }