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