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

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

Complexity

Total Complexity 26
Complexity/F 0

Size

Lines of Code 699
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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