formlab-mcp 0.6.90 → 0.6.92
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/README.md +4 -4
- package/package.json +1 -1
- package/server.json +2 -2
- package/tools/documents.js +1 -1
- package/tools/ingredients.js +7 -2
- package/tools/lab.js +33 -2
- package/vendor/cost.js +57 -28
- package/vendor/fragrance.js +103 -18
- package/vendor/nutrition-label.js +3 -3
package/README.md
CHANGED
|
@@ -34,15 +34,15 @@ Ask Claude (or another MCP client) things like:
|
|
|
34
34
|
| `get_fragrance_compliance` | The formula's **Fragrance** tab (Pro, live workspace only): each fragrance material's % in the finished product against its IFRA limit for the product category, the highest dosage that passes and the material that limits it, and the EU fragrance allergens to name on the label. Optional what-if `category`, `use`, `dosage` ("can this oil go into a body lotion at 2%?"). Limits come only from the certificates the lab has on file; anything missing makes the state `incomplete`. Not a certification. `get_formulation` carries the same summary as `fragranceCompliance`. |
|
|
35
35
|
| `find_similar_formulations` | Find formulas using a given ingredient ≥ threshold % |
|
|
36
36
|
| `compare_formulations` | Pairwise side-by-side composition diff |
|
|
37
|
-
| `list_ingredients` | Filtered list of raw materials. Filters: `family`, `supplier`, `name_contains`, `in_stock_only`, `ingredient_class` (small-molecule / surfactant / polymer / extract / fragrance / pigment / sequence / mixture), `sequence_contains` (e.g. `KTTKS` → Matrixyl), `taxon_contains` (e.g. `Centella`) |
|
|
37
|
+
| `list_ingredients` | Filtered list of raw materials. Filters: `family`, `supplier`, `name_contains`, `lot_number` (the ingredient a lot belongs to), `in_stock_only`, `ingredient_class` (small-molecule / surfactant / polymer / extract / fragrance / pigment / sequence / mixture), `sequence_contains` (e.g. `KTTKS` → Matrixyl), `taxon_contains` (e.g. `Centella`) |
|
|
38
38
|
| `get_ingredient` | Full record + supplier / **cost ($/kg)** / stock / chemical name / molecular weight / storage / formulations using it, plus **GHS safety** (pictograms, H/P codes, signal word), **per-jurisdiction regulatory status**, **approved sources** (the suppliers / manufacturers qualified to supply this material — ASL/AML), and **inventory lots** (balances + expiry + the source each was received from). Returns every class-specific sub-object when present: `sequence` (peptide / oligo), `taxon` (NCBI ID + scientific name), `ingredientClass`, `extractDetails`, `sequenceDetails`, `polymerDetails`, `surfactantDetails`, `pigmentDetails`, `fragranceDetails`, and its **custom fields** with units (`customFields`: protein / carb / fat in g/100g, solids %… — what theoretical parameters read), and its **reactive groups** (EEW, AHEW, OH number, NCO %, acid / amine value: as entered, in the datasheet's terms and meq/g, with any row the app ignores and why) |
|
|
39
|
-
| `list_lots` | Inventory lots across ingredients (each a received batch with its own remaining balance, supplier, expiry, **unit cost**, **status** — `active` / `hold` / `quarantine` / `rejected`; held lots are blocked from consumption, with a `holdReason` — and the **approved source** it was received from: `source.supplier` + `source.manufacturer`, where recalls hinge on the manufacturer). Each lot also reports its **Certificate of Analysis** (`coa`: linked, or matched by lot number) and `coaMissing` for an in-stock lot without one. Filters: `ingredient_id`, `expiring_within_days`, `status` (e.g. `hold` to find lots held for a recall), `missing_coa` |
|
|
39
|
+
| `list_lots` | Inventory lots across ingredients (each a received batch with its own remaining balance, supplier, expiry, **unit cost**, **status** — `active` / `hold` / `quarantine` / `rejected`; held lots are blocked from consumption, with a `holdReason` — and the **approved source** it was received from: `source.supplier` + `source.manufacturer`, where recalls hinge on the manufacturer). Each lot also reports its **Certificate of Analysis** (`coa`: linked, or matched by lot number) and `coaMissing` for an in-stock lot without one. Filters: `ingredient_id`, `lot_number`, `expiring_within_days`, `status` (e.g. `hold` to find lots held for a recall), `missing_coa` |
|
|
40
40
|
| `list_suppliers` | Supplier / manufacturer records with roll-ups — ingredients approved, lots received / on hand (+ value at paid cost), qualified / trial / disqualified source counts, last receipt; lots count by supplier **and** by manufacturer |
|
|
41
41
|
| `get_supplier` | One supplier in full: record, every ingredient it's an approved source for, every lot from it, and the **recall trace** (batches that consumed those lots → products, shipments, samples, sub-batches; lots on hold flagged) |
|
|
42
42
|
| `list_documents` | The document register (same as the app's Documents page): ingredient SDS / PDS / CoA / other with lot, version, source and expiry; test and notebook attachments; per-record uploads and links (formulas, batches, samples, suppliers, equipment…). File **metadata** only, never the text inside a file, with who added each file (`addedBy`) and when. Filters: `type`, `record`, `linked`, `query`, `lot`, `format`, `expiry`, `expiring_within_days`, `without_expiry`, `uploaded_within_days`, `added_by`. A `summary` block carries the page's tile counts: expired, expiring in 30 days, SDS/CoA without expiry, ingredients missing an SDS (+ coverage %), lots in stock without a CoA, added last 7 days |
|
|
43
43
|
| `list_inventory` | Portfolio stock rollup — one row per ingredient with on-hand qty, summed lot balance, nearest expiry, and a low-stock flag (on-hand ≤ `reorderThreshold`, or zero). Filters: `low_stock_only`, `expiring_within_days`, `family` |
|
|
44
|
-
| `list_batches` | Filtered list of production / lab-prep events; each row has **`bestBy`**; filter by `best_by_before` (past best-by = today) or `lots_expire_first` |
|
|
45
|
-
| `get_batch` | Full record + actual composition, measured/derived **actual volume** (mass ÷ density, never a sum of per-ingredient volumes) and **actual mass** (yield, else summed as-prepared inputs — mL rows through that ingredient's density — else measured volume × density), **estimatedVolume** (mass ÷ the formula's finished density when no actual exists, flagged `estimate: true`), **plannedMass** for volume-target batches (target × finished density) and **formulaFinishedDensity**, the **process** method + any **process-factor values** (DOE inputs), samples + blend lineage, and — as a finished-goods lot — its **`bestBy`** (the adjusted date with its change, reason, note and retest report, else prepared date + shelf life; `lotsExpiringFirst` = lots it drew from that expire sooner), its storage **`location`** + finished-goods **`stockLedger`** (shipments out + adjustments; `shippedQty` total), and its **theoretical parameters computed on the batch as made** (actual composition when logged — `basis: "actual"` — else the recipe; the batch's own parameter list when it overrides the formula's) |
|
|
44
|
+
| `list_batches` | Filtered list of production / lab-prep events; each row has **`bestBy`**; filter by `best_by_before` (past best-by = today) or `lots_expire_first`, `on_hold`, `made_with_lot` (batches that drew from a recalled lot), `held_lot` (drew from any lot now on hold) |
|
|
45
|
+
| `get_batch` | Full record + **`lotsUsed`** (raw lots drawn, with each lot's status and hold reason now) + actual composition, measured/derived **actual volume** (mass ÷ density, never a sum of per-ingredient volumes) and **actual mass** (yield, else summed as-prepared inputs — mL rows through that ingredient's density — else measured volume × density), **estimatedVolume** (mass ÷ the formula's finished density when no actual exists, flagged `estimate: true`), **plannedMass** for volume-target batches (target × finished density) and **formulaFinishedDensity**, the **process** method + any **process-factor values** (DOE inputs), samples + blend lineage, and — as a finished-goods lot — its **`bestBy`** (the adjusted date with its change, reason, note and retest report, else prepared date + shelf life; `lotsExpiringFirst` = lots it drew from that expire sooner), its storage **`location`** + finished-goods **`stockLedger`** (shipments out + adjustments; `shippedQty` total), and its **theoretical parameters computed on the batch as made** (actual composition when logged — `basis: "actual"` — else the recipe; the batch's own parameter list when it overrides the formula's) |
|
|
46
46
|
| `list_samples` | Filtered list of physical specimens |
|
|
47
47
|
| `get_sample` | Full record + canonical variant + test reports + blend lineage + its stability pulls (next pull, or pulled at) |
|
|
48
48
|
| `list_test_results` | Filtered list of test reports (by sample, parameter, **measured-value range** (`value_min`/`value_max` — a curve at its final point, a distribution at its spec's statistic or D50), **grade** (`min_grade`/`max_grade` on a ranked scale), **text value** (`value_equals`), **run condition** (`condition`), date, or lab) |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formlab-mcp",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.92",
|
|
4
4
|
"mcpName": "io.github.juliu1980/formlab-mcp",
|
|
5
5
|
"description": "Read-only Model Context Protocol server for FormLab. Lets Claude and other MCP clients read and analyze your FormLab data, from a local export file or your live cloud workspace.",
|
|
6
6
|
"homepage": "https://formvix.com/mcp",
|
package/server.json
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "io.github.juliu1980/formlab-mcp",
|
|
4
4
|
"description": "Read-only MCP server for FormLab formulation data: a local export file or your live cloud workspace.",
|
|
5
|
-
"version": "0.6.
|
|
5
|
+
"version": "0.6.92",
|
|
6
6
|
"websiteUrl": "https://formvix.com/mcp",
|
|
7
7
|
"packages": [
|
|
8
8
|
{
|
|
9
9
|
"registryType": "npm",
|
|
10
10
|
"identifier": "formlab-mcp",
|
|
11
|
-
"version": "0.6.
|
|
11
|
+
"version": "0.6.92",
|
|
12
12
|
"runtimeHint": "npx",
|
|
13
13
|
"transport": {
|
|
14
14
|
"type": "stdio"
|
package/tools/documents.js
CHANGED
|
@@ -125,7 +125,7 @@ const list_documents = {
|
|
|
125
125
|
inputSchema: {
|
|
126
126
|
type: 'object',
|
|
127
127
|
properties: {
|
|
128
|
-
type: { type: 'array', items: { type: 'string' }, description: 'Document types to include: SDS, PDS, COA, OTHER (ingredient documents), TEST, NOTE, FILE (upload), LINK.' },
|
|
128
|
+
type: { type: 'array', items: { type: 'string' }, description: 'Document types to include: SDS, PDS, COA, FRAG, OTHER (ingredient documents; FRAG = IFRA certificates and fragrance allergen declarations), TEST, NOTE, FILE (upload), LINK.' },
|
|
129
129
|
record: { type: 'string', description: 'Kind of record the file is attached to: ingredient, formulation, batch, sample, test, notebook, project, supplier, equipment, template, procedureTemplate, parameter.' },
|
|
130
130
|
linked: { type: 'string', description: 'Case-insensitive substring of the linked record\'s name / UID.' },
|
|
131
131
|
query: { type: 'string', description: 'Case-insensitive substring over file name, linked record, lot and source.' },
|
package/tools/ingredients.js
CHANGED
|
@@ -121,13 +121,14 @@ function _lotSourceInfo(l) {
|
|
|
121
121
|
const list_ingredients = {
|
|
122
122
|
definition: {
|
|
123
123
|
name: 'list_ingredients',
|
|
124
|
-
description: 'List ingredients (raw materials) in the FormLab library, optionally filtered by family, supplier, or
|
|
124
|
+
description: 'List ingredients (raw materials) in the FormLab library, optionally filtered by family, supplier, name pattern, or lot number (lot_number finds the ingredient a recalled lot belongs to). Returns metadata; use get_ingredient for full details.',
|
|
125
125
|
inputSchema: {
|
|
126
126
|
type: 'object',
|
|
127
127
|
properties: {
|
|
128
128
|
family: { type: 'string', description: 'Filter by family (e.g. "Pigment", "Surfactant"). Case-insensitive substring.' },
|
|
129
129
|
supplier: { type: 'string', description: 'Filter by supplier name. Case-insensitive substring.' },
|
|
130
130
|
name_contains: { type: 'string', description: 'Case-insensitive substring on ingredient name.' },
|
|
131
|
+
lot_number: { type: 'string', description: 'Only ingredients with a lot whose lot number or lot UID contains this (case-insensitive), e.g. "BIT-9912" from a supplier recall. Disposed lots count.' },
|
|
131
132
|
in_stock_only: { type: 'boolean', description: 'When true, return only ingredients with stockOnHand > 0.' },
|
|
132
133
|
ingredient_class: { type: 'string', description: 'Filter by symbolic class: small-molecule, surfactant, polymer, extract, fragrance, pigment, sequence, mixture.' },
|
|
133
134
|
sequence_contains: { type: 'string', description: 'Case-insensitive substring match on peptide / oligo sequence (e.g. "KTTKS" matches Matrixyl).' },
|
|
@@ -141,8 +142,10 @@ const list_ingredients = {
|
|
|
141
142
|
const { db } = getStore();
|
|
142
143
|
const limit = Math.min(1000, Math.max(1, args.limit || 100));
|
|
143
144
|
const norm = (s) => String(s || '').toLowerCase();
|
|
145
|
+
const lotIngs = args.lot_number ? new Set((db.lots || []).filter(l => l && !l._trashed && !l.deletedAt && (norm(l.lotNumber).includes(norm(args.lot_number)) || norm(l.uid).includes(norm(args.lot_number)))).map(l => l.ingredientId)) : null;
|
|
144
146
|
const filtered = (db.ingredients || []).filter(i => {
|
|
145
147
|
if (!i || i._trashed) return false;
|
|
148
|
+
if (lotIngs && !lotIngs.has(i.id)) return false;
|
|
146
149
|
if (args.family && !norm(i.family).includes(norm(args.family))) return false;
|
|
147
150
|
if (args.supplier && !norm(i.supplier).includes(norm(args.supplier))) return false;
|
|
148
151
|
if (args.name_contains && !norm(i.name).includes(norm(args.name_contains))) return false;
|
|
@@ -346,11 +349,12 @@ const find_by_smarts = {
|
|
|
346
349
|
const list_lots = {
|
|
347
350
|
definition: {
|
|
348
351
|
name: 'list_lots',
|
|
349
|
-
description: 'List inventory lots (received batches of an ingredient, each with its own remaining balance, supplier, expiry, and unit cost). Each lot also carries the approved source it was received from (source.supplier + source.manufacturer; recalls hinge on the manufacturer), or null for lots predating sources. Optionally filter by ingredient, expiring-within-days, or status. A lot\'s status can be "active", "hold" (a manual QC / recall hold — see holdReason), "quarantine", or "rejected"; the last three are blocked from auto-consumption. For one ingredient\'s full lots + traceability, use get_ingredient.',
|
|
352
|
+
description: 'List inventory lots (received batches of an ingredient, each with its own remaining balance, supplier, expiry, and unit cost). Each lot also carries the approved source it was received from (source.supplier + source.manufacturer; recalls hinge on the manufacturer), or null for lots predating sources. Optionally filter by ingredient, lot number, expiring-within-days, or status. A lot\'s status can be "active", "hold" (a manual QC / recall hold — see holdReason), "quarantine", or "rejected"; the last three are blocked from auto-consumption. For one ingredient\'s full lots + traceability, use get_ingredient.',
|
|
350
353
|
inputSchema: {
|
|
351
354
|
type: 'object',
|
|
352
355
|
properties: {
|
|
353
356
|
ingredient_id: { type: 'string', description: 'Only lots for this ingredient (internal id or UID, e.g. ING-001).' },
|
|
357
|
+
lot_number: { type: 'string', description: 'Only lots whose lot number or lot UID contains this (case-insensitive), e.g. "BIT-9912" from a supplier recall.' },
|
|
354
358
|
expiring_within_days: { type: 'number', description: 'Only lots whose expiryDate is within this many days from now (negative days = already expired are always included).' },
|
|
355
359
|
status: { type: 'string', description: 'Filter by lot status: "active", "hold", "quarantine", or "rejected". Held/quarantined/rejected lots are blocked from auto-consumption (use "hold" to find lots put on hold for a QC / recall).' },
|
|
356
360
|
missing_coa: { type: 'boolean', description: 'true = only lots still in stock (not rejected) that have no Certificate of Analysis — neither linked nor a CoA on the ingredient with the same lot number. Same list as the app\'s Documents → "Lots in stock without CoA".' },
|
|
@@ -372,6 +376,7 @@ const list_lots = {
|
|
|
372
376
|
const rows = (db.lots || []).filter(l => {
|
|
373
377
|
if (!l || l._trashed) return false;
|
|
374
378
|
if (ing && l.ingredientId !== ing.id) return false;
|
|
379
|
+
if (args.lot_number) { const w = String(args.lot_number).toLowerCase(); if (!String(l.lotNumber || '').toLowerCase().includes(w) && !String(l.uid || '').toLowerCase().includes(w)) return false; }
|
|
375
380
|
if (args.missing_coa === true && !_lotCoaInfo(l, ingById.get(l.ingredientId)).coaMissing) return false;
|
|
376
381
|
if (args.status && String(l.status || 'active').toLowerCase() !== String(args.status).toLowerCase()) return false;
|
|
377
382
|
if (args.expiring_within_days != null) {
|
package/tools/lab.js
CHANGED
|
@@ -284,10 +284,26 @@ function _trimSample(s, formulationsById, batchesById) {
|
|
|
284
284
|
};
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
+
// Raw lots a batch drew, net of material returned to the lot, with each lot's status now (0.6.92).
|
|
288
|
+
function _batchLotsUsed(db, batchId) {
|
|
289
|
+
const net = new Map();
|
|
290
|
+
(db.stockMovements || []).forEach(m => {
|
|
291
|
+
if (!m || m.batchId !== batchId || !m.lotId) return;
|
|
292
|
+
const d = Number(m.delta); if (!Number.isFinite(d)) return;
|
|
293
|
+
net.set(m.lotId, (net.get(m.lotId) || 0) - d);
|
|
294
|
+
});
|
|
295
|
+
return [...net].filter(([, q]) => q > 0.0000005).map(([lotId, q]) => {
|
|
296
|
+
const l = (db.lots || []).find(x => x && x.id === lotId) || {};
|
|
297
|
+
const ing = (db.ingredients || []).find(i => i && i.id === l.ingredientId);
|
|
298
|
+
return { lotId, lotUid: l.uid || '', lotNumber: l.lotNumber || '', ingredient: ing ? (ing.uid || ing.name || '') : '', ingredientName: ing ? (ing.name || '') : '',
|
|
299
|
+
qty: Math.round(q * 1e6) / 1e6, unit: l.unit || '', status: l.status || 'active', holdReason: l.status === 'hold' ? (l.holdReason || '') : '' };
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
287
303
|
const list_batches = {
|
|
288
304
|
definition: {
|
|
289
305
|
name: 'list_batches',
|
|
290
|
-
description: 'List batches (production / lab-prep events), optionally filtered by formulation, status, origin-only (hides batches derived from other batches), best-by before a date,
|
|
306
|
+
description: 'List batches (production / lab-prep events), optionally filtered by formulation, status, origin-only (hides batches derived from other batches), best-by before a date, batches whose ingredient lots expire before their best-by, batches made with a given raw lot (made_with_lot), or with a lot now on hold (held_lot). Each row carries `bestBy` (date, adjusted or from shelf life, the reason, lots expiring first). Returns metadata; use get_batch for the full consumption ledger and samples.',
|
|
291
307
|
inputSchema: {
|
|
292
308
|
type: 'object',
|
|
293
309
|
properties: {
|
|
@@ -299,6 +315,8 @@ const list_batches = {
|
|
|
299
315
|
lots_expire_first: { type: 'boolean', description: 'When true, only batches that drew from an ingredient lot expiring before the batch\'s best-by (the app\'s ⚠ on Best by).' },
|
|
300
316
|
shipped_to: { type: 'string', description: 'Only batches with a shipment whose note (customer / destination / PO) contains this text, case-insensitive. Use it to find which batch went to a customer.' },
|
|
301
317
|
on_hold: { type: 'boolean', description: 'When true, only finished batches currently on hold (no shipment can be recorded until released).' },
|
|
318
|
+
made_with_lot: { type: 'string', description: 'Only batches that drew from this raw lot: its lot number (e.g. "BIT-9912", from a supplier recall), lot UID, or internal id. Answers "which batches used the recalled lot?"; pair with on_hold to see which are not held yet.' },
|
|
319
|
+
held_lot: { type: 'boolean', description: 'When true, only batches that drew from a raw lot now on hold, whether or not the batch itself is held.' },
|
|
302
320
|
limit: { type: 'number', description: 'Max rows (default 50, max 500).' },
|
|
303
321
|
},
|
|
304
322
|
},
|
|
@@ -314,8 +332,18 @@ const list_batches = {
|
|
|
314
332
|
if (!f) return { error: `No formulation matched "${args.formulation_id}".` };
|
|
315
333
|
formId = f.id;
|
|
316
334
|
}
|
|
335
|
+
let lotBatches = null;
|
|
336
|
+
if (args.made_with_lot) {
|
|
337
|
+
const w = norm(args.made_with_lot).trim();
|
|
338
|
+
const lotIds = new Set((db.lots || []).filter(l => l && !l._trashed && (l.id === args.made_with_lot || norm(l.uid) === w || norm(l.lotNumber) === w)).map(l => l.id));
|
|
339
|
+
if (!lotIds.size) return { error: `No lot matched "${args.made_with_lot}" (lot number, lot UID, or id).` };
|
|
340
|
+
lotBatches = new Set((db.stockMovements || []).filter(m => m && lotIds.has(m.lotId) && m.batchId && Number(m.delta) < 0).map(m => m.batchId));
|
|
341
|
+
}
|
|
342
|
+
const heldBatches = args.held_lot ? (() => { const held = new Set((db.lots || []).filter(l => l && !l._trashed && l.status === 'hold').map(l => l.id)); return new Set((db.stockMovements || []).filter(m => m && held.has(m.lotId) && m.batchId && Number(m.delta) < 0).map(m => m.batchId)); })() : null;
|
|
317
343
|
const filtered = (db.batches || []).filter(b => {
|
|
318
344
|
if (!b || b._trashed) return false;
|
|
345
|
+
if (lotBatches && !lotBatches.has(b.id)) return false;
|
|
346
|
+
if (heldBatches && !heldBatches.has(b.id)) return false;
|
|
319
347
|
if (formId && b.formulationId !== formId) return false;
|
|
320
348
|
if (args.status && !norm(b.status).includes(norm(args.status))) return false;
|
|
321
349
|
if (args.origin_only && b.parentBatchId) return false;
|
|
@@ -341,7 +369,7 @@ const list_batches = {
|
|
|
341
369
|
const get_batch = {
|
|
342
370
|
definition: {
|
|
343
371
|
name: 'get_batch',
|
|
344
|
-
description: 'Get full details for a single batch including its actual composition (as-prepared, when logged), child samples, lineage (parent / sub-blend parents), and — treating the batch as a finished-goods lot — its storage `location` and finished-goods `stockLedger` (shipments out + adjustments; on-hand = produced − sample pulls − sub-batch draws + Σ ledger). Plus finished-product density + actual volume (measured directly or derived as actual mass ÷ measured density — never summed from per-ingredient volumes). Accepts internal id or UID. Also returns `theoreticalParameters` computed on the batch as made (its actual composition when logged — `basis: "actual"` — else the recipe of its formula), with the batch parameter list when it overrides the one on the formula; same fields as get_formulation.',
|
|
372
|
+
description: 'Get full details for a single batch including the raw lots it drew (lotsUsed: lot number, quantity, and the status of each lot now, with holdReason for a lot on hold), its actual composition (as-prepared, when logged), child samples, lineage (parent / sub-blend parents), and — treating the batch as a finished-goods lot — its storage `location` and finished-goods `stockLedger` (shipments out + adjustments; on-hand = produced − sample pulls − sub-batch draws + Σ ledger). Plus finished-product density + actual volume (measured directly or derived as actual mass ÷ measured density — never summed from per-ingredient volumes). Accepts internal id or UID. Also returns `theoreticalParameters` computed on the batch as made (its actual composition when logged — `basis: "actual"` — else the recipe of its formula), with the batch parameter list when it overrides the one on the formula; same fields as get_formulation.',
|
|
345
373
|
inputSchema: {
|
|
346
374
|
type: 'object',
|
|
347
375
|
properties: {
|
|
@@ -391,6 +419,9 @@ const get_batch = {
|
|
|
391
419
|
shippedQty: (Array.isArray(b.stockLedger) ? b.stockLedger : []).reduce((s, e) => e.kind === 'shipment' ? s + Math.abs(parseFloat(e.delta) || 0) : s, 0),
|
|
392
420
|
// Finished-batch hold: while set, the app records no shipment of this batch (QA / complaint / recall).
|
|
393
421
|
hold: (b.fgHold && b.fgHold.at) ? { since: b.fgHold.at, by: b.fgHold.by || '', reason: b.fgHold.reason || '' } : null,
|
|
422
|
+
// 0.6.92: the raw lots this batch drew (net of returns), each with its status now. A lot on hold
|
|
423
|
+
// here ("status: hold" + holdReason) is why a recall reaches this batch, held or not.
|
|
424
|
+
lotsUsed: _batchLotsUsed(getStore().db, b.id),
|
|
394
425
|
theoreticalParameters: theoreticalParams(getStore().db, 'batch', b.id),
|
|
395
426
|
};
|
|
396
427
|
},
|
package/vendor/cost.js
CHANGED
|
@@ -316,7 +316,13 @@ function getQuantityUnits() {
|
|
|
316
316
|
var its = items();
|
|
317
317
|
var pick = activeIdx >= 0 ? its[activeIdx] : (its.length === 1 ? its[0] : null);
|
|
318
318
|
if (pick) { choose(pick.getAttribute('data-val')); e.preventDefault(); }
|
|
319
|
-
} else if (e.key === 'Escape') {
|
|
319
|
+
} else if (e.key === 'Escape') {
|
|
320
|
+
// Esc closes the list only (dogfooding 26 Nov: in New Batch it also closed the dialog, and the refocus below
|
|
321
|
+
// reopened the list, left floating over the page). Marked as handled, so the dialog's Esc leaves it be.
|
|
322
|
+
e.preventDefault(); e.stopPropagation();
|
|
323
|
+
hide();
|
|
324
|
+
if (activeInput) { refocusing = true; try { activeInput.focus(); } catch (_) {} refocusing = false; }
|
|
325
|
+
}
|
|
320
326
|
}
|
|
321
327
|
|
|
322
328
|
document.addEventListener('focusin', function (e) { if (isCombo(e.target) && !refocusing) open(e.target); });
|
|
@@ -1707,27 +1713,37 @@ function deviationLegendHtml() {
|
|
|
1707
1713
|
|
|
1708
1714
|
// Effective % active for grossing up a weigh-out amount of a technical
|
|
1709
1715
|
// (impure) ingredient. Precedence:
|
|
1710
|
-
// 1. the
|
|
1711
|
-
//
|
|
1716
|
+
// 1. a lot the batch / sample PINS (lotPins, LP1) whose CoA assay is set:
|
|
1717
|
+
// that lot is the one weighed, so its assay is the basis (Jun, 25 Nov:
|
|
1718
|
+
// the remade batch weighs at the new lot's 94.1%, nominal stays 97%), else
|
|
1719
|
+
// 2. the ingredient's nominal `purity` (the stable spec / design basis), else
|
|
1720
|
+
// 3. a pinned lot with no assay → no correction (it is the lot drawn), else
|
|
1721
|
+
// 4. the purity of the active lot we'd draw next (soonest expiry, then
|
|
1712
1722
|
// oldest received) — so lot data entered on the CoA is used even with no
|
|
1713
1723
|
// nominal set, else
|
|
1714
|
-
//
|
|
1715
|
-
// A
|
|
1724
|
+
// 5. null → treat as 100% (no correction).
|
|
1725
|
+
// A value of ≥100 means "pure" → returns null (no correction).
|
|
1716
1726
|
// Used by the batch AND sample weigh-outs so both correct identically. This is
|
|
1717
1727
|
// a bench/weigh-out concept only — composition, cost, and property math keep
|
|
1718
|
-
// using the as-declared amounts.
|
|
1719
|
-
|
|
1720
|
-
|
|
1728
|
+
// using the as-declared amounts. _purityBasis also names the pinned lot when
|
|
1729
|
+
// its assay is the one used, so the weigh-out row can say so.
|
|
1730
|
+
function _purityBasis(ing, pinLotId) {
|
|
1731
|
+
const none = { purity: null, lot: null };
|
|
1732
|
+
if (!ing) return none;
|
|
1733
|
+
const ok = v => (isFinite(v) && v > 0 && v < 100) ? v : null;
|
|
1721
1734
|
const nom = parseFloat(ing.purity);
|
|
1722
|
-
|
|
1723
|
-
|
|
1735
|
+
const hasNom = isFinite(nom) && nom > 0;
|
|
1736
|
+
let pinned = null;
|
|
1724
1737
|
if (pinLotId && typeof db !== 'undefined' && Array.isArray(db.lots)) {
|
|
1725
1738
|
const pl = db.lots.find(l => l && l.id === pinLotId && l.ingredientId === ing.id);
|
|
1726
|
-
if (pl && (parseFloat(pl.qtyRemaining) || 0) > 0 && (typeof _lotIsUsable !== 'function' || _lotIsUsable(pl)))
|
|
1727
|
-
const pp = parseFloat(pl.purity);
|
|
1728
|
-
return (isFinite(pp) && pp > 0 && pp < 100) ? pp : null;
|
|
1729
|
-
}
|
|
1739
|
+
if (pl && (parseFloat(pl.qtyRemaining) || 0) > 0 && (typeof _lotIsUsable !== 'function' || _lotIsUsable(pl))) pinned = pl;
|
|
1730
1740
|
}
|
|
1741
|
+
if (pinned) {
|
|
1742
|
+
const pp = parseFloat(pinned.purity);
|
|
1743
|
+
if (isFinite(pp) && pp > 0) return { purity: ok(pp), lot: pinned };
|
|
1744
|
+
}
|
|
1745
|
+
if (hasNom) return { purity: ok(nom), lot: null };
|
|
1746
|
+
if (pinned) return none;
|
|
1731
1747
|
// No usable nominal → the purity of the lot the next draw takes (the lab's FEFO / FIFO rule over every usable lot),
|
|
1732
1748
|
// if that lot has one. It used to pick the first lot WITH a purity, so a trial drum's 68.5% grossed up a batch that
|
|
1733
1749
|
// drew a different supplier's lot with none (supplier-swap sim, 19 Nov: +46% SLES). No lot rule (off) → no fallback.
|
|
@@ -1735,17 +1751,17 @@ function effectivePurity(ing, pinLotId) {
|
|
|
1735
1751
|
? db.lots.filter(l => l.ingredientId === ing.id && (parseFloat(l.qtyRemaining) || 0) > 0
|
|
1736
1752
|
&& (typeof _lotIsUsable === 'function' ? _lotIsUsable(l) : (!l.status || l.status === 'active')))
|
|
1737
1753
|
: [];
|
|
1738
|
-
if (!lots.length) return
|
|
1754
|
+
if (!lots.length) return none;
|
|
1739
1755
|
const strat = (typeof _lotStrategy === 'function') ? _lotStrategy() : 'fefo';
|
|
1740
|
-
if (strat === 'off') return
|
|
1756
|
+
if (strat === 'off') return none;
|
|
1741
1757
|
const ordered = (typeof sortLotsForConsumption === 'function') ? sortLotsForConsumption(lots, strat === 'fifo' ? 'fifo' : 'fefo')
|
|
1742
1758
|
: lots.slice().sort((a, b) => { const ax = a.expiryDate || '9999-12-31', bx = b.expiryDate || '9999-12-31';
|
|
1743
1759
|
return ax !== bx ? (ax < bx ? -1 : 1) : (a.receivedDate || '').localeCompare(b.receivedDate || ''); });
|
|
1744
|
-
|
|
1745
|
-
return (isFinite(p) && p > 0 && p < 100) ? p : null;
|
|
1760
|
+
return { purity: ok(parseFloat((ordered[0] || {}).purity)), lot: null };
|
|
1746
1761
|
}
|
|
1762
|
+
function effectivePurity(ing, pinLotId) { return _purityBasis(ing, pinLotId).purity; }
|
|
1747
1763
|
|
|
1748
|
-
// Lot-assay deviation warning.
|
|
1764
|
+
// Lot-assay deviation warning. An unpinned weigh-out is grossed up on the ingredient's
|
|
1749
1765
|
// NOMINAL purity (the design basis — see effectivePurity); a delivered lot may
|
|
1750
1766
|
// assay differently. When the lot this row will draw from (the batch's consumed
|
|
1751
1767
|
// lots, else the FIFO front lot) deviates from the nominal by ≥ PURITY_DEVIATION_WARN
|
|
@@ -1786,9 +1802,13 @@ function correctAmountForPurity(comp, amt, pins) {
|
|
|
1786
1802
|
if (!comp || !comp.ingredientId || amt == null || !isFinite(amt)) return passthrough;
|
|
1787
1803
|
const ing = (typeof db !== 'undefined' && Array.isArray(db.ingredients))
|
|
1788
1804
|
? db.ingredients.find(i => i.id === comp.ingredientId) : null;
|
|
1789
|
-
const
|
|
1805
|
+
const basis = _purityBasis(ing, pins && ing ? pins[ing.id] : null);
|
|
1806
|
+
const p = basis.purity;
|
|
1790
1807
|
if (p == null || !(p > 0) || p >= 100) return passthrough;
|
|
1791
|
-
|
|
1808
|
+
// lotBasis: the pinned lot whose assay this row weighs at (null = nominal / next-lot basis).
|
|
1809
|
+
const nom = parseFloat(ing.purity);
|
|
1810
|
+
const lotBasis = basis.lot ? { lotId: basis.lot.id, lotNumber: basis.lot.lotNumber || basis.lot.uid || '', nominal: (isFinite(nom) && nom > 0) ? nom : null } : null;
|
|
1811
|
+
return { amount: amt / (p / 100), purity: p, activeAmount: amt, lotBasis };
|
|
1792
1812
|
}
|
|
1793
1813
|
|
|
1794
1814
|
// A composition row carrying this role is the "balance / q.s." ingredient:
|
|
@@ -1848,6 +1868,7 @@ function applyQsBalance(rows, targetQty) {
|
|
|
1848
1868
|
rows[bi].amount = bal;
|
|
1849
1869
|
rows[bi].qs = true; // panel shows a q.s. tag
|
|
1850
1870
|
rows[bi].purity = null; // the balance row isn't purity-corrected
|
|
1871
|
+
rows[bi].lotBasis = null;
|
|
1851
1872
|
rows[bi].activeAmount = bal;
|
|
1852
1873
|
return out;
|
|
1853
1874
|
}
|
|
@@ -1887,8 +1908,11 @@ function _weighoutDensityLineHtml(w) {
|
|
|
1887
1908
|
}
|
|
1888
1909
|
|
|
1889
1910
|
function renderWeighoutPanel(w, actuals, formula, copyOnclick, noun) {
|
|
1890
|
-
|
|
1891
|
-
|
|
1911
|
+
// Two decimals from 10 up (53.13 kg, 46.87 g: what a balance at that scale reads); smaller amounts keep four
|
|
1912
|
+
// so a 0.0583 g trace active still shows (Jun, 25 Nov, film 10).
|
|
1913
|
+
const _woDp = n => parseFloat(n.toFixed(Math.abs(n) >= 10 ? 2 : 4)).toString();
|
|
1914
|
+
const fmt = n => (n == null || !isFinite(n)) ? '—' : _woDp(n);
|
|
1915
|
+
const sgn = n => (n == null || !isFinite(n)) ? '—' : (n > 0 ? '+' : '') + _woDp(n);
|
|
1892
1916
|
if (!w || !w.available) {
|
|
1893
1917
|
if (w && w.reason === 'bad-unit')
|
|
1894
1918
|
return `<div style="padding:8px 11px;margin-bottom:12px;background:var(--dk-amber-bg, #fffbeb);border:1px solid var(--dk-amber-line, #fde68a);border-radius:6px;color:var(--dk-amber-fg, #92400e);font-size:12px"><span class="fl-warn" aria-hidden="true"></span> Set the ${noun} quantity in a <strong>mass or volume unit</strong> (g, kg, mL, L…) to get a weigh-out sheet — currently <strong>${esc(w.unit || '—')}</strong>.</div>`;
|
|
@@ -1975,7 +1999,7 @@ function renderWeighoutPanel(w, actuals, formula, copyOnclick, noun) {
|
|
|
1975
1999
|
if (a) { actInUnit = toUnit(a.amount, a.unit, r.key); if (actInUnit != null) actualTotal += actInUnit; }
|
|
1976
2000
|
const delta = (hasActuals && planned != null && actInUnit != null) ? (actInUnit - planned) : null;
|
|
1977
2001
|
const rel = (delta != null && planned > 0) ? Math.abs(delta) / planned : (delta != null && actInUnit > 0 ? 1 : null);
|
|
1978
|
-
return { key: r.key, name: r.name, planned, actInUnit, actRaw: a, delta, rel, purity: r.purity, activeAmount: r.activeAmount, qs: r.qs, lotDev: r.lotDev || null };
|
|
2002
|
+
return { key: r.key, name: r.name, planned, actInUnit, actRaw: a, delta, rel, purity: r.purity, activeAmount: r.activeAmount, qs: r.qs, lotDev: r.lotDev || null, lotBasis: r.lotBasis || null };
|
|
1979
2003
|
});
|
|
1980
2004
|
// Union in ingredients that were ADDED to the As-prepared table but aren't in
|
|
1981
2005
|
// the recipe (a spike / colorant / q.s. carrier). Without this the weigh-out
|
|
@@ -1994,9 +2018,10 @@ function renderWeighoutPanel(w, actuals, formula, copyOnclick, noun) {
|
|
|
1994
2018
|
rows.push({ key, name, planned: null, actInUnit, actRaw: a, delta: actInUnit, rel: (actInUnit > 0 ? 1 : null), purity: null, activeAmount: null, qs: false, _added: true });
|
|
1995
2019
|
});
|
|
1996
2020
|
}
|
|
1997
|
-
const _rNumFmt = v => (
|
|
1998
|
-
const _purityTagBase = r => (r.purity == null) ? '' :
|
|
1999
|
-
` <span style="font-size:9.5px;color:var(--dk-violet-fg, #6d28d9);font-weight:600;background:var(--dk-violet-bg, #f5f3ff);border:1px solid var(--dk-violet-line, #ddd6fe);border-radius:4px;padding:0 3px;vertical-align:middle;white-space:nowrap" title="
|
|
2021
|
+
const _rNumFmt = v => cv(v); // the badge's corrected amount reads like the row: same unit, same decimals
|
|
2022
|
+
const _purityTagBase = r => (r.purity == null) ? '' : r.lotBasis
|
|
2023
|
+
? ` <span style="font-size:9.5px;color:var(--dk-violet-fg, #6d28d9);font-weight:600;background:var(--dk-violet-bg, #f5f3ff);border:1px solid var(--dk-violet-line, #ddd6fe);border-radius:4px;padding:0 3px;vertical-align:middle;white-space:nowrap" title="Weighed at the assay of pinned lot ${esc(String(r.lotBasis.lotNumber))}, ${esc(String(+r.purity))}%${r.lotBasis.nominal != null ? ` (nominal ${esc(String(+r.lotBasis.nominal))}%)` : ''}. Delivers ${cv(r.activeAmount)} ${esc(displayUnit)} of active">↑ at lot <span translate="no">${esc(String(r.lotBasis.lotNumber))}</span> ${esc(String(+r.purity))}%</span>`
|
|
2024
|
+
: ` <span style="font-size:9.5px;color:var(--dk-violet-fg, #6d28d9);font-weight:600;background:var(--dk-violet-bg, #f5f3ff);border:1px solid var(--dk-violet-line, #ddd6fe);border-radius:4px;padding:0 3px;vertical-align:middle;white-space:nowrap" title="Grossed up for ${esc(String(+r.purity))}% purity, delivers ${cv(r.activeAmount)} ${esc(displayUnit)} of active">↑${esc(String(+r.purity))}%</span>`;
|
|
2000
2025
|
// Lot-assay deviation: the lot this row draws from assays away from the nominal.
|
|
2001
2026
|
const purityTag = r => _purityTagBase(r) + (!r.lotDev ? '' :
|
|
2002
2027
|
` <span style="font-size:9.5px;color:var(--dk-amber-fg, #b45309);font-weight:600;background:var(--dk-amber-bg, #fffbeb);border:1px solid var(--dk-amber-line, #fde68a);border-radius:4px;padding:0 3px;vertical-align:middle;white-space:nowrap" title="Lot ${esc(String(r.lotDev.lotNumber))} assays ${esc(String(+r.lotDev.lotPurity))}% but the weigh-out is grossed up on the nominal ${esc(String(+r.lotDev.nominal))}%. ${r.lotDev.consumed ? 'This batch drew from that lot.' : 'FIFO will draw from that lot next.'} To deliver the spec active at the lot's assay, weigh ${r.lotDev.correctedAmount != null ? esc(_rNumFmt(r.lotDev.correctedAmount)) + ' ' + esc(String(displayUnit || w.unit || '')) : 'the corrected amount'} instead.">⚠ lot ${esc(String(+r.lotDev.lotPurity))}% vs ${esc(String(+r.lotDev.nominal))}%${r.lotDev.correctedAmount != null ? ' → ' + esc(_rNumFmt(r.lotDev.correctedAmount)) : ''}</span>`);
|
|
@@ -2075,9 +2100,13 @@ function renderWeighoutPanel(w, actuals, formula, copyOnclick, noun) {
|
|
|
2075
2100
|
${th('Unit', 'text-align:left')}
|
|
2076
2101
|
${_altAny ? `<th style="padding:5px 8px;color:var(--dk-text-3, #475569);font-weight:400;text-align:right" title="Approx. ${esc(_altDim || '')} equivalent, derived per-ingredient from its own density. Reference only — not additive, so no total.">≈ ${esc(altUnit)}</th>` : ''}
|
|
2077
2102
|
</tr>`;
|
|
2103
|
+
// The gross-up's arithmetic under the ingredient name, so the sheet shows why a row weighs more than the recipe
|
|
2104
|
+
// (Jun, 26 Nov, film 10: "the reasoning behind 106.27"). Basis = the pinned lot's assay, else the nominal.
|
|
2105
|
+
const purityWhy = r => (r.purity == null || r._added || r.planned == null || r.activeAmount == null || !isFinite(r.activeAmount)) ? ''
|
|
2106
|
+
: `<div class="fl-wo-why" style="font-size:11px;color:var(--dk-muted, #64748b);margin-top:1px;font-variant-numeric:tabular-nums">${cv(r.activeAmount)} ${esc(displayUnit)} active ÷ ${esc(String(+r.purity))}% ${r.lotBasis ? `(lot <span translate="no">${esc(String(r.lotBasis.lotNumber))}</span> assay)` : '(nominal)'} = <strong style="color:var(--dk-text-2, #334155)">${cv(r.planned)} ${esc(displayUnit)}</strong></div>`;
|
|
2078
2107
|
const body = rows.map((r, i) => `<tr data-wo-key="${esc(r.key)}" style="${hasActuals ? dRowBg(r.rel) : ''}">
|
|
2079
2108
|
<td style="padding:4px 8px;color:var(--dk-faint, #94a3b8)">${i + 1}</td>
|
|
2080
|
-
<td style="padding:4px 8px">${esc(r.name)}${r._added ? ` <span style="font-size:9.5px;color:var(--dk-red-fg, #b91c1c);font-weight:600;background:var(--dk-red-bg, #fef2f2);border:1px solid var(--dk-red-line, #fecaca);border-radius:4px;padding:0 4px;vertical-align:middle;white-space:nowrap" title="Added to the as-prepared batch — not part of the linked recipe">+ not in recipe</span>` : ''}</td>
|
|
2109
|
+
<td style="padding:4px 8px">${esc(r.name)}${purityWhy(r)}${r._added ? ` <span style="font-size:9.5px;color:var(--dk-red-fg, #b91c1c);font-weight:600;background:var(--dk-red-bg, #fef2f2);border:1px solid var(--dk-red-line, #fecaca);border-radius:4px;padding:0 4px;vertical-align:middle;white-space:nowrap" title="Added to the as-prepared batch — not part of the linked recipe">+ not in recipe</span>` : ''}</td>
|
|
2081
2110
|
<td style="padding:4px 8px;text-align:right;font-variant-numeric:tabular-nums;font-weight:600;color:var(--dk-text, #0f172a)">${r.planned != null ? `${cv(r.planned)}${purityTag(r)}${qsTag(r)}` : '<span style="color:var(--dk-dim, #cbd5e1)">—</span>'}</td>
|
|
2082
2111
|
${hasActuals ? `<td style="padding:4px 8px;text-align:right;font-variant-numeric:tabular-nums">${
|
|
2083
2112
|
r.actInUnit != null ? cv(r.actInUnit)
|
package/vendor/fragrance.js
CHANGED
|
@@ -39,6 +39,8 @@ const _frgIsUse = (v) => typeof v === 'string' && Object.prototype.hasOwnPropert
|
|
|
39
39
|
// (EU) 2023/1545. [Annex III reference number, the name to print on the label, CAS numbers, other names].
|
|
40
40
|
// Entries 45 to 324 (the 17 replaced) and 327 to 371 (the 45 added) are from the 2023 regulation's Annex; the 19
|
|
41
41
|
// others are the entries of 67 to 92 it left as they were. Entries 79 and 83 (HICC, BMHCA) are gone: both are banned.
|
|
42
|
+
// Checked 23 Nov 2026 against the consolidated text of 24.04.2024 on EUR-Lex (CELEX 02009R1223-20240424): all 81
|
|
43
|
+
// reference numbers present, and every CAS number the same in both directions, the 19 older entries included.
|
|
42
44
|
const FL_FR_ALLERGENS = [
|
|
43
45
|
[45, 'Benzyl Alcohol', ['100-51-6']],
|
|
44
46
|
[46, '6-Methyl Coumarin', ['92-48-8'], ['6-Methylcoumarin']],
|
|
@@ -348,6 +350,24 @@ function flFrCompute(f, opts) {
|
|
|
348
350
|
}));
|
|
349
351
|
out.max.push({ id: o.id, name: o.name, uid: o.uid, current: share, max: lo ? Math.min(100, lo.max) : 100, capped: !lo || lo.max >= 100, limitedBy: lo && lo.max < 100 ? lo.name : '', partial });
|
|
350
352
|
});
|
|
353
|
+
// A fragrance held as a plain ingredient (a bought compound, dosed as it is; the film session's review, 23 Nov):
|
|
354
|
+
// its own limit, less what the same material brings in through an oil. Fragrance materials only, not a substance
|
|
355
|
+
// counted by its CAS alone; the five with the least room, so a long list of aroma chemicals stays a table.
|
|
356
|
+
if (!wk.rootOil) {
|
|
357
|
+
const own = [];
|
|
358
|
+
out.rows.forEach(r => {
|
|
359
|
+
const m = mats.get(r.id);
|
|
360
|
+
if (!r.limit || !m || !flFrIsMaterial(m.ing)) return;
|
|
361
|
+
let via = 0; r.byOil.forEach(w => { via += w * 100 * k; });
|
|
362
|
+
const direct = r.pct - via;
|
|
363
|
+
if (!(direct > 1e-9)) return;
|
|
364
|
+
const free = r.limit.kind === 'unrestricted';
|
|
365
|
+
const max = free ? 100 : r.limit.kind === 'prohibited' ? 0 : Math.min(100, Math.max(0, r.limit.maxPct - via));
|
|
366
|
+
own.push({ id: null, ingredientId: r.id, name: r.name, uid: r.uid, current: direct, max, capped: free || max >= 100, limitedBy: '', own: true, partial: false });
|
|
367
|
+
});
|
|
368
|
+
own.sort((x, y) => (x.max - x.current) - (y.max - y.current) || x.name.localeCompare(y.name));
|
|
369
|
+
out.max.push(...own.slice(0, 5));
|
|
370
|
+
}
|
|
351
371
|
}
|
|
352
372
|
|
|
353
373
|
const n = (a, one, many) => a.length + ' ' + (a.length === 1 ? one : many);
|
|
@@ -444,7 +464,10 @@ function flFrSummary(f, opts) {
|
|
|
444
464
|
state,
|
|
445
465
|
heading: state === 'conforms' ? 'IFRA conformity statement' : state === 'over' ? 'IFRA check: does not conform' : 'IFRA check: incomplete',
|
|
446
466
|
statement: state === 'conforms' ? `${name} conforms to the IFRA limits on file for ${where}${at}.`
|
|
447
|
-
|
|
467
|
+
// What is unknown is said with what is over (Jun, 23 Nov: "list the ones with no limit in report"): fixing the
|
|
468
|
+
// material over its limit would not make the formula conform while another has no limit on file.
|
|
469
|
+
: state === 'over' ? `${name} does not conform in ${where}${at}: ${c.over.join(', ')} ${c.over.length === 1 ? 'is' : 'are'} over the limit.${
|
|
470
|
+
c.why.filter(w => !/over the limit\.$/.test(w)).map(w => ' ' + w).join('')}`
|
|
448
471
|
: `No conformity statement can be made for ${name}${where ? ' in ' + where + at : ''}. ${c.why.join(' ')}`,
|
|
449
472
|
basis: FL_FR_BASIS,
|
|
450
473
|
category: c.category, categoryWords: FL_FR_CAT_WORDS[c.category] || '', use: c.use, dosage: c.dosage, asSold: !c.rootOil || c.dosage === 100,
|
|
@@ -467,11 +490,14 @@ function _frgStatementBlocks(f, table) {
|
|
|
467
490
|
const s = flFrSummary(f);
|
|
468
491
|
if (!s) return null;
|
|
469
492
|
const e = _frgEsc, p = (v) => _frgPct(v) + '%';
|
|
470
|
-
const
|
|
471
|
-
|
|
493
|
+
const by = (m, pre) => m.limitedBy ? pre + e(m.limitedBy) : ''; // a plain fragrance ingredient is limited by its own limit: nothing to name
|
|
494
|
+
const max = s.maxDosage.map(m => m.maxPct <= 0 ? `${e(m.of)}: no dosage passes${m.limitedBy ? ' (limited by ' + e(m.limitedBy) + ')' : ''}.`
|
|
495
|
+
: m.anyDosage ? `${e(m.of)}: passes at any dosage.` : `${e(m.of)}: passes up to ${p(m.maxPct)}${by(m, ', limited by ')}.`).join(' ');
|
|
472
496
|
const ifra = `<p class="fr-st fr-st-${s.state}"><strong>${e(s.statement)}</strong></p>
|
|
473
497
|
<p class="muted">${e(s.basis)}${s.amendments.length ? ' IFRA amendment cited: ' + e(s.amendments.join(', ')) + '.' : ''}${s.use ? ' Product use: ' + e(FL_FR_USES[s.use].toLowerCase()) + '.' : ''}</p>
|
|
474
498
|
${max ? `<p class="muted">Highest dosage${s.maxDosage.some(m => m.partial) ? ' (among the materials with a limit on file)' : ''}: ${max}</p>` : ''}
|
|
499
|
+
${s.unknown.noLimit.length ? `<p class="fr-st fr-st-incomplete"><strong>Not confirmed:</strong> no limit on file for category ${e(s.category)} for ${e(s.unknown.noLimit.join(', '))}.</p>` : ''}
|
|
500
|
+
${s.unknown.noSourceDocument.length ? `<p class="fr-st fr-st-incomplete"><strong>No source document:</strong> ${e(s.unknown.noSourceDocument.join(', '))}.</p>` : ''}
|
|
475
501
|
${table([{ t: 'Material', i: 'name' }, { t: 'In product', i: 'pct', num: true }, { t: 'Limit', i: 'limit', num: true }, { t: 'Status', i: 'status' }, { t: 'Amendment', i: 'amendment' }, { t: 'Source document', i: 'document' }],
|
|
476
502
|
s.materials.map(m => ({ name: m.name, pct: p(m.pctInProduct), limit: m.limit, status: m.status, amendment: m.amendment || '—', document: m.document || 'None on file' })))}
|
|
477
503
|
${s.unknown.notChecked.length ? `<p class="muted">Not fragrance materials, not checked: ${e(s.unknown.notChecked.join(', '))}.</p>` : ''}`;
|
|
@@ -589,7 +615,10 @@ function _frgMaxHtml(c) {
|
|
|
589
615
|
const part = m.partial ? ' <span class="fr-dim">Among the materials with a limit on file.</span>' : '';
|
|
590
616
|
const who = c.rootOil ? '' : `<span class="fr-max-who" translate="no">${_frgEsc(m.name)}</span> `;
|
|
591
617
|
const now = c.rootOil ? '' : ` Now ${_frgPct(m.current)}%.`;
|
|
592
|
-
const body = m.max <= 0 ? `${who}<strong>No dosage passes</strong> in category ${_frgEsc(c.category)}
|
|
618
|
+
const body = m.own ? (m.max <= 0 ? `${who}<strong>No dosage passes</strong> in category ${_frgEsc(c.category)}.${now}`
|
|
619
|
+
: m.capped ? `${who}<strong>Passes at any dosage</strong> in category ${_frgEsc(c.category)}.${now}`
|
|
620
|
+
: `${who}Passes in category ${_frgEsc(c.category)} up to <strong class="fl-val">${_frgPct(m.max)}%</strong>, its limit on file.${now}`)
|
|
621
|
+
: m.max <= 0 ? `${who}<strong>No dosage passes</strong> in category ${_frgEsc(c.category)}. Limited by ${_frgEsc(m.limitedBy)}.`
|
|
593
622
|
: m.capped ? `${who}<strong>Passes at any dosage</strong> in category ${_frgEsc(c.category)}.${now}`
|
|
594
623
|
: `${who}Passes in category ${_frgEsc(c.category)} up to <strong class="fl-val">${_frgPct(m.max)}%</strong>. Limited by ${_frgEsc(m.limitedBy)}.${now}`;
|
|
595
624
|
return `<div class="fr-max ${m.max + 1e-9 < m.current ? 'bad' : ''}">${body}${part}</div>`;
|
|
@@ -601,24 +630,72 @@ function _frgSourceHtml(r) {
|
|
|
601
630
|
if (!r.cert) return `${am ? am + ' · ' : ''}<span class="fr-warn">no certificate</span>`;
|
|
602
631
|
return `${am ? am + ' · ' : ''}<a class="fr-doc" onclick="downloadIngredientDoc('${escJsAttr(r.id)}','${escJsAttr(r.cert.id)}',true)">${_frgEsc(r.cert.name)}</a>`;
|
|
603
632
|
}
|
|
633
|
+
// Both tables sort by a header click (Shift+click for a second key) and take column widths, like the app's other
|
|
634
|
+
// tables (Jun, 23 Nov). Never sorted: the tab's own order, what needs attention first. Views 'frIfra', 'frAllergens'.
|
|
635
|
+
const _FRG_STATUS_ORDER = { prohibited: 0, over: 1, unknown: 2, pass: 3, unrestricted: 4, nocat: 5 };
|
|
636
|
+
const _frgLimitSort = (r) => !r.limit ? -1 : r.limit.kind === 'prohibited' ? 0 : r.limit.kind === 'unrestricted' ? Infinity : r.limit.maxPct;
|
|
637
|
+
function _frgIfraSortVal(r, col) {
|
|
638
|
+
switch (col) {
|
|
639
|
+
case 'name': return r.name;
|
|
640
|
+
case 'pct': return r.pct;
|
|
641
|
+
case 'limit': return _frgLimitSort(r);
|
|
642
|
+
case 'headroom': return r.headroom == null ? Infinity : r.headroom;
|
|
643
|
+
case 'status': return _FRG_STATUS_ORDER[r.status] != null ? _FRG_STATUS_ORDER[r.status] : 9;
|
|
644
|
+
case 'source': return (r.amendment || '') + ' ' + ((r.cert && r.cert.name) || '');
|
|
645
|
+
default: return '';
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function _frgAllergenSortVal(a, col) {
|
|
649
|
+
switch (col) {
|
|
650
|
+
case 'name': return a.name;
|
|
651
|
+
case 'cas': return a.cas || '';
|
|
652
|
+
case 'pct': return a.pct;
|
|
653
|
+
case 'label': return !a._listed ? 3 : a.label == null ? 2 : a.label ? 0 : 1;
|
|
654
|
+
case 'from': return (a.sources.slice().sort((x, y) => y.pct - x.pct)[0] || {}).name || '';
|
|
655
|
+
default: return '';
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
const _frgSorted = (list, view, acc) => (typeof sortData === 'function' ? sortData(list, view, acc) : list);
|
|
659
|
+
// A header through the app's sort helper; a right-aligned one for numbers.
|
|
660
|
+
const _frgTh = (view, col, label, num) => typeof thSort === 'function'
|
|
661
|
+
? thSort(view, col, label, num ? 'text-align:right' : '').replace('<th ', num ? '<th class="num" ' : '<th ')
|
|
662
|
+
: `<th data-col="${col}"${num ? ' class="num"' : ''}>${label}</th>`;
|
|
663
|
+
// After the tab is drawn: the resize handles and each column's saved width.
|
|
664
|
+
function _frgTablesWire() {
|
|
665
|
+
['frIfra', 'frAllergens'].forEach(v => {
|
|
666
|
+
const t = document.getElementById('fr-table-' + v);
|
|
667
|
+
if (t && typeof enableColResize === 'function') try { enableColResize(t, v); } catch (_) {}
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
// A header click redraws the tab (sorting.js asks this map).
|
|
671
|
+
function _frgRedrawTables() {
|
|
672
|
+
const el = document.getElementById('tab-fragrance'), f = el && _frgFormula(el.dataset.fid);
|
|
673
|
+
if (!f) return;
|
|
674
|
+
el.innerHTML = flFrTabHtml(f);
|
|
675
|
+
_frgTablesWire();
|
|
676
|
+
}
|
|
677
|
+
if (typeof _SORT_RENDER_MAP !== 'undefined') { _SORT_RENDER_MAP.frIfra = _frgRedrawTables; _SORT_RENDER_MAP.frAllergens = _frgRedrawTables; }
|
|
604
678
|
function _frgIfraTableHtml(c) {
|
|
605
|
-
const body = c.rows.map(r => {
|
|
679
|
+
const body = _frgSorted(c.rows, 'frIfra', _frgIfraSortVal).map(r => {
|
|
606
680
|
const [cls, word] = _FRG_STATUS[r.status];
|
|
607
681
|
const lim = !r.limit ? '—' : r.limit.kind === 'unrestricted' ? 'None' : r.limit.kind === 'prohibited' ? '0' : _frgPct(r.limit.maxPct) + '%';
|
|
608
|
-
return `<tr><td><a class="fr-name" translate="no" onclick="navigate('ingredient-detail','${escJsAttr(r.id)}')">${_frgEsc(r.name)}</a></td>
|
|
609
|
-
<td class="num">${_frgPct(r.pct)}%</td><td class="num">${lim}</td>
|
|
610
|
-
<td class="num">${r.headroom == null ? '' : (r.headroom < 0 ? '−' : '') + _frgPct(Math.abs(r.headroom)) + '%'}</td>
|
|
611
|
-
<td>${word ? `<span class="badge badge-${cls}">${word}</span>` : ''}</td><td class="fr-src fr-nw">${_frgSourceHtml(r)}</td></tr>`;
|
|
682
|
+
return `<tr><td data-col="name"><a class="fr-name" translate="no" onclick="navigate('ingredient-detail','${escJsAttr(r.id)}')">${_frgEsc(r.name)}</a></td>
|
|
683
|
+
<td data-col="pct" class="num">${_frgPct(r.pct)}%</td><td data-col="limit" class="num">${lim}</td>
|
|
684
|
+
<td data-col="headroom" class="num">${r.headroom == null ? '' : (r.headroom < 0 ? '−' : '') + _frgPct(Math.abs(r.headroom)) + '%'}</td>
|
|
685
|
+
<td data-col="status">${word ? `<span class="badge badge-${cls}">${word}</span>` : ''}</td><td data-col="source" class="fr-src fr-nw">${_frgSourceHtml(r)}</td></tr>`;
|
|
612
686
|
}).join('');
|
|
613
|
-
|
|
687
|
+
const v = 'frIfra';
|
|
688
|
+
return `<div class="table-wrapper"><table class="fr-table fl-band" id="fr-table-${v}"><thead><tr>${_frgTh(v, 'name', 'Material')}${_frgTh(v, 'pct', 'In product', true)}${_frgTh(v, 'limit', 'Limit', true)}${_frgTh(v, 'headroom', 'Headroom', true)}${_frgTh(v, 'status', 'Status')}${_frgTh(v, 'source', 'Source')}</tr></thead><tbody>${body}</tbody></table></div>`;
|
|
614
689
|
}
|
|
615
690
|
function _frgAllergenTableHtml(c) {
|
|
616
691
|
if (!c.allergens.length && !c.unlisted.length) return `<div class="fr-dim">${c.noDecl.length ? 'No allergens on the declarations on file.' : 'No regulated allergens declared.'}</div>`;
|
|
617
692
|
const src = (a) => a.sources.slice().sort((x, y) => y.pct - x.pct).map(s => `${_frgEsc(s.name)} ${_frgPct(s.pct)}%`).join(', ');
|
|
618
|
-
const row = (a
|
|
619
|
-
<td>${!listed ? '<span class="badge badge-gray">Not on the EU list</span>' : a.label == null ? '' : a.label ? '<span class="badge badge-amber">Label</span>' : '<span class="badge badge-gray">Below</span>'}</td><td class="fr-src">${src(a)}</td></tr>`;
|
|
620
|
-
|
|
621
|
-
|
|
693
|
+
const row = (a) => { const listed = a._listed; return `<tr><td data-col="name" translate="no">${listed ? `<a class="fr-name" onclick="flFrFindSources('${escJsAttr(a.name)}')">${_frgEsc(a.name)}</a>` : _frgEsc(a.name)}</td><td data-col="cas" class="fr-cas" translate="no">${_frgEsc(a.cas)}</td><td data-col="pct" class="num">${_frgPct(a.pct)}%</td>
|
|
694
|
+
<td data-col="label">${!listed ? '<span class="badge badge-gray">Not on the EU list</span>' : a.label == null ? '' : a.label ? '<span class="badge badge-amber">Label</span>' : '<span class="badge badge-gray">Below</span>'}</td><td data-col="from" class="fr-src">${src(a)}</td></tr>`; };
|
|
695
|
+
const all = c.allergens.map(a => ({ ...a, _listed: true })).concat(c.unlisted.map(a => ({ ...a, _listed: false, sources: a.sources || [] })));
|
|
696
|
+
const v = 'frAllergens';
|
|
697
|
+
return `<div class="table-wrapper"><table class="fr-table fl-band" id="fr-table-${v}"><thead><tr>${_frgTh(v, 'name', 'Allergen')}${_frgTh(v, 'cas', 'CAS')}${_frgTh(v, 'pct', 'In product', true)}${_frgTh(v, 'label', c.use ? _frgEsc(FL_FR_USES[c.use]) : 'Label')}${_frgTh(v, 'from', 'From')}</tr></thead>
|
|
698
|
+
<tbody>${_frgSorted(all, v, _frgAllergenSortVal).map(row).join('')}</tbody></table></div>`;
|
|
622
699
|
}
|
|
623
700
|
function _frgUnknownsHtml(c) {
|
|
624
701
|
const list = (a) => `<span translate="no">${_frgEsc(a.slice(0, 12).join(', '))}${a.length > 12 ? ` and ${a.length - 12} more` : ''}</span>`;
|
|
@@ -639,7 +716,7 @@ function _frgControlsHtml(f, c) {
|
|
|
639
716
|
<label>IFRA category<select id="fr-cat-in" onchange="flFrSet('${id}','category',this.value)"><option value="">Choose…</option>${FL_FR_CATEGORIES.map(k => `<option value="${k}"${c.category === k ? ' selected' : ''}>${_frgEsc(_frgCatText(k))}</option>`).join('')}</select></label>
|
|
640
717
|
<label>Product use<span class="nl-unit"><span class="fl-seg-group sm" role="group" aria-label="Product use">${seg('leave-on')}${seg('rinse-off')}</span></span></label>
|
|
641
718
|
${c.rootOil ? `<label data-tip="How much of this oil goes into the finished product. 100 checks it as sold.">Dosage in the product<span class="nl-unit"><input id="fr-dose-in" type="number" min="0" max="100" step="any" inputmode="decimal" value="${st.dosage !== 100 ? _frgEsc(String(st.dosage)) : ''}" placeholder="100" onchange="flFrSet('${id}','dosage',this.value)"><em>%</em></span></label>` : ''}
|
|
642
|
-
${c.others.length ? `<div class="fr-dim" data-tip="${_frgEsc(c.others.slice(0, 12).join(', ') + (c.others.length > 12 ? ` +${c.others.length - 12} more` : ''))}">${c.others.length} other ${c.others.length === 1 ? 'ingredient is' : 'ingredients are
|
|
719
|
+
${c.others.length ? `<div class="fr-dim" data-tip="${_frgEsc(c.others.slice(0, 12).join(', ') + (c.others.length > 12 ? ` +${c.others.length - 12} more` : ''))}">${c.others.length} other ${c.others.length === 1 ? 'ingredient is not a fragrance material' : 'ingredients are not fragrance materials'}. Not checked.</div>` : ''}
|
|
643
720
|
</div></div>`;
|
|
644
721
|
}
|
|
645
722
|
function flFrTabHtml(f) {
|
|
@@ -669,6 +746,7 @@ function flFrRepaint() {
|
|
|
669
746
|
const el = document.getElementById('tab-fragrance'), f = el && _frgFormula(el.dataset.fid);
|
|
670
747
|
if (!f || !el || el.contains(document.activeElement)) return;
|
|
671
748
|
el.innerHTML = flFrTabHtml(f);
|
|
749
|
+
_frgTablesWire();
|
|
672
750
|
}
|
|
673
751
|
// Save the category, the use or the dosage on the formula, then redraw the tab.
|
|
674
752
|
function flFrSet(fid, key, value) {
|
|
@@ -683,7 +761,7 @@ function flFrSet(fid, key, value) {
|
|
|
683
761
|
}
|
|
684
762
|
const saved = typeof _fmlSyncSave === 'function' && _fmlSyncSave(f, [key === 'category' ? 'ifraCategory' : key === 'use' ? 'productUse' : 'ifraDosagePct']);
|
|
685
763
|
const el = typeof document !== 'undefined' ? document.getElementById('tab-fragrance') : null;
|
|
686
|
-
if (el) el.innerHTML = flFrTabHtml(f);
|
|
764
|
+
if (el) { el.innerHTML = flFrTabHtml(f); _frgTablesWire(); }
|
|
687
765
|
const ov = typeof document !== 'undefined' ? document.getElementById('fr-overview') : null;
|
|
688
766
|
if (ov) ov.outerHTML = flFrOverviewHtml(f);
|
|
689
767
|
const tick = typeof document !== 'undefined' ? document.getElementById('fr-saved') : null;
|
|
@@ -824,9 +902,16 @@ function _frgPasteRead(which) {
|
|
|
824
902
|
_frgFormCheck();
|
|
825
903
|
if (typeof toast === 'function') toast(`${res.rows.length} ${res.rows.length === 1 ? 'row' : 'rows'} read${res.skipped ? `, ${res.skipped} skipped` : ''}. Check them against the document.`);
|
|
826
904
|
}
|
|
905
|
+
// The ingredient's documents, the Fragrance Compliance ones first (Documents › Fragrance Compliance, 23 Nov); the rest
|
|
906
|
+
// stay pickable under their own heading, since older certificates were filed under Other.
|
|
827
907
|
function _frgDocSelectHtml(id, ing, picked, none) {
|
|
828
908
|
const docs = (ing && Array.isArray(ing.documents) ? ing.documents : []).filter(d => d && !d.deleted);
|
|
829
|
-
|
|
909
|
+
const opt = d => `<option value="${_frgEsc(d.id)}"${d.id === picked ? ' selected' : ''}>${_frgEsc(d.filename || d.name || d.id)}</option>`;
|
|
910
|
+
const frag = docs.filter(d => d.docType === 'FRAG'), rest = docs.filter(d => d.docType !== 'FRAG');
|
|
911
|
+
const body = frag.length && rest.length
|
|
912
|
+
? `<optgroup label="Fragrance compliance">${frag.map(opt).join('')}</optgroup><optgroup label="Other documents">${rest.map(opt).join('')}</optgroup>`
|
|
913
|
+
: frag.concat(rest).map(opt).join('');
|
|
914
|
+
return `<select id="${id}"${docs.length ? '' : ' disabled'}><option value="">${docs.length ? none : 'No documents yet'}</option>${body}</select>`;
|
|
830
915
|
}
|
|
831
916
|
// The two blocks inside the ingredient form's Fragrance Details panel.
|
|
832
917
|
function flFrIngFormHtml(ing) {
|
|
@@ -871,7 +956,7 @@ function flFrIngFormHtml(ing) {
|
|
|
871
956
|
${flFoldHtml('f-fr-fold-limits', 'IFRA limits', _frgEsc(limHint), false, limitsBody)}
|
|
872
957
|
${flFoldHtml('f-fr-fold-allergens', 'Fragrance allergens', _frgEsc(alHint), false, allergensBody)}
|
|
873
958
|
<datalist id="f-fr-al-list">${FL_FR_ALLERGENS.map(a => `<option value="${_frgEsc(a.name)}"></option>`).join('')}</datalist>
|
|
874
|
-
${hasDocs ? '' : '<div class="fr-dim">Attach the certificate and the declaration on the Documents tab, then choose them here.</div>'}
|
|
959
|
+
${hasDocs ? '' : '<div class="fr-dim">Attach the certificate and the declaration on the Documents tab, under Fragrance Compliance, then choose them here.</div>'}
|
|
875
960
|
</div>`;
|
|
876
961
|
}
|
|
877
962
|
// The folded line of each block: what is inside, and what is missing.
|
|
@@ -851,7 +851,7 @@ function _nlGate() {
|
|
|
851
851
|
}
|
|
852
852
|
function flNlCopyStatement(fid) {
|
|
853
853
|
if (!_nlGate()) return;
|
|
854
|
-
if (typeof flExportAllowed === 'function' && !flExportAllowed('single', 'an ingredient statement')) return; // what members can take out (0114)
|
|
854
|
+
if (typeof flExportAllowed === 'function' && !flExportAllowed('single', 'an ingredient statement', { records: (db.formulations || []).filter(x => x.id === fid), format: 'text' })) return; // what members can take out (0114); EX1
|
|
855
855
|
const f = (db.formulations || []).find(x => x.id === fid);
|
|
856
856
|
if (!f) return;
|
|
857
857
|
const text = _nlStatementText(f);
|
|
@@ -860,7 +860,7 @@ function flNlCopyStatement(fid) {
|
|
|
860
860
|
}
|
|
861
861
|
function flNlSavePng(fid) {
|
|
862
862
|
if (!_nlGate()) return;
|
|
863
|
-
if (typeof flExportAllowed === 'function' && !flExportAllowed('image', 'a nutrition label image')) return; // what members can take out (0114)
|
|
863
|
+
if (typeof flExportAllowed === 'function' && !flExportAllowed('image', 'a nutrition label image', { records: (db.formulations || []).filter(x => x.id === fid), format: 'PNG' })) return; // what members can take out (0114); EX1
|
|
864
864
|
const f = (db.formulations || []).find(x => x.id === fid);
|
|
865
865
|
const el = document.getElementById('nl-panel');
|
|
866
866
|
if (!f || !el) return;
|
|
@@ -929,7 +929,7 @@ const FL_NL_PANEL_CSS = `.nl-panel{box-sizing:border-box;width:280px;padding:4px
|
|
|
929
929
|
.nl-eu tr:last-child td{border-bottom:0}.nl-ri th:first-child{width:37%}.nl-eu th.nl-e-ri{width:13%}.nl-eu.nl-ri td{white-space:normal}.nl-eu.nl-ri .nl-e-in td:first-child{padding-left:12px}.nl-eu .nl-e-note td{text-align:left;font-size:9.5px;white-space:normal}.nl-eu .nl-e-note td + td{border-left:0}.nl-eu .nl-e-in td:first-child{padding-left:16px}`;
|
|
930
930
|
function flNlPrint(fid) {
|
|
931
931
|
if (!_nlGate()) return;
|
|
932
|
-
if (typeof flExportAllowed === 'function' && !flExportAllowed('single', 'a nutrition label print')) return; // what members can take out (0114)
|
|
932
|
+
if (typeof flExportAllowed === 'function' && !flExportAllowed('single', 'a nutrition label print', { records: (db.formulations || []).filter(x => x.id === fid), format: 'print' })) return; // what members can take out (0114); EX1
|
|
933
933
|
const f = (db.formulations || []).find(x => x.id === fid);
|
|
934
934
|
if (!f) return;
|
|
935
935
|
const s = flNlStatement(f);
|