Passed
Push — master ( 6a22d7...683105 )
by Guangyu
05:11 queued 12s
created

src/components/MyEMS/Tenant/TenantSaving.js   A

Complexity

Total Complexity 24
Complexity/F 0

Size

Lines of Code 637
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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