1
|
|
|
import React, { Fragment, useEffect, useState } from 'react'; |
2
|
|
|
import { |
3
|
|
|
Breadcrumb, |
4
|
|
|
BreadcrumbItem, |
5
|
|
|
Row, |
6
|
|
|
Col, |
7
|
|
|
Card, |
8
|
|
|
CardBody, |
9
|
|
|
Button, |
10
|
|
|
ButtonGroup, |
11
|
|
|
Form, |
12
|
|
|
FormGroup, |
13
|
|
|
Input, |
14
|
|
|
Label, |
15
|
|
|
CustomInput, |
16
|
|
|
Spinner, |
17
|
|
|
} from 'reactstrap'; |
18
|
|
|
import CountUp from 'react-countup'; |
19
|
|
|
import Datetime from 'react-datetime'; |
20
|
|
|
import moment from 'moment'; |
21
|
|
|
import loadable from '@loadable/component'; |
22
|
|
|
import Cascader from 'rc-cascader'; |
23
|
|
|
import CardSummary from '../common/CardSummary'; |
24
|
|
|
import LineChart from '../common/LineChart'; |
25
|
|
|
import SharePie from '../common/SharePie'; |
26
|
|
|
import { getCookieValue, createCookie } from '../../../helpers/utils'; |
27
|
|
|
import withRedirect from '../../../hoc/withRedirect'; |
28
|
|
|
import { withTranslation } from 'react-i18next'; |
29
|
|
|
import { toast } from 'react-toastify'; |
30
|
|
|
import ButtonIcon from '../../common/ButtonIcon'; |
31
|
|
|
import { APIBaseURL } from '../../../config'; |
32
|
|
|
import { periodTypeOptions } from '../common/PeriodTypeOptions'; |
33
|
|
|
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions'; |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable')); |
37
|
|
|
|
38
|
|
|
const StoreSaving = ({ setRedirect, setRedirectUrl, t }) => { |
39
|
|
|
let current_moment = moment(); |
40
|
|
|
useEffect(() => { |
41
|
|
|
let is_logged_in = getCookieValue('is_logged_in'); |
42
|
|
|
let user_name = getCookieValue('user_name'); |
43
|
|
|
let user_display_name = getCookieValue('user_display_name'); |
44
|
|
|
let user_uuid = getCookieValue('user_uuid'); |
45
|
|
|
let token = getCookieValue('token'); |
46
|
|
|
if (is_logged_in === null || !is_logged_in) { |
47
|
|
|
setRedirectUrl(`/authentication/basic/login`); |
48
|
|
|
setRedirect(true); |
49
|
|
|
} else { |
50
|
|
|
//update expires time of cookies |
51
|
|
|
createCookie('is_logged_in', true, 1000 * 60 * 60 * 8); |
52
|
|
|
createCookie('user_name', user_name, 1000 * 60 * 60 * 8); |
53
|
|
|
createCookie('user_display_name', user_display_name, 1000 * 60 * 60 * 8); |
54
|
|
|
createCookie('user_uuid', user_uuid, 1000 * 60 * 60 * 8); |
55
|
|
|
createCookie('token', token, 1000 * 60 * 60 * 8); |
56
|
|
|
} |
57
|
|
|
}); |
58
|
|
|
// State |
59
|
|
|
// Query Parameters |
60
|
|
|
const [selectedSpaceName, setSelectedSpaceName] = useState(undefined); |
61
|
|
|
const [selectedSpaceID, setSelectedSpaceID] = useState(undefined); |
62
|
|
|
const [storeList, setStoreList] = useState([]); |
63
|
|
|
const [selectedStore, setSelectedStore] = useState(undefined); |
64
|
|
|
const [comparisonType, setComparisonType] = useState('month-on-month'); |
65
|
|
|
const [periodType, setPeriodType] = useState('daily'); |
66
|
|
|
const [basePeriodBeginsDatetime, setBasePeriodBeginsDatetime] = useState(current_moment.clone().subtract(1, 'months').startOf('month')); |
67
|
|
|
const [basePeriodEndsDatetime, setBasePeriodEndsDatetime] = useState(current_moment.clone().subtract(1, 'months')); |
68
|
|
|
const [basePeriodBeginsDatetimeDisabled, setBasePeriodBeginsDatetimeDisabled] = useState(true); |
69
|
|
|
const [basePeriodEndsDatetimeDisabled, setBasePeriodEndsDatetimeDisabled] = useState(true); |
70
|
|
|
const [reportingPeriodBeginsDatetime, setReportingPeriodBeginsDatetime] = useState(current_moment.clone().startOf('month')); |
71
|
|
|
const [reportingPeriodEndsDatetime, setReportingPeriodEndsDatetime] = useState(current_moment); |
72
|
|
|
const [cascaderOptions, setCascaderOptions] = useState(undefined); |
73
|
|
|
|
74
|
|
|
// buttons |
75
|
|
|
const [submitButtonDisabled, setSubmitButtonDisabled] = useState(true); |
76
|
|
|
const [spinnerHidden, setSpinnerHidden] = useState(true); |
77
|
|
|
const [exportButtonHidden, setExportButtonHidden] = useState(true); |
78
|
|
|
|
79
|
|
|
//Results |
80
|
|
|
const [TCEShareData, setTCEShareData] = useState([]); |
81
|
|
|
const [TCO2EShareData, setTCO2EShareData] = useState([]); |
82
|
|
|
|
83
|
|
|
const [cardSummaryList, setCardSummaryList] = useState([]); |
84
|
|
|
const [totalInTCE, setTotalInTCE] = useState({}); |
85
|
|
|
const [totalInTCO2E, setTotalInTCO2E] = useState({}); |
86
|
|
|
const [storeLineChartLabels, setStoreLineChartLabels] = useState([]); |
87
|
|
|
const [storeLineChartData, setStoreLineChartData] = useState({}); |
88
|
|
|
const [storeLineChartOptions, setStoreLineChartOptions] = useState([]); |
89
|
|
|
|
90
|
|
|
const [parameterLineChartLabels, setParameterLineChartLabels] = useState([]); |
91
|
|
|
const [parameterLineChartData, setParameterLineChartData] = useState({}); |
92
|
|
|
const [parameterLineChartOptions, setParameterLineChartOptions] = useState([]); |
93
|
|
|
|
94
|
|
|
const [detailedDataTableData, setDetailedDataTableData] = useState([]); |
95
|
|
|
const [detailedDataTableColumns, setDetailedDataTableColumns] = useState([{dataField: 'startdatetime', text: t('Datetime'), sort: true}]); |
96
|
|
|
const [excelBytesBase64, setExcelBytesBase64] = useState(undefined); |
97
|
|
|
|
98
|
|
|
useEffect(() => { |
99
|
|
|
let isResponseOK = false; |
100
|
|
|
fetch(APIBaseURL + '/spaces/tree', { |
101
|
|
|
method: 'GET', |
102
|
|
|
headers: { |
103
|
|
|
"Content-type": "application/json", |
104
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
105
|
|
|
"Token": getCookieValue('token') |
106
|
|
|
}, |
107
|
|
|
body: null, |
108
|
|
|
|
109
|
|
|
}).then(response => { |
110
|
|
|
console.log(response); |
111
|
|
|
if (response.ok) { |
112
|
|
|
isResponseOK = true; |
113
|
|
|
} |
114
|
|
|
return response.json(); |
115
|
|
|
}).then(json => { |
116
|
|
|
console.log(json); |
117
|
|
|
if (isResponseOK) { |
118
|
|
|
// rename keys |
119
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
120
|
|
|
setCascaderOptions(json); |
121
|
|
|
setSelectedSpaceName([json[0]].map(o => o.label)); |
122
|
|
|
setSelectedSpaceID([json[0]].map(o => o.value)); |
123
|
|
|
// get Stores by root Space ID |
124
|
|
|
let isResponseOK = false; |
125
|
|
|
fetch(APIBaseURL + '/spaces/' + [json[0]].map(o => o.value) + '/stores', { |
126
|
|
|
method: 'GET', |
127
|
|
|
headers: { |
128
|
|
|
"Content-type": "application/json", |
129
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
130
|
|
|
"Token": getCookieValue('token') |
131
|
|
|
}, |
132
|
|
|
body: null, |
133
|
|
|
|
134
|
|
|
}).then(response => { |
135
|
|
|
if (response.ok) { |
136
|
|
|
isResponseOK = true; |
137
|
|
|
} |
138
|
|
|
return response.json(); |
139
|
|
|
}).then(json => { |
140
|
|
|
if (isResponseOK) { |
141
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
142
|
|
|
console.log(json); |
143
|
|
|
setStoreList(json[0]); |
144
|
|
|
if (json[0].length > 0) { |
145
|
|
|
setSelectedStore(json[0][0].value); |
146
|
|
|
// enable submit button |
147
|
|
|
setSubmitButtonDisabled(false); |
148
|
|
|
} else { |
149
|
|
|
setSelectedStore(undefined); |
150
|
|
|
// disable submit button |
151
|
|
|
setSubmitButtonDisabled(true); |
152
|
|
|
} |
153
|
|
|
} else { |
154
|
|
|
toast.error(json.description) |
155
|
|
|
} |
156
|
|
|
}).catch(err => { |
157
|
|
|
console.log(err); |
158
|
|
|
}); |
159
|
|
|
// end of get Stores by root Space ID |
160
|
|
|
} else { |
161
|
|
|
toast.error(json.description); |
162
|
|
|
} |
163
|
|
|
}).catch(err => { |
164
|
|
|
console.log(err); |
165
|
|
|
}); |
166
|
|
|
|
167
|
|
|
}, []); |
168
|
|
|
|
169
|
|
|
const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0'; |
170
|
|
|
|
171
|
|
|
let onSpaceCascaderChange = (value, selectedOptions) => { |
172
|
|
|
setSelectedSpaceName(selectedOptions.map(o => o.label).join('/')); |
173
|
|
|
setSelectedSpaceID(value[value.length - 1]); |
174
|
|
|
|
175
|
|
|
let isResponseOK = false; |
176
|
|
|
fetch(APIBaseURL + '/spaces/' + value[value.length - 1] + '/stores', { |
177
|
|
|
method: 'GET', |
178
|
|
|
headers: { |
179
|
|
|
"Content-type": "application/json", |
180
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
181
|
|
|
"Token": getCookieValue('token') |
182
|
|
|
}, |
183
|
|
|
body: null, |
184
|
|
|
|
185
|
|
|
}).then(response => { |
186
|
|
|
if (response.ok) { |
187
|
|
|
isResponseOK = true; |
188
|
|
|
} |
189
|
|
|
return response.json(); |
190
|
|
|
}).then(json => { |
191
|
|
|
if (isResponseOK) { |
192
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
193
|
|
|
console.log(json) |
194
|
|
|
setStoreList(json[0]); |
195
|
|
|
if (json[0].length > 0) { |
196
|
|
|
setSelectedStore(json[0][0].value); |
197
|
|
|
// enable submit button |
198
|
|
|
setSubmitButtonDisabled(false); |
199
|
|
|
} else { |
200
|
|
|
setSelectedStore(undefined); |
201
|
|
|
// disable submit button |
202
|
|
|
setSubmitButtonDisabled(true); |
203
|
|
|
} |
204
|
|
|
} else { |
205
|
|
|
toast.error(json.description) |
206
|
|
|
} |
207
|
|
|
}).catch(err => { |
208
|
|
|
console.log(err); |
209
|
|
|
}); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
|
213
|
|
|
let onComparisonTypeChange = ({ target }) => { |
214
|
|
|
console.log(target.value); |
215
|
|
|
setComparisonType(target.value); |
216
|
|
|
if (target.value === 'year-over-year') { |
217
|
|
|
setBasePeriodBeginsDatetimeDisabled(true); |
218
|
|
|
setBasePeriodEndsDatetimeDisabled(true); |
219
|
|
|
setBasePeriodBeginsDatetime(moment(reportingPeriodBeginsDatetime).subtract(1, 'years')); |
220
|
|
|
setBasePeriodEndsDatetime(moment(reportingPeriodEndsDatetime).subtract(1, 'years')); |
221
|
|
|
} else if (target.value === 'month-on-month') { |
222
|
|
|
setBasePeriodBeginsDatetimeDisabled(true); |
223
|
|
|
setBasePeriodEndsDatetimeDisabled(true); |
224
|
|
|
setBasePeriodBeginsDatetime(moment(reportingPeriodBeginsDatetime).subtract(1, 'months')); |
225
|
|
|
setBasePeriodEndsDatetime(moment(reportingPeriodEndsDatetime).subtract(1, 'months')); |
226
|
|
|
} else if (target.value === 'free-comparison') { |
227
|
|
|
setBasePeriodBeginsDatetimeDisabled(false); |
228
|
|
|
setBasePeriodEndsDatetimeDisabled(false); |
229
|
|
|
} else if (target.value === 'none-comparison') { |
230
|
|
|
setBasePeriodBeginsDatetime(undefined); |
231
|
|
|
setBasePeriodEndsDatetime(undefined); |
232
|
|
|
setBasePeriodBeginsDatetimeDisabled(true); |
233
|
|
|
setBasePeriodEndsDatetimeDisabled(true); |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
let onBasePeriodBeginsDatetimeChange = (newDateTime) => { |
238
|
|
|
setBasePeriodBeginsDatetime(newDateTime); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
let onBasePeriodEndsDatetimeChange = (newDateTime) => { |
242
|
|
|
setBasePeriodEndsDatetime(newDateTime); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
let onReportingPeriodBeginsDatetimeChange = (newDateTime) => { |
246
|
|
|
setReportingPeriodBeginsDatetime(newDateTime); |
247
|
|
|
if (comparisonType === 'year-over-year') { |
248
|
|
|
setBasePeriodBeginsDatetime(newDateTime.clone().subtract(1, 'years')); |
249
|
|
|
} else if (comparisonType === 'month-on-month') { |
250
|
|
|
setBasePeriodBeginsDatetime(newDateTime.clone().subtract(1, 'months')); |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
let onReportingPeriodEndsDatetimeChange = (newDateTime) => { |
255
|
|
|
setReportingPeriodEndsDatetime(newDateTime); |
256
|
|
|
if (comparisonType === 'year-over-year') { |
257
|
|
|
setBasePeriodEndsDatetime(newDateTime.clone().subtract(1, 'years')); |
258
|
|
|
} else if (comparisonType === 'month-on-month') { |
259
|
|
|
setBasePeriodEndsDatetime(newDateTime.clone().subtract(1, 'months')); |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
var getValidBasePeriodBeginsDatetimes = function (currentDate) { |
264
|
|
|
return currentDate.isBefore(moment(basePeriodEndsDatetime, 'MM/DD/YYYY, hh:mm:ss a')); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
var getValidBasePeriodEndsDatetimes = function (currentDate) { |
268
|
|
|
return currentDate.isAfter(moment(basePeriodBeginsDatetime, 'MM/DD/YYYY, hh:mm:ss a')); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
var getValidReportingPeriodBeginsDatetimes = function (currentDate) { |
272
|
|
|
return currentDate.isBefore(moment(reportingPeriodEndsDatetime, 'MM/DD/YYYY, hh:mm:ss a')); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
var getValidReportingPeriodEndsDatetimes = function (currentDate) { |
276
|
|
|
return currentDate.isAfter(moment(reportingPeriodBeginsDatetime, 'MM/DD/YYYY, hh:mm:ss a')); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
// Handler |
280
|
|
|
const handleSubmit = e => { |
281
|
|
|
e.preventDefault(); |
282
|
|
|
console.log('handleSubmit'); |
283
|
|
|
console.log(selectedSpaceID); |
284
|
|
|
console.log(selectedStore); |
285
|
|
|
console.log(periodType); |
286
|
|
|
console.log(basePeriodBeginsDatetime != null ? basePeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') : undefined); |
287
|
|
|
console.log(basePeriodEndsDatetime != null ? basePeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss') : undefined); |
288
|
|
|
console.log(reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss')); |
289
|
|
|
console.log(reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss')); |
290
|
|
|
|
291
|
|
|
// disable submit button |
292
|
|
|
setSubmitButtonDisabled(true); |
293
|
|
|
// show spinner |
294
|
|
|
setSpinnerHidden(false); |
295
|
|
|
// hide export buttion |
296
|
|
|
setExportButtonHidden(true) |
297
|
|
|
|
298
|
|
|
// Reinitialize tables |
299
|
|
|
setDetailedDataTableData([]); |
300
|
|
|
|
301
|
|
|
let isResponseOK = false; |
302
|
|
|
fetch(APIBaseURL + '/reports/storesaving?' + |
303
|
|
|
'storeid=' + selectedStore + |
304
|
|
|
'&periodtype=' + periodType + |
305
|
|
|
'&baseperiodstartdatetime=' + (basePeriodBeginsDatetime != null ? basePeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') + |
306
|
|
|
'&baseperiodenddatetime=' + (basePeriodEndsDatetime != null ? basePeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') + |
307
|
|
|
'&reportingperiodstartdatetime=' + reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') + |
308
|
|
|
'&reportingperiodenddatetime=' + reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'), { |
309
|
|
|
method: 'GET', |
310
|
|
|
headers: { |
311
|
|
|
"Content-type": "application/json", |
312
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
313
|
|
|
"Token": getCookieValue('token') |
314
|
|
|
}, |
315
|
|
|
body: null, |
316
|
|
|
|
317
|
|
|
}).then(response => { |
318
|
|
|
if (response.ok) { |
319
|
|
|
isResponseOK = true; |
320
|
|
|
} |
321
|
|
|
return response.json(); |
322
|
|
|
}).then(json => { |
323
|
|
|
if (isResponseOK) { |
324
|
|
|
console.log(json) |
325
|
|
|
|
326
|
|
|
let cardSummaryArray = [] |
327
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
328
|
|
|
let cardSummaryItem = {} |
329
|
|
|
cardSummaryItem['name'] = json['reporting_period']['names'][index]; |
330
|
|
|
cardSummaryItem['unit'] = json['reporting_period']['units'][index]; |
331
|
|
|
cardSummaryItem['subtotal'] = json['reporting_period']['subtotals_saving'][index]; |
332
|
|
|
cardSummaryItem['increment_rate'] = parseFloat(json['reporting_period']['increment_rates_saving'][index] * 100).toFixed(2) + "%"; |
333
|
|
|
cardSummaryItem['subtotal_per_unit_area'] = json['reporting_period']['subtotals_per_unit_area_saving'][index]; |
334
|
|
|
cardSummaryArray.push(cardSummaryItem); |
335
|
|
|
}); |
336
|
|
|
setCardSummaryList(cardSummaryArray); |
337
|
|
|
|
338
|
|
|
let totalInTCE = {}; |
339
|
|
|
totalInTCE['value'] = json['reporting_period']['total_in_kgce_saving'] / 1000; // convert from kg to t |
340
|
|
|
totalInTCE['increment_rate'] = parseFloat(json['reporting_period']['increment_rate_in_kgce_saving'] * 100).toFixed(2) + "%"; |
341
|
|
|
totalInTCE['value_per_unit_area'] = json['reporting_period']['total_in_kgce_per_unit_area_saving'] / 1000; // convert from kg to t |
342
|
|
|
setTotalInTCE(totalInTCE); |
343
|
|
|
|
344
|
|
|
let totalInTCO2E = {}; |
345
|
|
|
totalInTCO2E['value'] = json['reporting_period']['total_in_kgco2e_saving'] / 1000; // convert from kg to t |
346
|
|
|
totalInTCO2E['increment_rate'] = parseFloat(json['reporting_period']['increment_rate_in_kgco2e_saving'] * 100).toFixed(2) + "%"; |
347
|
|
|
totalInTCO2E['value_per_unit_area'] = json['reporting_period']['total_in_kgco2e_per_unit_area_saving'] / 1000; // convert from kg to t |
348
|
|
|
setTotalInTCO2E(totalInTCO2E); |
349
|
|
|
|
350
|
|
|
let TCEDataArray = []; |
351
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
352
|
|
|
let TCEDataItem = {} |
353
|
|
|
TCEDataItem['id'] = index; |
354
|
|
|
TCEDataItem['name'] = currentValue; |
355
|
|
|
TCEDataItem['value'] = json['reporting_period']['subtotals_in_kgce_saving'][index] / 1000; // convert from kg to t |
356
|
|
|
TCEDataItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); |
357
|
|
|
TCEDataArray.push(TCEDataItem); |
358
|
|
|
}); |
359
|
|
|
setTCEShareData(TCEDataArray); |
360
|
|
|
|
361
|
|
|
let TCO2EDataArray = []; |
362
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
363
|
|
|
let TCO2EDataItem = {} |
364
|
|
|
TCO2EDataItem['id'] = index; |
365
|
|
|
TCO2EDataItem['name'] = currentValue; |
366
|
|
|
TCO2EDataItem['value'] = json['reporting_period']['subtotals_in_kgco2e_saving'][index] / 1000; // convert from kg to t |
367
|
|
|
TCO2EDataItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); |
368
|
|
|
TCO2EDataArray.push(TCO2EDataItem); |
369
|
|
|
}); |
370
|
|
|
setTCO2EShareData(TCO2EDataArray); |
371
|
|
|
|
372
|
|
|
let timestamps = {} |
373
|
|
|
json['reporting_period']['timestamps'].forEach((currentValue, index) => { |
374
|
|
|
timestamps['a' + index] = currentValue; |
375
|
|
|
}); |
376
|
|
|
setStoreLineChartLabels(timestamps); |
377
|
|
|
|
378
|
|
|
let values = {} |
379
|
|
|
json['reporting_period']['values_saving'].forEach((currentValue, index) => { |
380
|
|
|
values['a' + index] = currentValue; |
381
|
|
|
}); |
382
|
|
|
setStoreLineChartData(values); |
383
|
|
|
|
384
|
|
|
let names = Array(); |
385
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
386
|
|
|
let unit = json['reporting_period']['units'][index]; |
387
|
|
|
names.push({ 'value': 'a' + index, 'label': currentValue + ' (' + unit + ')'}); |
388
|
|
|
}); |
389
|
|
|
setStoreLineChartOptions(names); |
390
|
|
|
|
391
|
|
|
timestamps = {} |
392
|
|
|
json['parameters']['timestamps'].forEach((currentValue, index) => { |
393
|
|
|
timestamps['a' + index] = currentValue; |
394
|
|
|
}); |
395
|
|
|
setParameterLineChartLabels(timestamps); |
396
|
|
|
|
397
|
|
|
values = {} |
398
|
|
|
json['parameters']['values'].forEach((currentValue, index) => { |
399
|
|
|
values['a' + index] = currentValue; |
400
|
|
|
}); |
401
|
|
|
setParameterLineChartData(values); |
402
|
|
|
|
403
|
|
|
names = Array(); |
404
|
|
|
json['parameters']['names'].forEach((currentValue, index) => { |
405
|
|
|
if (currentValue.startsWith('TARIFF-')) { |
406
|
|
|
currentValue = t('Tariff') + currentValue.replace('TARIFF-', '-'); |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
names.push({ 'value': 'a' + index, 'label': currentValue }); |
410
|
|
|
}); |
411
|
|
|
setParameterLineChartOptions(names); |
412
|
|
|
|
413
|
|
|
let detailed_value_list = []; |
414
|
|
|
if (json['reporting_period']['timestamps'].length > 0) { |
415
|
|
|
json['reporting_period']['timestamps'][0].forEach((currentTimestamp, timestampIndex) => { |
416
|
|
|
let detailed_value = {}; |
417
|
|
|
detailed_value['id'] = timestampIndex; |
418
|
|
|
detailed_value['startdatetime'] = currentTimestamp; |
419
|
|
|
json['reporting_period']['values_saving'].forEach((currentValue, energyCategoryIndex) => { |
420
|
|
|
detailed_value['a' + energyCategoryIndex] = json['reporting_period']['values_saving'][energyCategoryIndex][timestampIndex].toFixed(2); |
421
|
|
|
}); |
422
|
|
|
detailed_value_list.push(detailed_value); |
423
|
|
|
}); |
424
|
|
|
}; |
425
|
|
|
|
426
|
|
|
let detailed_value = {}; |
427
|
|
|
detailed_value['id'] = detailed_value_list.length; |
428
|
|
|
detailed_value['startdatetime'] = t('Subtotal'); |
429
|
|
|
json['reporting_period']['subtotals_saving'].forEach((currentValue, index) => { |
430
|
|
|
detailed_value['a' + index] = currentValue.toFixed(2); |
431
|
|
|
}); |
432
|
|
|
detailed_value_list.push(detailed_value); |
433
|
|
|
setDetailedDataTableData(detailed_value_list); |
434
|
|
|
|
435
|
|
|
let detailed_column_list = []; |
436
|
|
|
detailed_column_list.push({ |
437
|
|
|
dataField: 'startdatetime', |
438
|
|
|
text: t('Datetime'), |
439
|
|
|
sort: true |
440
|
|
|
}) |
441
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
442
|
|
|
let unit = json['reporting_period']['units'][index]; |
443
|
|
|
detailed_column_list.push({ |
444
|
|
|
dataField: 'a' + index, |
445
|
|
|
text: currentValue + ' (' + unit + ')', |
446
|
|
|
sort: true |
447
|
|
|
}) |
448
|
|
|
}); |
449
|
|
|
setDetailedDataTableColumns(detailed_column_list); |
450
|
|
|
|
451
|
|
|
setExcelBytesBase64(json['excel_bytes_base64']); |
452
|
|
|
|
453
|
|
|
// enable submit button |
454
|
|
|
setSubmitButtonDisabled(false); |
455
|
|
|
// hide spinner |
456
|
|
|
setSpinnerHidden(true); |
457
|
|
|
// show export buttion |
458
|
|
|
setExportButtonHidden(false) |
459
|
|
|
|
460
|
|
|
} else { |
461
|
|
|
toast.error(json.description) |
462
|
|
|
} |
463
|
|
|
}).catch(err => { |
464
|
|
|
console.log(err); |
465
|
|
|
}); |
466
|
|
|
}; |
467
|
|
|
|
468
|
|
|
const handleExport = e => { |
469
|
|
|
e.preventDefault(); |
470
|
|
|
const mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' |
471
|
|
|
const fileName = 'storesaving.xlsx' |
472
|
|
|
var fileUrl = "data:" + mimeType + ";base64," + excelBytesBase64; |
473
|
|
|
fetch(fileUrl) |
474
|
|
|
.then(response => response.blob()) |
475
|
|
|
.then(blob => { |
476
|
|
|
var link = window.document.createElement("a"); |
477
|
|
|
link.href = window.URL.createObjectURL(blob, { type: mimeType }); |
478
|
|
|
link.download = fileName; |
479
|
|
|
document.body.appendChild(link); |
480
|
|
|
link.click(); |
481
|
|
|
document.body.removeChild(link); |
482
|
|
|
}); |
483
|
|
|
}; |
484
|
|
|
|
485
|
|
|
|
486
|
|
|
|
487
|
|
|
return ( |
488
|
|
|
<Fragment> |
489
|
|
|
<div> |
490
|
|
|
<Breadcrumb> |
491
|
|
|
<BreadcrumbItem>{t('Store Data')}</BreadcrumbItem><BreadcrumbItem active>{t('Saving')}</BreadcrumbItem> |
492
|
|
|
</Breadcrumb> |
493
|
|
|
</div> |
494
|
|
|
<Card className="bg-light mb-3"> |
495
|
|
|
<CardBody className="p-3"> |
496
|
|
|
<Form onSubmit={handleSubmit}> |
497
|
|
|
<Row form> |
498
|
|
|
<Col xs="auto"> |
499
|
|
|
<FormGroup className="form-group"> |
500
|
|
|
<Label className={labelClasses} for="space"> |
501
|
|
|
{t('Space')} |
502
|
|
|
</Label> |
503
|
|
|
<br /> |
504
|
|
|
<Cascader options={cascaderOptions} |
505
|
|
|
onChange={onSpaceCascaderChange} |
506
|
|
|
changeOnSelect |
507
|
|
|
expandTrigger="hover"> |
508
|
|
|
<Input value={selectedSpaceName || ''} readOnly /> |
509
|
|
|
</Cascader> |
510
|
|
|
</FormGroup> |
511
|
|
|
</Col> |
512
|
|
|
<Col xs="auto"> |
513
|
|
|
<FormGroup> |
514
|
|
|
<Label className={labelClasses} for="storeSelect"> |
515
|
|
|
{t('Store')} |
516
|
|
|
</Label> |
517
|
|
|
<CustomInput type="select" id="storeSelect" name="storeSelect" onChange={({ target }) => setSelectedStore(target.value)} |
518
|
|
|
> |
519
|
|
|
{storeList.map((store, index) => ( |
520
|
|
|
<option value={store.value} key={store.value}> |
521
|
|
|
{store.label} |
522
|
|
|
</option> |
523
|
|
|
))} |
524
|
|
|
</CustomInput> |
525
|
|
|
</FormGroup> |
526
|
|
|
</Col> |
527
|
|
|
<Col xs="auto"> |
528
|
|
|
<FormGroup> |
529
|
|
|
<Label className={labelClasses} for="comparisonType"> |
530
|
|
|
{t('Comparison Types')} |
531
|
|
|
</Label> |
532
|
|
|
<CustomInput type="select" id="comparisonType" name="comparisonType" |
533
|
|
|
defaultValue="month-on-month" |
534
|
|
|
onChange={onComparisonTypeChange} |
535
|
|
|
> |
536
|
|
|
{comparisonTypeOptions.map((comparisonType, index) => ( |
537
|
|
|
<option value={comparisonType.value} key={comparisonType.value} > |
538
|
|
|
{t(comparisonType.label)} |
539
|
|
|
</option> |
540
|
|
|
))} |
541
|
|
|
</CustomInput> |
542
|
|
|
</FormGroup> |
543
|
|
|
</Col> |
544
|
|
|
<Col xs="auto"> |
545
|
|
|
<FormGroup> |
546
|
|
|
<Label className={labelClasses} for="periodType"> |
547
|
|
|
{t('Period Types')} |
548
|
|
|
</Label> |
549
|
|
|
<CustomInput type="select" id="periodType" name="periodType" defaultValue="daily" onChange={({ target }) => setPeriodType(target.value)} |
550
|
|
|
> |
551
|
|
|
{periodTypeOptions.map((periodType, index) => ( |
552
|
|
|
<option value={periodType.value} key={periodType.value} > |
553
|
|
|
{t(periodType.label)} |
554
|
|
|
</option> |
555
|
|
|
))} |
556
|
|
|
</CustomInput> |
557
|
|
|
</FormGroup> |
558
|
|
|
</Col> |
559
|
|
|
<Col xs="auto"> |
560
|
|
|
<FormGroup className="form-group"> |
561
|
|
|
<Label className={labelClasses} for="basePeriodBeginsDatetime"> |
562
|
|
|
{t('Base Period Begins')}{t('(Optional)')} |
563
|
|
|
</Label> |
564
|
|
|
<Datetime id='basePeriodBeginsDatetime' |
565
|
|
|
value={basePeriodBeginsDatetime} |
566
|
|
|
inputProps={{ disabled: basePeriodBeginsDatetimeDisabled }} |
567
|
|
|
onChange={onBasePeriodBeginsDatetimeChange} |
568
|
|
|
isValidDate={getValidBasePeriodBeginsDatetimes} |
569
|
|
|
closeOnSelect={true} /> |
570
|
|
|
</FormGroup> |
571
|
|
|
</Col> |
572
|
|
|
<Col xs="auto"> |
573
|
|
|
<FormGroup className="form-group"> |
574
|
|
|
<Label className={labelClasses} for="basePeriodEndsDatetime"> |
575
|
|
|
{t('Base Period Ends')}{t('(Optional)')} |
576
|
|
|
</Label> |
577
|
|
|
<Datetime id='basePeriodEndsDatetime' |
578
|
|
|
value={basePeriodEndsDatetime} |
579
|
|
|
inputProps={{ disabled: basePeriodEndsDatetimeDisabled }} |
580
|
|
|
onChange={onBasePeriodEndsDatetimeChange} |
581
|
|
|
isValidDate={getValidBasePeriodEndsDatetimes} |
582
|
|
|
closeOnSelect={true} /> |
583
|
|
|
</FormGroup> |
584
|
|
|
</Col> |
585
|
|
|
<Col xs="auto"> |
586
|
|
|
<FormGroup className="form-group"> |
587
|
|
|
<Label className={labelClasses} for="reportingPeriodBeginsDatetime"> |
588
|
|
|
{t('Reporting Period Begins')} |
589
|
|
|
</Label> |
590
|
|
|
<Datetime id='reportingPeriodBeginsDatetime' |
591
|
|
|
value={reportingPeriodBeginsDatetime} |
592
|
|
|
onChange={onReportingPeriodBeginsDatetimeChange} |
593
|
|
|
isValidDate={getValidReportingPeriodBeginsDatetimes} |
594
|
|
|
closeOnSelect={true} /> |
595
|
|
|
</FormGroup> |
596
|
|
|
</Col> |
597
|
|
|
<Col xs="auto"> |
598
|
|
|
<FormGroup className="form-group"> |
599
|
|
|
<Label className={labelClasses} for="reportingPeriodEndsDatetime"> |
600
|
|
|
{t('Reporting Period Ends')} |
601
|
|
|
</Label> |
602
|
|
|
<Datetime id='reportingPeriodEndsDatetime' |
603
|
|
|
value={reportingPeriodEndsDatetime} |
604
|
|
|
onChange={onReportingPeriodEndsDatetimeChange} |
605
|
|
|
isValidDate={getValidReportingPeriodEndsDatetimes} |
606
|
|
|
closeOnSelect={true} /> |
607
|
|
|
</FormGroup> |
608
|
|
|
</Col> |
609
|
|
|
<Col xs="auto"> |
610
|
|
|
<FormGroup> |
611
|
|
|
<br></br> |
612
|
|
|
<ButtonGroup id="submit"> |
613
|
|
|
<Button color="success" disabled={submitButtonDisabled} >{t('Submit')}</Button> |
614
|
|
|
</ButtonGroup> |
615
|
|
|
</FormGroup> |
616
|
|
|
</Col> |
617
|
|
|
<Col xs="auto"> |
618
|
|
|
<FormGroup> |
619
|
|
|
<br></br> |
620
|
|
|
<Spinner color="primary" hidden={spinnerHidden} /> |
621
|
|
|
</FormGroup> |
622
|
|
|
</Col> |
623
|
|
|
<Col xs="auto"> |
624
|
|
|
<br></br> |
625
|
|
|
<ButtonIcon icon="external-link-alt" transform="shrink-3 down-2" color="falcon-default" |
626
|
|
|
hidden={exportButtonHidden} |
627
|
|
|
onClick={handleExport} > |
628
|
|
|
{t('Export')} |
629
|
|
|
</ButtonIcon> |
630
|
|
|
</Col> |
631
|
|
|
</Row> |
632
|
|
|
</Form> |
633
|
|
|
</CardBody> |
634
|
|
|
</Card> |
635
|
|
|
<div className="card-deck"> |
636
|
|
|
{cardSummaryList.map(cardSummaryItem => ( |
637
|
|
|
<CardSummary key={cardSummaryItem['name']} |
638
|
|
|
rate={cardSummaryItem['increment_rate']} |
639
|
|
|
title={t('Reporting Period Savings CATEGORY (Baseline - Actual) UNIT', { 'CATEGORY': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + ')' })} |
640
|
|
|
color="success" |
641
|
|
|
footnote={t('Per Unit Area')} |
642
|
|
|
footvalue={cardSummaryItem['subtotal_per_unit_area']} |
643
|
|
|
footunit={"(" + cardSummaryItem['unit'] + "/M²)"} > |
644
|
|
|
{cardSummaryItem['subtotal'] && <CountUp end={cardSummaryItem['subtotal']} duration={2} prefix="" separator="," decimal="." decimals={2} />} |
645
|
|
|
</CardSummary> |
646
|
|
|
))} |
647
|
|
|
|
648
|
|
|
<CardSummary |
649
|
|
|
rate={totalInTCE['increment_rate'] || ''} |
650
|
|
|
title={t('Reporting Period Savings CATEGORY (Baseline - Actual) UNIT', { 'CATEGORY': t('Ton of Standard Coal'), 'UNIT': '(TCE)' })} |
651
|
|
|
color="warning" |
652
|
|
|
footnote={t('Per Unit Area')} |
653
|
|
|
footvalue={totalInTCE['value_per_unit_area']} |
654
|
|
|
footunit="(TCE/M²)"> |
655
|
|
|
{totalInTCE['value'] && <CountUp end={totalInTCE['value']} duration={2} prefix="" separator="," decimal="." decimals={2} />} |
656
|
|
|
</CardSummary> |
657
|
|
|
<CardSummary |
658
|
|
|
rate={totalInTCO2E['increment_rate'] || ''} |
659
|
|
|
title={t('Reporting Period Decreased CATEGORY (Baseline - Actual) UNIT', { 'CATEGORY': t('Ton of Carbon Dioxide Emissions'), 'UNIT': '(TCO2E)' })} |
660
|
|
|
color="warning" |
661
|
|
|
footnote={t('Per Unit Area')} |
662
|
|
|
footvalue={totalInTCO2E['value_per_unit_area']} |
663
|
|
|
footunit="(TCO2E/M²)"> |
664
|
|
|
{totalInTCO2E['value'] && <CountUp end={totalInTCO2E['value']} duration={2} prefix="" separator="," decimal="." decimals={2} />} |
665
|
|
|
</CardSummary> |
666
|
|
|
</div> |
667
|
|
|
<Row noGutters> |
668
|
|
|
<Col className="mb-3 pr-lg-2 mb-3"> |
669
|
|
|
<SharePie data={TCEShareData} title={t('Ton of Standard Coal by Energy Category')} /> |
670
|
|
|
</Col> |
671
|
|
|
<Col className="mb-3 pr-lg-2 mb-3"> |
672
|
|
|
<SharePie data={TCO2EShareData} title={t('Ton of Carbon Dioxide Emissions by Energy Category')} /> |
673
|
|
|
</Col> |
674
|
|
|
</Row> |
675
|
|
|
<LineChart reportingTitle={t('Reporting Period Savings CATEGORY VALUE UNIT', { 'CATEGORY': null, 'VALUE': null, 'UNIT': null })} |
676
|
|
|
baseTitle='' |
677
|
|
|
labels={storeLineChartLabels} |
678
|
|
|
data={storeLineChartData} |
679
|
|
|
options={storeLineChartOptions}> |
680
|
|
|
</LineChart> |
681
|
|
|
|
682
|
|
|
<LineChart reportingTitle={t('Related Parameters')} |
683
|
|
|
baseTitle='' |
684
|
|
|
labels={parameterLineChartLabels} |
685
|
|
|
data={parameterLineChartData} |
686
|
|
|
options={parameterLineChartOptions}> |
687
|
|
|
</LineChart> |
688
|
|
|
<br /> |
689
|
|
|
<DetailedDataTable data={detailedDataTableData} title={t('Detailed Data')} columns={detailedDataTableColumns} pagesize={50} > |
690
|
|
|
</DetailedDataTable> |
691
|
|
|
|
692
|
|
|
</Fragment> |
693
|
|
|
); |
694
|
|
|
}; |
695
|
|
|
|
696
|
|
|
export default withTranslation()(withRedirect(StoreSaving)); |
697
|
|
|
|