Passed
Push — master ( e3086e...7c86e8 )
by Guangyu
04:24
created

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

Complexity

Total Complexity 25
Complexity/F 0

Size

Lines of Code 638
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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