Passed
Push — master ( 9a2876...4f3f28 )
by Guangyu
04:12 queued 14s
created

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

Complexity

Total Complexity 26
Complexity/F 0

Size

Lines of Code 599
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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