Passed
Push — master ( 3cf56c...4a4ccf )
by Guangyu
04:43 queued 10s
created

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

Complexity

Total Complexity 25
Complexity/F 0

Size

Lines of Code 660
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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