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