Passed
Push — master ( 711ecf...045d72 )
by Guangyu
21:04 queued 20:30
created

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

Complexity

Total Complexity 25
Complexity/F 0

Size

Lines of Code 624
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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