pict-section-form 1.0.87 → 1.0.88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,125 @@
1
+
2
+ const Pict = require('pict');
3
+ const Provider = require('../source/providers/inputs/Pict-Provider-Input-EntityBundleRequest.js');
4
+
5
+ const main = async (projectID) =>
6
+ {
7
+ const pict = new Pict({ RestClientURLPrefix: 'https://api.qa.headlight.com', PictDefaultURLPrefix: '/1.0/' });
8
+ pict.LogNoisiness = 1;
9
+ const preRequestOptions = pict.RestClient.prepareRequestOptions;
10
+ let token = '';
11
+ pict.RestClient.prepareRequestOptions = (pOptions) =>
12
+ {
13
+ if (!pOptions.headers)
14
+ {
15
+ pOptions.headers = { };
16
+ }
17
+ if (token)
18
+ {
19
+ pOptions.headers.Authorization = `Bearer ${token}`;
20
+ }
21
+ pict.log.info(`Requesting ${pOptions.url} with token ${token}`);
22
+ return preRequestOptions(pOptions);
23
+ };
24
+ await new Promise((resolve, reject) => pict.RestClient.postJSON({ url: '/1.0/Authenticate', body: { UserName: 'ladotd', Password: 'emerald guppy' } }, (err, response, result) =>
25
+ {
26
+ if (err)
27
+ {
28
+ return reject(err);
29
+ }
30
+ token = result.SessionID;
31
+ pict.log.info(`Received token ${token}`);
32
+ resolve(result);
33
+ }));
34
+ pict.AppData.IDProject = projectID;
35
+ const provider = pict.addProvider('EntityBundleRequest', {}, Provider);
36
+ const dataLoadError = await provider.gatherDataFromServer({},
37
+ {
38
+ PictForm:
39
+ {
40
+ EntitiesBundle:
41
+ [
42
+ {
43
+ "Entity": "Project",
44
+ "Filter": "FBV~IDProject~EQ~{~D:Record.Value.IDProject~}",
45
+ "Destination": "AppData.Project",
46
+ "SingleRecord": true
47
+ },
48
+ {
49
+ "Entity": "Document",
50
+ "Filter": "FBV~IDProject~EQ~{~D:Record.Value.IDProject~}~FBV~DocumentType~EQ~LADOTD-PartialPayment~FSF~DocumentDate~DESC~0~FSF~IDDocument~DESC~0",
51
+ "Destination": "AppData.PaymentForms",
52
+ "RecordCount": 1
53
+ },
54
+ {
55
+ "Entity": "Document",
56
+ "Filter": "FBV~IDProject~EQ~{~D:Record.Value.IDProject~}~FBV~DocumentType~EQ~ProjectProgressUpdate-LADOTD~FSF~DocumentDate~DESC~0~FSF~IDDocument~DESC~0",
57
+ "Destination": "AppData.ProgressForms",
58
+ "RecordCount": 1
59
+ },
60
+ {
61
+ "Entity": "Contract",
62
+ "Filter": "FBV~IDContract~EQ~{~D:AppData.Project.IDContract~}",
63
+ "Destination": "AppData.Contract"
64
+ },
65
+ {
66
+ "Entity": "ContractDate",
67
+ "Filter": "FBV~IDContract~EQ~{~D:AppData.Project.IDContract~}~FBV~Hash~EQ~NTPD",
68
+ "Destination": "AppData.NTPDate",
69
+ "SingleRecord": true
70
+ },
71
+ {
72
+ "Entity": "LineItem",
73
+ "Filter": "FBV~IDProject~EQ~{~D:Record.Value.IDProject~}",
74
+ "Destination": "AppData.LineItems"
75
+ },
76
+ ]
77
+ }
78
+ }, { IDProject: projectID });
79
+ if (dataLoadError)
80
+ {
81
+ pict.log.error(`Error loading data from server: ${dataLoadError.message || dataLoadError}`, { dataLoadError });
82
+ }
83
+ const data =
84
+ {
85
+ ProjectID: pict.AppData.Project.IDProject,
86
+ ContractID: pict.AppData.Project.IDContract,
87
+ Project: pict.AppData.Project.Name,
88
+ ContractedDays: pict.AppData.Project.ContractedDays,
89
+ //TODO: precise math?
90
+ SumOfLineItemAmounts: pict.AppData.LineItems.reduce((sum, lineItem) => sum + lineItem.ExpectedQuantity * lineItem.CostPerUnit, 0),
91
+ TotalBidAmount: pict.AppData.Contract.TotalBidAmount,
92
+ NetChangeOrderAmount: pict.AppData.Contract.NetChangeOrderAmount,
93
+ NTPDate: pict.AppData.NTPDate ? pict.AppData.NTPDate.Date : null,
94
+ };
95
+ if (pict.AppData.PaymentForms.length > 0)
96
+ {
97
+ data.PaymentDaysTotalPaidIncludingThisPayment = pict.AppData.PaymentForms[0].FormData.PaymentDaysTotalPaidIncludingThisPayment;
98
+ data.WorkingDaysTotal = pict.AppData.PaymentForms[0].FormData.WorkingDaysTotal;
99
+ for (const total of pict.AppData.PaymentForms[0].FormData.Totals)
100
+ {
101
+ if (total.name == 'Grand Total Paid to Date this Contract - Including this Payment')
102
+ {
103
+ data.PaidTotal = total.amount;
104
+ }
105
+ }
106
+ }
107
+ if (pict.AppData.ProgressForms.length > 0)
108
+ {
109
+ const progressData = pict.AppData.ProgressForms[0].FormData?.EstimatedCompletion;
110
+ if (progressData)
111
+ {
112
+ data.EstimatedCompletionDate = `${progressData.Month}, ${progressData.Year}`;
113
+ data.ECDNotes = progressData.Notes;
114
+ }
115
+ }
116
+ pict.log.info('Data gathered from server', data);
117
+ };
118
+
119
+ main(7323).then(() =>
120
+ {
121
+ console.info('Done');
122
+ }).catch((err) =>
123
+ {
124
+ console.error(err);
125
+ });
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "harness",
3
+ "version": "1.0.0",
4
+ "main": "Harness.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "author": "",
9
+ "license": "ISC",
10
+ "description": "",
11
+ "dependencies": {
12
+ "pict": "^1.0.241"
13
+ }
14
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "include": ["*.js", "../source"],
3
+ "compilerOptions":
4
+ {
5
+ "target": "es2019",
6
+ "esModuleInterop": true,
7
+ "allowJs": true,
8
+ "checkJs": true,
9
+ "declaration": true,
10
+ "emitDeclarationOnly": true,
11
+ "outDir": "types",
12
+ "declarationMap": true,
13
+ "module": "commonjs",
14
+ "resolveJsonModule": true
15
+ }
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pict-section-form",
3
- "version": "1.0.87",
3
+ "version": "1.0.88",
4
4
  "description": "Pict dynamic form sections",
5
5
  "main": "source/Pict-Section-Form.js",
6
6
  "directories": {
@@ -164,7 +164,7 @@ class PictDynamicSolver extends libPictProvider
164
164
  continue;
165
165
  }
166
166
 
167
- tmpSolver.StartTimeStamp = +new Date();
167
+ tmpSolver.StartTimeStamp = Date.now();
168
168
  tmpSolver.Hash = `${pGroupSolverArray[j].ViewHash}-GroupSolver-${j}`;
169
169
 
170
170
  if (this.pict.LogNoisiness > 1)
@@ -174,12 +174,11 @@ class PictDynamicSolver extends libPictProvider
174
174
 
175
175
  let tmpRecordSet = tmpView.getTabularRecordSet(tmpGroup.GroupIndex);
176
176
 
177
- if (typeof(tmpRecordSet) == 'object')
177
+ if (Array.isArray(tmpRecordSet))
178
178
  {
179
- let tmpRecordSetKeys = Object.keys(tmpRecordSet);
180
- for (let l = 0; l < tmpRecordSetKeys.length; l++)
179
+ for (let l = 0; l < tmpRecordSet.length; l++)
181
180
  {
182
- let tmpRecord = tmpRecordSet[tmpRecordSetKeys[l]];
181
+ let tmpRecord = tmpRecordSet[l];
183
182
  tmpSolver.ResultsObject = {};
184
183
  let tmpSolutionValue = tmpView.fable.ExpressionParser.solve(tmpSolver.Expression, tmpRecord, tmpSolver.ResultsObject, tmpGroup.supportingManifest, tmpRecord);
185
184
  if (this.pict.LogNoisiness > 1)
@@ -188,11 +187,12 @@ class PictDynamicSolver extends libPictProvider
188
187
  }
189
188
  }
190
189
  }
191
- if (Array.isArray(tmpRecordSet))
190
+ else if (typeof(tmpRecordSet) == 'object')
192
191
  {
193
- for (let l = 0; l < tmpRecordSet.length; l++)
192
+ let tmpRecordSetKeys = Object.keys(tmpRecordSet);
193
+ for (let l = 0; l < tmpRecordSetKeys.length; l++)
194
194
  {
195
- let tmpRecord = tmpRecordSet[l];
195
+ let tmpRecord = tmpRecordSet[tmpRecordSetKeys[l]];
196
196
  tmpSolver.ResultsObject = {};
197
197
  let tmpSolutionValue = tmpView.fable.ExpressionParser.solve(tmpSolver.Expression, tmpRecord, tmpSolver.ResultsObject, tmpGroup.supportingManifest, tmpRecord);
198
198
  if (this.pict.LogNoisiness > 1)
@@ -201,7 +201,7 @@ class PictDynamicSolver extends libPictProvider
201
201
  }
202
202
  }
203
203
  }
204
- tmpSolver.EndTimeStamp = +new Date();
204
+ tmpSolver.EndTimeStamp = Date.now();
205
205
  }
206
206
  }
207
207