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

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

Complexity

Total Complexity 24
Complexity/F 0

Size

Lines of Code 597
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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