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