Passed
Push — master ( 669be3...4762c7 )
by Guangyu
19:25 queued 10s
created

src/components/MyEMS/CombinedEquipment/CombinedEquipmentEnergyItem.js   A

Complexity

Total Complexity 27
Complexity/F 0

Size

Lines of Code 662
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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