@dhyasama/totem-models 11.142.0 → 11.144.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/lib/Financials.js CHANGED
@@ -112,7 +112,8 @@ module.exports = function(mongoose, config) {
112
112
  scenario: { type: String, enum: ['actual', 'budget', 'forecast'] },
113
113
  value: { type: Number },
114
114
  breakdown: { type: Schema.Types.Mixed },
115
- source: {
115
+ calculation: { type: String, trim: true },
116
+ sources: [{
116
117
  _id: false,
117
118
  model: {
118
119
  type: String,
@@ -120,11 +121,11 @@ module.exports = function(mongoose, config) {
120
121
  },
121
122
  ref: {
122
123
  type: Schema.Types.ObjectId,
123
- refPath: 'metrics.source.model',
124
+ refPath: 'metrics.sources.model',
124
125
  },
125
- position: {
126
- _id: false,
127
- page: { type: Number },
126
+ position: {
127
+ _id: false,
128
+ page: { type: Number },
128
129
  bbox: {
129
130
  _id: false,
130
131
  top: { type: Number },
@@ -132,29 +133,17 @@ module.exports = function(mongoose, config) {
132
133
  width: { type: Number },
133
134
  height: { type: Number }
134
135
  },
135
- row: { type: Number },
136
- col: { type: Number },
137
- sheet: { type: String }
138
- },
139
- calculation: {
140
- _id: false,
141
- description: { type: String, trim: true },
142
- positions: [{
143
- _id: false,
144
- page: { type: Number },
145
- bbox: {
146
- _id: false,
147
- top: { type: Number },
148
- left: { type: Number },
149
- width: { type: Number },
150
- height: { type: Number }
151
- },
136
+ sheet: { type: String },
137
+ header: {
152
138
  row: { type: Number },
153
- col: { type: Number },
154
- sheet: { type: String }
155
- }]
139
+ column: { type: Number }
140
+ },
141
+ cell: {
142
+ row: { type: Number },
143
+ column: { type: Number }
144
+ }
156
145
  }
157
- },
146
+ }],
158
147
  verified: { type: Boolean, default: false },
159
148
  history: [{
160
149
  _id: false,
@@ -166,19 +155,32 @@ module.exports = function(mongoose, config) {
166
155
  _id: false,
167
156
  value: { type: Number },
168
157
  breakdown: { type: Schema.Types.Mixed },
169
- source: {
158
+ calculation: { type: String, trim: true },
159
+ sources: [{
170
160
  _id: false,
171
161
  model: { type: String, enum: ['Document', 'Meeting', 'Message', 'Note'] },
172
162
  ref: { type: Schema.Types.ObjectId },
173
163
  position: {
174
164
  _id: false,
175
165
  page: { type: Number },
176
- bbox: { _id: false, top: { type: Number }, left: { type: Number }, width: { type: Number }, height: { type: Number } },
177
- row: { type: Number },
178
- col: { type: Number },
179
- sheet: { type: String }
166
+ bbox: {
167
+ _id: false,
168
+ top: { type: Number },
169
+ left: { type: Number },
170
+ width: { type: Number },
171
+ height: { type: Number }
172
+ },
173
+ sheet: { type: String },
174
+ header: {
175
+ row: { type: Number },
176
+ column: { type: Number }
177
+ },
178
+ cell: {
179
+ row: { type: Number },
180
+ column: { type: Number }
181
+ }
180
182
  }
181
- },
183
+ }],
182
184
  verified: { type: Boolean },
183
185
  history: [{
184
186
  _id: false,
@@ -439,7 +441,8 @@ module.exports = function(mongoose, config) {
439
441
  const previousState = currentMetric ? {
440
442
  value: currentMetric.value != null ? currentMetric.value : null,
441
443
  breakdown: currentMetric.breakdown != null ? currentMetric.breakdown : null,
442
- source: currentMetric.source || null,
444
+ calculation: currentMetric.calculation || null,
445
+ sources: currentMetric.sources || [],
443
446
  verified: currentMetric.verified != null ? currentMetric.verified : null,
444
447
  history: currentMetric.history || []
445
448
  } : undefined;
@@ -450,7 +453,8 @@ module.exports = function(mongoose, config) {
450
453
  const $set = {
451
454
  'snapshots.$.metrics.$[metric].value': metric.value,
452
455
  'snapshots.$.metrics.$[metric].breakdown': metric.breakdown,
453
- 'snapshots.$.metrics.$[metric].source': metric.source,
456
+ 'snapshots.$.metrics.$[metric].calculation': metric.calculation,
457
+ 'snapshots.$.metrics.$[metric].sources': metric.sources,
454
458
  'snapshots.$.metrics.$[metric].verified': metric.verified
455
459
  };
456
460
 
@@ -562,7 +566,7 @@ module.exports = function(mongoose, config) {
562
566
  const $set = {};
563
567
  const $unset = { [prefix + '.previous']: 1 };
564
568
 
565
- const fields = ['value', 'breakdown', 'source', 'verified'];
569
+ const fields = ['value', 'breakdown', 'calculation', 'sources', 'verified'];
566
570
  fields.forEach(field => {
567
571
  if (prev[field] != null) {
568
572
  $set[prefix + '.' + field] = prev[field];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "11.142.0",
3
+ "version": "11.144.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
@@ -17,7 +17,7 @@
17
17
  * 7. Remove verified field from questions[] (removed in commit 300a22a)
18
18
  * 8. Add verified: true for metrics[] only
19
19
  * 9. Convert metrics from old structure { name, actual, budget, forecast, breakdown }
20
- * to new structure { name, scenario, value, breakdown, source, verified, history }
20
+ * to new structure { name, scenario, value, breakdown, calculation, sources, verified, history }
21
21
  * 10. Link metrics to their source financial statement documents (Income Statement,
22
22
  * Balance Sheet, Cash Flow Statement) when available
23
23
  * 11. Remove projections array from root level
@@ -326,7 +326,7 @@ async function migrateFinancials() {
326
326
  verified: true,
327
327
  history: historyArrayForMetrics
328
328
  };
329
- if (source) newMetric.source = source;
329
+ if (source) newMetric.sources = [source];
330
330
  newMetrics.push(newMetric);
331
331
  }
332
332
 
@@ -339,7 +339,7 @@ async function migrateFinancials() {
339
339
  verified: true,
340
340
  history: historyArrayForMetrics
341
341
  };
342
- if (source) newMetric.source = source;
342
+ if (source) newMetric.sources = [source];
343
343
  newMetrics.push(newMetric);
344
344
  }
345
345
 
@@ -352,14 +352,14 @@ async function migrateFinancials() {
352
352
  verified: true,
353
353
  history: historyArrayForMetrics
354
354
  };
355
- if (source) newMetric.source = source;
355
+ if (source) newMetric.sources = [source];
356
356
  newMetrics.push(newMetric);
357
357
  }
358
358
  });
359
359
 
360
- const metricsWithSource = newMetrics.filter(m => m.source).length;
360
+ const metricsWithSources = newMetrics.filter(m => m.sources && m.sources.length > 0).length;
361
361
  updates[`snapshots.${index}.metrics`] = newMetrics;
362
- changes.push(` - Snapshot ${index}: Converted ${oldMetrics.length} metric(s) to new structure (${newMetrics.length} entries, ${metricsWithSource} with source)`);
362
+ changes.push(` - Snapshot ${index}: Converted ${oldMetrics.length} metric(s) to new structure (${newMetrics.length} entries, ${metricsWithSources} with sources)`);
363
363
  } else {
364
364
  // Already in new structure, just add verified, history, and source if missing
365
365
  oldMetrics.forEach((metric, mIndex) => {
@@ -371,11 +371,11 @@ async function migrateFinancials() {
371
371
  updates[`snapshots.${index}.metrics.${mIndex}.history`] = historyArrayForMetrics;
372
372
  changes.push(` - Snapshot ${index}: Added history (${historyArrayForMetrics.length} entries) to metric ${mIndex}`);
373
373
  }
374
- if (!('source' in metric)) {
374
+ if (!('sources' in metric)) {
375
375
  const source = getSourceForMetric(metric.name);
376
376
  if (source) {
377
- updates[`snapshots.${index}.metrics.${mIndex}.source`] = source;
378
- changes.push(` - Snapshot ${index}: Added source to metric ${mIndex} (${metric.name})`);
377
+ updates[`snapshots.${index}.metrics.${mIndex}.sources`] = [source];
378
+ changes.push(` - Snapshot ${index}: Added sources to metric ${mIndex} (${metric.name})`);
379
379
  }
380
380
  }
381
381
  });