@kruschdev/pascal-plugin-plumbing 0.2.1 → 0.4.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/docs/CAD-CATALOG.md +2 -2
- package/package.json +2 -2
- package/src/agent-operations.ts +14 -2
- package/src/agent-tools.ts +1 -0
- package/src/cad/fittings.ts +26 -8
- package/src/cad/manifold-interior.ts +5 -6
- package/src/index.ts +3 -0
- package/src/ipc/audit.ts +124 -26
- package/src/ipc/autopopulate.ts +609 -93
- package/src/ipc/framing-interop.ts +3 -2
- package/src/ipc/pricing.ts +222 -22
- package/src/ipc/routing.ts +148 -18
- package/src/ipc/schedule.ts +37 -14
- package/src/ipc/sizing.ts +140 -0
- package/src/ipc/tables.ts +5 -2
- package/src/nodes/parametrics.ts +76 -0
- package/src/nodes/pipe-run.ts +83 -32
- package/src/ui/chat-card.tsx +52 -0
- package/src/ui/inspector-card.tsx +36 -4
- package/src/ui/manifold-cutaway-view.tsx +35 -8
- package/src/ui/plumbing-panel.tsx +5 -3
- package/src/ui/schedule-view.tsx +1 -1
- package/src/ui/store.ts +0 -17
|
@@ -310,7 +310,7 @@ export type BonesPlumbingContext = {
|
|
|
310
310
|
/** Authoritative stud cavity depth in inches from Priority #1 `structural:assembly` (`5.5` for 2x6, `3.5` for 2x4). */
|
|
311
311
|
defaultStudDepthIn?: number
|
|
312
312
|
framingSystem: 'lumber' | 'lgs'
|
|
313
|
-
floorSystem?: 'dimensional' | 'tji-ijoist' | 'open-web-truss'
|
|
313
|
+
floorSystem?: 'dimensional' | 'tji-ijoist' | 'open-web-truss' | 'slab-on-grade'
|
|
314
314
|
wallRules: ReadonlyMap<string, BonesWallRule>
|
|
315
315
|
waterHeaterAnchor: BonesPlumbingServiceAnchor | null
|
|
316
316
|
waterEntryAnchor: BonesPlumbingServiceAnchor | null
|
|
@@ -416,7 +416,8 @@ export function extractBonesPlumbingContext(
|
|
|
416
416
|
const floorSystem =
|
|
417
417
|
structuralNode?.floorSystem === 'tji-ijoist' ||
|
|
418
418
|
structuralNode?.floorSystem === 'open-web-truss' ||
|
|
419
|
-
structuralNode?.floorSystem === 'dimensional'
|
|
419
|
+
structuralNode?.floorSystem === 'dimensional' ||
|
|
420
|
+
structuralNode?.floorSystem === 'slab-on-grade'
|
|
420
421
|
? structuralNode.floorSystem
|
|
421
422
|
: undefined
|
|
422
423
|
const wallRules = new Map<string, BonesWallRule>()
|
package/src/ipc/pricing.ts
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
* Framework-free: zero React, Three.js, or `@pascal-app/*` imports.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import {
|
|
7
|
+
type BomCostScope,
|
|
8
|
+
type PascalBomFragment,
|
|
9
|
+
createBomLine,
|
|
10
|
+
slugifyBomSku,
|
|
11
|
+
applyCallerInjectedPartsToFragment,
|
|
12
|
+
type CallerInjectedPart,
|
|
13
|
+
} from '@kruschdev/pascal-mep-kernel/bom'
|
|
6
14
|
import type { SceneNodeLike } from './framing-interop'
|
|
7
15
|
import { type PlumbingSchedule, buildPlumbingSchedule } from './schedule'
|
|
8
16
|
import {
|
|
@@ -39,6 +47,7 @@ export type PlumbingBomLine = {
|
|
|
39
47
|
laborHours: number
|
|
40
48
|
laborUsd: number
|
|
41
49
|
totalUsd: number
|
|
50
|
+
nodeIds?: string[]
|
|
42
51
|
}
|
|
43
52
|
|
|
44
53
|
export type PlumbingBomResult = {
|
|
@@ -254,9 +263,23 @@ export function buildPlumbingBom(
|
|
|
254
263
|
occupancy,
|
|
255
264
|
...(supplyMaterial ? { supplyMaterial } : {}),
|
|
256
265
|
})
|
|
257
|
-
const
|
|
266
|
+
const allEntries = Object.entries(nodes)
|
|
258
267
|
const lines: PlumbingBomLine[] = []
|
|
259
268
|
|
|
269
|
+
const normalizeNodeIds = (ids: Iterable<string | undefined>): string[] => {
|
|
270
|
+
const seen = new Set<string>()
|
|
271
|
+
const out: string[] = []
|
|
272
|
+
for (const raw of ids) {
|
|
273
|
+
if (typeof raw !== 'string' || raw.length === 0 || seen.has(raw)) continue
|
|
274
|
+
seen.add(raw)
|
|
275
|
+
out.push(raw)
|
|
276
|
+
}
|
|
277
|
+
return out
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const resolveEntryNodeId = (key: string, node: SceneNodeLike): string =>
|
|
281
|
+
typeof node.id === 'string' && node.id.length > 0 ? node.id : key
|
|
282
|
+
|
|
260
283
|
const addLine = (
|
|
261
284
|
category: PlumbingBomLine['category'],
|
|
262
285
|
item: string,
|
|
@@ -264,11 +287,13 @@ export function buildPlumbingBom(
|
|
|
264
287
|
quantity: number,
|
|
265
288
|
unitMaterialUsd: number,
|
|
266
289
|
laborHours: number,
|
|
290
|
+
rawNodeIds?: Iterable<string | undefined>,
|
|
267
291
|
) => {
|
|
268
292
|
if (quantity <= 0) return
|
|
269
293
|
const mat = round2(quantity * unitMaterialUsd)
|
|
270
294
|
const hrs = round2(laborHours)
|
|
271
295
|
const lab = round2(hrs * laborRateUsd)
|
|
296
|
+
const dedupedIds = rawNodeIds ? normalizeNodeIds(rawNodeIds) : []
|
|
272
297
|
lines.push({
|
|
273
298
|
category,
|
|
274
299
|
item,
|
|
@@ -279,71 +304,117 @@ export function buildPlumbingBom(
|
|
|
279
304
|
laborHours: hrs,
|
|
280
305
|
laborUsd: lab,
|
|
281
306
|
totalUsd: round2(mat + lab),
|
|
307
|
+
...(dedupedIds.length > 0 ? { nodeIds: dedupedIds } : {}),
|
|
282
308
|
})
|
|
283
309
|
}
|
|
284
310
|
|
|
285
311
|
// 1. Equipment (separate roughInOnly SKU-linked units so real-world water heater SKUs aren't double-billed)
|
|
286
312
|
const eqFullCounts = new Map<EquipmentKind, number>()
|
|
287
313
|
const eqRoughOnlyCounts = new Map<EquipmentKind, number>()
|
|
288
|
-
|
|
314
|
+
const eqFullNodeIds = new Map<EquipmentKind, string[]>()
|
|
315
|
+
const eqRoughOnlyNodeIds = new Map<EquipmentKind, string[]>()
|
|
316
|
+
for (const [key, n] of allEntries) {
|
|
289
317
|
if (n.type !== 'plumbing:equipment') continue
|
|
318
|
+
const nid = resolveEntryNodeId(key, n)
|
|
290
319
|
const k = (n.equipmentKind as EquipmentKind) || 'water-heater-tank-electric'
|
|
291
320
|
if (n.roughInOnly === true) {
|
|
292
321
|
eqRoughOnlyCounts.set(k, (eqRoughOnlyCounts.get(k) ?? 0) + 1)
|
|
322
|
+
const list = eqRoughOnlyNodeIds.get(k) ?? []
|
|
323
|
+
list.push(nid)
|
|
324
|
+
eqRoughOnlyNodeIds.set(k, list)
|
|
293
325
|
} else {
|
|
294
326
|
eqFullCounts.set(k, (eqFullCounts.get(k) ?? 0) + 1)
|
|
327
|
+
const list = eqFullNodeIds.get(k) ?? []
|
|
328
|
+
list.push(nid)
|
|
329
|
+
eqFullNodeIds.set(k, list)
|
|
295
330
|
}
|
|
296
331
|
}
|
|
297
332
|
for (const [k, qty] of eqFullCounts) {
|
|
298
333
|
const p = EQUIPMENT_PRICES[k] ?? { mat: 350, hrs: 2.5, label: k }
|
|
299
|
-
addLine('Equipment', p.label, 'ea', qty, p.mat, qty * p.hrs)
|
|
334
|
+
addLine('Equipment', p.label, 'ea', qty, p.mat, qty * p.hrs, eqFullNodeIds.get(k))
|
|
300
335
|
}
|
|
301
336
|
for (const [k, qty] of eqRoughOnlyCounts) {
|
|
302
337
|
const p = EQUIPMENT_PRICES[k] ?? { mat: 350, hrs: 2.5, label: k }
|
|
303
|
-
addLine('Equipment', `${p.label} (rough-in connection, SKU linked)`, 'ea', qty, round2(p.mat * 0.25), round2(qty * p.hrs * 0.55))
|
|
338
|
+
addLine('Equipment', `${p.label} (rough-in connection, SKU linked)`, 'ea', qty, round2(p.mat * 0.25), round2(qty * p.hrs * 0.55), eqRoughOnlyNodeIds.get(k))
|
|
304
339
|
}
|
|
305
340
|
|
|
306
341
|
// 2. Manifolds (separate roughInOnly SKU-linked manifolds so catalog SKUs aren't double-billed)
|
|
307
342
|
const manFullCounts = new Map<ManifoldKind, number>()
|
|
308
343
|
const manRoughOnlyCounts = new Map<ManifoldKind, number>()
|
|
309
|
-
|
|
344
|
+
const manFullNodeIds = new Map<ManifoldKind, string[]>()
|
|
345
|
+
const manRoughOnlyNodeIds = new Map<ManifoldKind, string[]>()
|
|
346
|
+
for (const [key, n] of allEntries) {
|
|
310
347
|
if (n.type !== 'plumbing:manifold') continue
|
|
348
|
+
const nid = resolveEntryNodeId(key, n)
|
|
311
349
|
const k = (n.manifoldKind as ManifoldKind) || 'pex-homerun'
|
|
312
350
|
if (n.roughInOnly === true) {
|
|
313
351
|
manRoughOnlyCounts.set(k, (manRoughOnlyCounts.get(k) ?? 0) + 1)
|
|
352
|
+
const list = manRoughOnlyNodeIds.get(k) ?? []
|
|
353
|
+
list.push(nid)
|
|
354
|
+
manRoughOnlyNodeIds.set(k, list)
|
|
314
355
|
} else {
|
|
315
356
|
manFullCounts.set(k, (manFullCounts.get(k) ?? 0) + 1)
|
|
357
|
+
const list = manFullNodeIds.get(k) ?? []
|
|
358
|
+
list.push(nid)
|
|
359
|
+
manFullNodeIds.set(k, list)
|
|
316
360
|
}
|
|
317
361
|
}
|
|
318
362
|
for (const [k, qty] of manFullCounts) {
|
|
319
363
|
const p = MANIFOLD_PRICES[k] ?? { mat: 295, hrs: 3.0, label: k }
|
|
320
|
-
addLine('Manifolds', p.label, 'ea', qty, p.mat, qty * p.hrs)
|
|
364
|
+
addLine('Manifolds', p.label, 'ea', qty, p.mat, qty * p.hrs, manFullNodeIds.get(k))
|
|
321
365
|
}
|
|
322
366
|
for (const [k, qty] of manRoughOnlyCounts) {
|
|
323
367
|
const p = MANIFOLD_PRICES[k] ?? { mat: 295, hrs: 3.0, label: k }
|
|
324
|
-
addLine('Manifolds', `${p.label} (rough-in connection, SKU linked)`, 'ea', qty, round2(p.mat * 0.35), round2(qty * p.hrs * 0.55))
|
|
368
|
+
addLine('Manifolds', `${p.label} (rough-in connection, SKU linked)`, 'ea', qty, round2(p.mat * 0.35), round2(qty * p.hrs * 0.55), manRoughOnlyNodeIds.get(k))
|
|
325
369
|
}
|
|
326
370
|
|
|
327
371
|
// 3. Fixtures (separate linked real-world SKU/furnishing rough-in-only assemblies so porcelain/trim isn't double-billed)
|
|
328
372
|
const fixFullCounts = new Map<FixtureKind, number>()
|
|
329
373
|
const fixRoughOnlyCounts = new Map<FixtureKind, number>()
|
|
374
|
+
const fixFullNodeIds = new Map<FixtureKind, string[]>()
|
|
375
|
+
const fixRoughOnlyNodeIds = new Map<FixtureKind, string[]>()
|
|
330
376
|
for (const f of schedule.fixtures) {
|
|
331
377
|
if (f.roughInOnly) {
|
|
332
378
|
fixRoughOnlyCounts.set(f.fixtureKind, (fixRoughOnlyCounts.get(f.fixtureKind) ?? 0) + 1)
|
|
379
|
+
const list = fixRoughOnlyNodeIds.get(f.fixtureKind) ?? []
|
|
380
|
+
list.push(f.nodeId)
|
|
381
|
+
fixRoughOnlyNodeIds.set(f.fixtureKind, list)
|
|
333
382
|
} else {
|
|
334
383
|
fixFullCounts.set(f.fixtureKind, (fixFullCounts.get(f.fixtureKind) ?? 0) + 1)
|
|
384
|
+
const list = fixFullNodeIds.get(f.fixtureKind) ?? []
|
|
385
|
+
list.push(f.nodeId)
|
|
386
|
+
fixFullNodeIds.set(f.fixtureKind, list)
|
|
335
387
|
}
|
|
336
388
|
}
|
|
337
389
|
for (const [k, qty] of fixFullCounts) {
|
|
338
390
|
const p = FIXTURE_ROUGH_PRICES[k] ?? { mat: 200, hrs: 2.0 }
|
|
339
|
-
addLine('Fixtures', `${k} (rough-in + trim)`, 'ea', qty, p.mat, qty * p.hrs)
|
|
391
|
+
addLine('Fixtures', `${k} (rough-in + trim)`, 'ea', qty, p.mat, qty * p.hrs, fixFullNodeIds.get(k))
|
|
340
392
|
}
|
|
341
393
|
for (const [k, qty] of fixRoughOnlyCounts) {
|
|
342
394
|
const p = FIXTURE_ROUGH_PRICES[k] ?? { mat: 200, hrs: 2.0 }
|
|
343
|
-
addLine('Fixtures', `${k} (rough-in stub-out, SKU linked)`, 'ea', qty, round2(p.mat * 0.35), round2(qty * p.hrs * 0.55))
|
|
395
|
+
addLine('Fixtures', `${k} (rough-in stub-out, SKU linked)`, 'ea', qty, round2(p.mat * 0.35), round2(qty * p.hrs * 0.55), fixRoughOnlyNodeIds.get(k))
|
|
344
396
|
}
|
|
345
397
|
|
|
346
398
|
// 4. Pipe & Tubing (with 10% waste factor)
|
|
399
|
+
const pipeRunEntries: {
|
|
400
|
+
readonly nodeId: string
|
|
401
|
+
readonly system: string
|
|
402
|
+
readonly material: string
|
|
403
|
+
readonly nominalSize: string
|
|
404
|
+
}[] = []
|
|
405
|
+
const pipeRunIdsByKey = new Map<string, string[]>()
|
|
406
|
+
for (const [key, n] of allEntries) {
|
|
407
|
+
if (n.type !== 'plumbing:pipe-run' || n.visible === false) continue
|
|
408
|
+
const nid = resolveEntryNodeId(key, n)
|
|
409
|
+
const system = String(n.system || 'cold-water')
|
|
410
|
+
const material = String(n.material || 'pex-a')
|
|
411
|
+
const nominalSize = String(n.nominalSize || '1/2"')
|
|
412
|
+
pipeRunEntries.push({ nodeId: nid, system, material, nominalSize })
|
|
413
|
+
const mapKey = `${system}|${material}|${nominalSize}`
|
|
414
|
+
const list = pipeRunIdsByKey.get(mapKey) ?? []
|
|
415
|
+
list.push(nid)
|
|
416
|
+
pipeRunIdsByKey.set(mapKey, list)
|
|
417
|
+
}
|
|
347
418
|
let totalPipeFt = 0
|
|
348
419
|
let totalDwvFt = 0
|
|
349
420
|
let totalSupplyFt = 0
|
|
@@ -364,12 +435,14 @@ export function buildPlumbingBom(
|
|
|
364
435
|
qty,
|
|
365
436
|
p.matPerUnit,
|
|
366
437
|
(billedFt / 100) * p.hrsPer100Ft,
|
|
438
|
+
pipeRunIdsByKey.get(`${row.system}|${row.material}|${row.nominalSize}`),
|
|
367
439
|
)
|
|
368
440
|
}
|
|
369
441
|
|
|
370
442
|
// 5. Fittings, Hangers, P-Traps, Cleanouts, Angle Stops & Consumables
|
|
371
443
|
const externalSupplyKeys = new Set<string>()
|
|
372
|
-
|
|
444
|
+
const externalSupplyNodeIds: string[] = []
|
|
445
|
+
for (const [key, n] of allEntries) {
|
|
373
446
|
if (
|
|
374
447
|
n.type === 'plumbing:pipe-run' &&
|
|
375
448
|
(n.system === 'cold-water' || n.system === 'hot-water') &&
|
|
@@ -379,22 +452,33 @@ export function buildPlumbingBom(
|
|
|
379
452
|
const target = nodes[n.targetNodeId]
|
|
380
453
|
if (target && !target.type.startsWith('plumbing:')) {
|
|
381
454
|
externalSupplyKeys.add(`${n.system}:${n.targetNodeId}`)
|
|
455
|
+
externalSupplyNodeIds.push(resolveEntryNodeId(key, n), resolveEntryNodeId(n.targetNodeId, target))
|
|
382
456
|
}
|
|
383
457
|
}
|
|
384
458
|
}
|
|
385
459
|
const externalSupplyStops = externalSupplyKeys.size
|
|
386
460
|
const fixTotal = schedule.fixtures.length
|
|
387
|
-
const
|
|
461
|
+
const dwvFixtures = schedule.fixtures.filter((f) => f.drainSize !== null || f.dfu > 0)
|
|
462
|
+
const dwvFixtureCount = dwvFixtures.length
|
|
463
|
+
const supplyFixtures = schedule.fixtures.filter((f) => f.supplySize !== null || f.wsfuTotal > 0)
|
|
388
464
|
const supplyFixtureCount =
|
|
389
|
-
|
|
465
|
+
supplyFixtures.length + externalSupplyStops
|
|
390
466
|
const hasDwvScope = totalDwvFt > 0 || dwvFixtureCount > 0
|
|
391
467
|
const hasSupplyScope = totalSupplyFt > 0 || supplyFixtureCount > 0
|
|
392
468
|
if (fixTotal > 0 || totalPipeFt > 0) {
|
|
393
|
-
const
|
|
469
|
+
const pTrapFixtures = schedule.fixtures.filter(
|
|
394
470
|
(f) => FIXTURE_SPECS[f.fixtureKind]?.needsPTrap && nodes[f.nodeId]?.hasPTrap !== false,
|
|
395
|
-
)
|
|
471
|
+
)
|
|
472
|
+
const pTraps = pTrapFixtures.length
|
|
473
|
+
const cleanoutEntries = allEntries.filter(([, n]) => n.type === 'plumbing:pipe-run' && n.hasCleanout)
|
|
474
|
+
const dwvRunNodeIds = pipeRunEntries
|
|
475
|
+
.filter((r) => r.system === 'dwv-drain' || r.system === 'dwv-vent')
|
|
476
|
+
.map((r) => r.nodeId)
|
|
477
|
+
const supplyRunNodeIds = pipeRunEntries
|
|
478
|
+
.filter((r) => r.system === 'cold-water' || r.system === 'hot-water' || r.system === 'hot-recirc')
|
|
479
|
+
.map((r) => r.nodeId)
|
|
396
480
|
const cleanouts = hasDwvScope
|
|
397
|
-
? Math.max(2,
|
|
481
|
+
? Math.max(2, cleanoutEntries.length)
|
|
398
482
|
: 0
|
|
399
483
|
const dwvFittings = hasDwvScope ? Math.ceil(dwvFixtureCount * 3 + totalDwvFt / 10) : 0
|
|
400
484
|
const supplyFittings = hasSupplyScope ? Math.ceil(supplyFixtureCount * 4 + totalSupplyFt / 15) : 0
|
|
@@ -411,18 +495,33 @@ export function buildPlumbingBom(
|
|
|
411
495
|
'mop-sink',
|
|
412
496
|
'drinking-fountain',
|
|
413
497
|
])
|
|
498
|
+
const angleStopNodeIds: string[] = []
|
|
414
499
|
const angleStops =
|
|
415
500
|
schedule.fixtures.reduce((sum, f) => {
|
|
416
501
|
if (NO_ANGLE_STOP_FIXTURES.has(f.fixtureKind)) return sum
|
|
417
|
-
|
|
502
|
+
const stops = (f.wsfuCold > 0 ? 1 : 0) + (f.wsfuHot > 0 ? 1 : 0)
|
|
503
|
+
if (stops > 0) angleStopNodeIds.push(f.nodeId)
|
|
504
|
+
return sum + stops
|
|
418
505
|
}, 0) + externalSupplyStops
|
|
506
|
+
angleStopNodeIds.push(...externalSupplyNodeIds)
|
|
507
|
+
const cleanoutNodeIds =
|
|
508
|
+
cleanoutEntries.length > 0
|
|
509
|
+
? cleanoutEntries.map(([key, n]) => resolveEntryNodeId(key, n))
|
|
510
|
+
: [...dwvRunNodeIds, ...dwvFixtures.map((f) => f.nodeId)]
|
|
419
511
|
|
|
420
|
-
addLine('Fittings & Accessories', 'DWV Fittings (Wyes, Combos, Sweeps, San-Tees)', 'ea', dwvFittings, 7.5, dwvFittings * 0.08
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
addLine('Fittings & Accessories', '
|
|
425
|
-
|
|
512
|
+
addLine('Fittings & Accessories', 'DWV Fittings (Wyes, Combos, Sweeps, San-Tees)', 'ea', dwvFittings, 7.5, dwvFittings * 0.08, [
|
|
513
|
+
...dwvFixtures.map((f) => f.nodeId),
|
|
514
|
+
...dwvRunNodeIds,
|
|
515
|
+
])
|
|
516
|
+
addLine('Fittings & Accessories', 'Supply Fittings & Crimp/Expansion Rings', 'ea', supplyFittings, 4.2, supplyFittings * 0.05, [
|
|
517
|
+
...supplyFixtures.map((f) => f.nodeId),
|
|
518
|
+
...externalSupplyNodeIds,
|
|
519
|
+
...supplyRunNodeIds,
|
|
520
|
+
])
|
|
521
|
+
addLine('Fittings & Accessories', 'P-Trap Assemblies (1-1/2" / 2")', 'ea', pTraps, 16, pTraps * 0.25, pTrapFixtures.map((f) => f.nodeId))
|
|
522
|
+
addLine('Fittings & Accessories', 'Cleanout Tees & Brass/PVC Plugs', 'ea', cleanouts, 24, cleanouts * 0.4, cleanoutNodeIds)
|
|
523
|
+
addLine('Fittings & Accessories', 'Quarter-Turn Angle Stops & Braided Supply Lines', 'ea', angleStops, 18, angleStops * 0.15, angleStopNodeIds)
|
|
524
|
+
addLine('Fittings & Accessories', 'Pipe Hangers, J-Hooks, Nail Plates & Solvent Cement', 'ea', hangers, 2.5, hangers * 0.04, pipeRunEntries.map((r) => r.nodeId))
|
|
426
525
|
}
|
|
427
526
|
|
|
428
527
|
const subtotalMaterialUsd = round2(lines.reduce((s, l) => s + l.materialUsd, 0))
|
|
@@ -471,3 +570,104 @@ export function formatPlumbingBomCsv(bom: PlumbingBomResult): string {
|
|
|
471
570
|
rows.push(['Summary', 'Grand Total', '', '', '', round2(bom.subtotalMaterialUsd + bom.markupUsd + bom.taxUsd).toFixed(2), bom.totalLaborHours.toFixed(2), bom.subtotalLaborUsd.toFixed(2), bom.grandTotalUsd.toFixed(2)].join(','))
|
|
472
571
|
return [header.join(','), ...rows].join('\n')
|
|
473
572
|
}
|
|
573
|
+
|
|
574
|
+
function classifyPlumbingBomLine(line: PlumbingBomLine): {
|
|
575
|
+
readonly costScope: BomCostScope
|
|
576
|
+
readonly csiMasterFormat?: string
|
|
577
|
+
readonly dedupeKey?: string
|
|
578
|
+
} {
|
|
579
|
+
const lower = line.item.toLowerCase()
|
|
580
|
+
if (line.category === 'Fixtures') {
|
|
581
|
+
if (/\b(?:rough-?in|carrier|flange|stub-?out)\b/.test(lower)) {
|
|
582
|
+
return { costScope: 'rough-in', csiMasterFormat: '22 41 00' }
|
|
583
|
+
}
|
|
584
|
+
if (lower.includes('water closet') || lower.includes('toilet')) {
|
|
585
|
+
return { costScope: 'allowance', csiMasterFormat: '22 41 13', dedupeKey: 'fixture:water-closet' }
|
|
586
|
+
}
|
|
587
|
+
if (lower.includes('lavatory')) {
|
|
588
|
+
return { costScope: 'allowance', csiMasterFormat: '22 41 16', dedupeKey: 'fixture:lavatory' }
|
|
589
|
+
}
|
|
590
|
+
if (lower.includes('kitchen sink')) {
|
|
591
|
+
return { costScope: 'allowance', csiMasterFormat: '22 41 16', dedupeKey: 'fixture:kitchen-sink' }
|
|
592
|
+
}
|
|
593
|
+
if (lower.includes('bathtub') || lower.includes('tub-shower') || lower.includes('tub / shower')) {
|
|
594
|
+
return { costScope: 'allowance', csiMasterFormat: '22 41 19', dedupeKey: 'fixture:bathtub' }
|
|
595
|
+
}
|
|
596
|
+
if (lower.includes('shower')) {
|
|
597
|
+
return { costScope: 'allowance', csiMasterFormat: '22 41 19', dedupeKey: 'fixture:shower' }
|
|
598
|
+
}
|
|
599
|
+
return { costScope: 'allowance', csiMasterFormat: '22 41 00' }
|
|
600
|
+
}
|
|
601
|
+
if (line.category === 'Equipment' || line.category === 'Manifolds') {
|
|
602
|
+
return { costScope: 'assembly' }
|
|
603
|
+
}
|
|
604
|
+
if (line.category === 'Fittings & Accessories') {
|
|
605
|
+
return { costScope: 'consumable' }
|
|
606
|
+
}
|
|
607
|
+
if (/\b(?:dwv|abs|pvc|drain|vent|waste|sanitary|cast\s*iron|no-hub)\b/.test(lower)) {
|
|
608
|
+
return { costScope: 'rough-in', csiMasterFormat: '22 13 16' }
|
|
609
|
+
}
|
|
610
|
+
return { costScope: 'rough-in', csiMasterFormat: '22 11 16' }
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Convert a `PlumbingBomResult` into a canonical `@kruschdev/pascal-mep-kernel/bom` fragment (`pascal-bom/1.x`).
|
|
615
|
+
*/
|
|
616
|
+
export function toPlumbingPascalBom(
|
|
617
|
+
bom: PlumbingBomResult,
|
|
618
|
+
options: { readonly laborRateUsd?: number } = {},
|
|
619
|
+
): PascalBomFragment {
|
|
620
|
+
const effectiveLaborRate =
|
|
621
|
+
typeof options.laborRateUsd === 'number' && Number.isFinite(options.laborRateUsd)
|
|
622
|
+
? Math.max(0, options.laborRateUsd)
|
|
623
|
+
: 125
|
|
624
|
+
const lines = bom.lines.map((line) => {
|
|
625
|
+
const meta = classifyPlumbingBomLine(line)
|
|
626
|
+
return createBomLine({
|
|
627
|
+
sourcePlugin: 'pascal-plugin-plumbing',
|
|
628
|
+
trade: 'plumbing',
|
|
629
|
+
category: line.category,
|
|
630
|
+
costScope: meta.costScope,
|
|
631
|
+
...(meta.csiMasterFormat ? { csiMasterFormat: meta.csiMasterFormat } : {}),
|
|
632
|
+
...(meta.dedupeKey ? { dedupeKey: meta.dedupeKey } : {}),
|
|
633
|
+
sku: slugifyBomSku('PLB', line.item),
|
|
634
|
+
name: line.item,
|
|
635
|
+
quantity: line.quantity,
|
|
636
|
+
unit: line.unit,
|
|
637
|
+
unitMaterialUsd: line.unitMaterialUsd,
|
|
638
|
+
extendedMaterialUsd: line.materialUsd,
|
|
639
|
+
extendedLaborHours: line.laborHours,
|
|
640
|
+
laborRateUsd: effectiveLaborRate,
|
|
641
|
+
extendedLaborUsd: line.laborUsd,
|
|
642
|
+
...(line.nodeIds && line.nodeIds.length > 0 ? { nodeIds: line.nodeIds } : {}),
|
|
643
|
+
})
|
|
644
|
+
})
|
|
645
|
+
|
|
646
|
+
return {
|
|
647
|
+
plugin: 'pascal-plugin-plumbing',
|
|
648
|
+
pluginVersion: '0.2.1',
|
|
649
|
+
laborIncluded: true,
|
|
650
|
+
lines,
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
export interface PascalBomBuildOptions {
|
|
655
|
+
readonly injectedParts?: readonly CallerInjectedPart[]
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
export function buildPlumbingPascalBom(
|
|
659
|
+
nodes: Readonly<Record<string, SceneNodeLike>>,
|
|
660
|
+
options: PlumbingPricingOptions = {},
|
|
661
|
+
bomOptions: PascalBomBuildOptions = {},
|
|
662
|
+
): PascalBomFragment {
|
|
663
|
+
const effectiveLaborRate =
|
|
664
|
+
typeof options.laborRateUsd === 'number' && Number.isFinite(options.laborRateUsd)
|
|
665
|
+
? Math.max(0, options.laborRateUsd)
|
|
666
|
+
: 125
|
|
667
|
+
const fragment = toPlumbingPascalBom(buildPlumbingBom(nodes, { ...options, laborRateUsd: effectiveLaborRate }), {
|
|
668
|
+
laborRateUsd: effectiveLaborRate,
|
|
669
|
+
})
|
|
670
|
+
return Array.isArray(bomOptions.injectedParts) && bomOptions.injectedParts.length > 0
|
|
671
|
+
? applyCallerInjectedPartsToFragment(fragment, bomOptions.injectedParts)
|
|
672
|
+
: fragment
|
|
673
|
+
}
|