Passed
Push — master ( 6dae1b...ad9069 )
by Guangyu
04:19 queued 11s
created

src/components/MyEMS/Shopfloor/ShopfloorCost.js   A

Complexity

Total Complexity 23
Complexity/F 0

Size

Lines of Code 679
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 23
eloc 602
mnd 23
bc 23
fnc 0
dl 0
loc 679
rs 9.998
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 { toast } from 'react-toastify';
29
import { APIBaseURL } from '../../../config';
30
import { periodTypeOptions } from '../common/PeriodTypeOptions';
31
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions';
32
33
34
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
35
36
const ShopfloorCost = ({ 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 [shopfloorList, setShopfloorList] = useState([]);
61
  const [selectedShopfloor, setSelectedShopfloor] = 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 [costShareData, setCostShareData] = useState([]);
74
  const [TCEShareData, setTCEShareData] = useState([]);
75
  const [CO2ShareData, setCO2ShareData] = useState([]);
76
77
  const [shopfloorLineChartLabels, setShopfloorLineChartLabels] = useState([]);
78
  const [shopfloorLineChartData, setShopfloorLineChartData] = useState({});
79
  const [shopfloorLineChartOptions, setShopfloorLineChartOptions] = 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 Shopfloors by root Space ID
114
        let isResponseOK = false;
115
        fetch(APIBaseURL + '/spaces/' + [json[0]].map(o => o.value) + '/shopfloors', {
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
            setShopfloorList(json[0]);
134
            if (json[0].length > 0) {
135
              setSelectedShopfloor(json[0][0].value);
136
              setIsDisabled(false);
137
            } else {
138
              setSelectedShopfloor(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 Shopfloors 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] + '/shopfloors', {
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
        setShopfloorList(json[0]);
183
        if (json[0].length > 0) {
184
          setSelectedShopfloor(json[0][0].value);
185
          setIsDisabled(false);
186
        } else {
187
          setSelectedShopfloor(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(selectedShopfloor);
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/shopfloorcost?' +
282
      'shopfloorid=' + selectedShopfloor +
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
        setCostShareData([
306
          { id: 1, value: 5890863, name: '电', color: '#2c7be5' },
307
          { id: 2, value: 29878, name: '自来水', color: '#27bcfd' },
308
          { id: 3, value: 9887, name: '天然气', color: '#d8e2ef' }
309
        ]);
310
        
311
        setTCEShareData([
312
          { id: 1, value: 5890863 / 8135.56, name: '电', color: '#2c7be5' },
313
          { id: 2, value: 29878 / 1000, name: '自来水', color: '#27bcfd' },
314
          { id: 3, value: 9887 / 751.8, name: '天然气', color: '#d8e2ef' }
315
        ]);
316
317
        setCO2ShareData([
318
          { id: 1, value: (5890863 / 8135.56) * 0.67, name: '电', color: '#2c7be5' },
319
          { id: 2, value: (29878 / 1000) * 0.67, name: '自来水', color: '#27bcfd' },
320
          { id: 3, value: (9887 / 751.8) * 0.67, name: '天然气', color: '#d8e2ef' }
321
        ]);
322
323
        setShopfloorLineChartLabels({
324
          a0: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'],
325
          a1: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'],
326
          a2: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'],
327
          a3: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'],
328
        });
329
330
        setShopfloorLineChartData({
331
          a0: [4, 1, 6, 2, 7, 12, 4, 6, 5, 4, 5, 10],
332
          a1: [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8],
333
          a2: [1, 0, 2, 1, 2, 1, 1, 0, 0, 1, 0, 2],
334
          a3: [1, 0, 2, 1, 2, 1, 1, 0, 0, 1, 0, 2]
335
        });
336
337
        setShopfloorLineChartOptions([
338
          { value: 'a0', label: '电' },
339
          { value: 'a1', label: '自来水' },
340
          { value: 'a2', label: '天然气' },
341
          { value: 'a3', label: '二氧化碳排放' }
342
        ]);
343
344
        setParameterLineChartLabels({
345
          a0: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'],
346
          a1: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'],
347
          a2: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'],
348
          a3: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'],
349
        });
350
351
        setParameterLineChartData({
352
          a0: [40, 31, 36, 32, 27, 32, 34, 26, 25, 24, 25, 30],
353
          a1: [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8],
354
          a2: [1, 0, 2, 1, 2, 1, 1, 0, 0, 1, 0, 2],
355
          a3: [1, 0, 2, 1, 2, 1, 1, 0, 0, 1, 0, 2],
356
          a4: [1, 0, 2, 1, 2, 1, 1, 0, 0, 1, 0, 2]
357
        });
358
359
        setParameterLineChartOptions([
360
          { value: 'a0', label: '室外温度' },
361
          { value: 'a1', label: '相对湿度' },
362
          { value: 'a2', label: '电费率' },
363
          { value: 'a3', label: '自来水费率' },
364
          { value: 'a4', label: '天然气费率' }
365
        ]);
366
367
        setDetailedDataTableData([
368
          {
369
            id: 1,
370
            startdatetime: '2020-07-01',
371
            a0: '9872',
372
            a1: '3457',
373
            a2: '567',
374
            a3: '567',
375
          },
376
          {
377
            id: 2,
378
            startdatetime: '2020-07-02',
379
            a0: '9872',
380
            a1: '3457',
381
            a2: '567',
382
            a3: '567',
383
          },
384
          {
385
            id: 3,
386
            startdatetime: '2020-07-03',
387
            a0: '9872',
388
            a1: '3457',
389
            a2: '567',
390
            a3: '567',
391
          },
392
          {
393
            id: 4,
394
            startdatetime: '2020-07-04',
395
            a0: '9872',
396
            a1: '3457',
397
            a2: '567',
398
            a3: '567',
399
          },
400
          {
401
            id: 5,
402
            startdatetime: '2020-07-05',
403
            a0: '9872',
404
            a1: '3457',
405
            a2: '567',
406
            a3: '567',
407
          },
408
          {
409
            id: 6,
410
            startdatetime: '2020-07-06',
411
            a0: '9872',
412
            a1: '3457',
413
            a2: '567',
414
            a3: '567',
415
          },
416
          {
417
            id: 7,
418
            startdatetime: '2020-07-07',
419
            a0: '9872',
420
            a1: '3457',
421
            a2: '567',
422
            a3: '567',
423
          },
424
          {
425
            id: 8,
426
            startdatetime: '2020-07-08',
427
            a0: '9872',
428
            a1: '3457',
429
            a2: '567',
430
            a3: '567',
431
          },
432
          {
433
            id: 9,
434
            startdatetime: '2020-07-09',
435
            a0: '9872',
436
            a1: '3457',
437
            a2: '567',
438
            a3: '567',
439
          },
440
          {
441
            id: 10,
442
            startdatetime: '2020-07-10',
443
            a0: '9872',
444
            a1: '3457',
445
            a2: '567',
446
            a3: '567',
447
          },
448
          {
449
            id: 11,
450
            startdatetime: t('Total'),
451
            a0: '98720',
452
            a1: '34570',
453
            a2: '5670',
454
            a3: '5670',
455
          }
456
        ]);
457
458
        setDetailedDataTableColumns([
459
          {
460
            dataField: 'startdatetime',
461
            text: t('Datetime'),
462
            sort: true
463
          }, {
464
            dataField: 'a0',
465
            text: '电 (RMB)',
466
            sort: true
467
          }, {
468
            dataField: 'a1',
469
            text: '自来水 (RMB)',
470
            sort: true
471
          }, {
472
            dataField: 'a2',
473
            text: '天然气 (RMB)',
474
            sort: true
475
          }, {
476
            dataField: 'a3',
477
            text: '二氧化碳排放 (T)',
478
            sort: true
479
          }
480
        ]);
481
      } else {
482
        toast.error(json.description)
483
      }
484
    }).catch(err => {
485
      console.log(err);
486
    });
487
  };
488
489
  return (
490
    <Fragment>
491
      <div>
492
        <Breadcrumb>
493
          <BreadcrumbItem>{t('Shopfloor Data')}</BreadcrumbItem><BreadcrumbItem active>{t('Cost')}</BreadcrumbItem>
494
        </Breadcrumb>
495
      </div>
496
      <Card className="bg-light mb-3">
497
        <CardBody className="p-3">
498
          <Form onSubmit={handleSubmit}>
499
            <Row form>
500
              <Col xs="auto">
501
                <FormGroup className="form-group">
502
                  <Label className={labelClasses} for="space">
503
                    {t('Space')}
504
                  </Label>
505
                  <br />
506
                  <Cascader options={cascaderOptions}
507
                    onChange={onSpaceCascaderChange}
508
                    changeOnSelect
509
                    expandTrigger="hover">
510
                    <Input value={selectedSpaceName || ''} readOnly />
511
                  </Cascader>
512
                </FormGroup>
513
              </Col>
514
              <Col xs="auto">
515
                <FormGroup>
516
                  <Label className={labelClasses} for="shopfloorSelect">
517
                    {t('Shopfloor')}
518
                  </Label>
519
                  <CustomInput type="select" id="shopfloorSelect" name="shopfloorSelect" onChange={({ target }) => setSelectedShopfloor(target.value)}
520
                  >
521
                    {shopfloorList.map((shopfloor, index) => (
522
                      <option value={shopfloor.value} key={shopfloor.value}>
523
                        {shopfloor.label}
524
                      </option>
525
                    ))}
526
                  </CustomInput>
527
                </FormGroup>
528
              </Col>
529
              <Col xs="auto">
530
                <FormGroup>
531
                  <Label className={labelClasses} for="comparisonType">
532
                    {t('Comparison Types')}
533
                  </Label>
534
                  <CustomInput type="select" id="comparisonType" name="comparisonType"
535
                    defaultValue="month-on-month"
536
                    onChange={onComparisonTypeChange}
537
                  >
538
                    {comparisonTypeOptions.map((comparisonType, index) => (
539
                      <option value={comparisonType.value} key={comparisonType.value} >
540
                        {t(comparisonType.label)}
541
                      </option>
542
                    ))}
543
                  </CustomInput>
544
                </FormGroup>
545
              </Col>
546
              <Col xs="auto">
547
                <FormGroup>
548
                  <Label className={labelClasses} for="periodType">
549
                    {t('Period Types')}
550
                  </Label>
551
                  <CustomInput type="select" id="periodType" name="periodType" defaultValue="daily" onChange={({ target }) => setPeriodType(target.value)}
552
                  >
553
                    {periodTypeOptions.map((periodType, index) => (
554
                      <option value={periodType.value} key={periodType.value} >
555
                        {t(periodType.label)}
556
                      </option>
557
                    ))}
558
                  </CustomInput>
559
                </FormGroup>
560
              </Col>
561
              <Col xs="auto">
562
                <FormGroup className="form-group">
563
                  <Label className={labelClasses} for="basePeriodBeginsDatetime">
564
                    {t('Base Period Begins')}{t('(Optional)')}
565
                  </Label>
566
                  <Datetime id='basePeriodBeginsDatetime'
567
                    value={basePeriodBeginsDatetime}
568
                    inputProps={{ disabled: basePeriodBeginsDatetimeDisabled }}
569
                    onChange={onBasePeriodBeginsDatetimeChange}
570
                    isValidDate={getValidBasePeriodBeginsDatetimes}
571
                    closeOnSelect={true} />
572
                </FormGroup>
573
              </Col>
574
              <Col xs="auto">
575
                <FormGroup className="form-group">
576
                  <Label className={labelClasses} for="basePeriodEndsDatetime">
577
                    {t('Base Period Ends')}{t('(Optional)')}
578
                  </Label>
579
                  <Datetime id='basePeriodEndsDatetime'
580
                    value={basePeriodEndsDatetime}
581
                    inputProps={{ disabled: basePeriodEndsDatetimeDisabled }}
582
                    onChange={onBasePeriodEndsDatetimeChange}
583
                    isValidDate={getValidBasePeriodEndsDatetimes}
584
                    closeOnSelect={true} />
585
                </FormGroup>
586
              </Col>
587
              <Col xs="auto">
588
                <FormGroup className="form-group">
589
                  <Label className={labelClasses} for="reportingPeriodBeginsDatetime">
590
                    {t('Reporting Period Begins')}
591
                  </Label>
592
                  <Datetime id='reportingPeriodBeginsDatetime'
593
                    value={reportingPeriodBeginsDatetime}
594
                    onChange={onReportingPeriodBeginsDatetimeChange}
595
                    isValidDate={getValidReportingPeriodBeginsDatetimes}
596
                    closeOnSelect={true} />
597
                </FormGroup>
598
              </Col>
599
              <Col xs="auto">
600
                <FormGroup className="form-group">
601
                  <Label className={labelClasses} for="reportingPeriodEndsDatetime">
602
                    {t('Reporting Period Ends')}
603
                  </Label>
604
                  <Datetime id='reportingPeriodEndsDatetime'
605
                    value={reportingPeriodEndsDatetime}
606
                    onChange={onReportingPeriodEndsDatetimeChange}
607
                    isValidDate={getValidReportingPeriodEndsDatetimes}
608
                    closeOnSelect={true} />
609
                </FormGroup>
610
              </Col>
611
              <Col xs="auto">
612
                <FormGroup>
613
                  <br></br>
614
                  <ButtonGroup id="submit">
615
                    <Button color="success" disabled={isDisabled} >{t('Submit')}</Button>
616
                  </ButtonGroup>
617
                </FormGroup>
618
              </Col>
619
            </Row>
620
          </Form>
621
        </CardBody>
622
      </Card>
623
      <div className="card-deck">
624
        <CardSummary rate="-0.23%" title={t('Reporting Period Costs CATEGORY UNIT', { 'CATEGORY': '电', 'UNIT': '(RMB)' })}
625
          color="success" footnote={t('Per Unit Production')} footvalue={5890863 / 1000} footunit="(RMB/PC)" >
626
          <CountUp end={5890863} duration={2} prefix="" separator="," decimals={2} decimal="." />
627
        </CardSummary>
628
        <CardSummary rate="0.0%" title={t('Reporting Period Costs CATEGORY UNIT', { 'CATEGORY': '自来水', 'UNIT': '(RMB)' })}
629
          color="info" footnote={t('Per Unit Production')} footvalue={29878 / 1000} footunit="(RMB/PC)">
630
          <CountUp end={29878} duration={2} prefix="" separator="," decimals={2} decimal="." />
631
        </CardSummary>
632
        <CardSummary rate="0.0%" title={t('Reporting Period Costs CATEGORY UNIT', { 'CATEGORY': '天然气', 'UNIT': '(RMB)' })}
633
          color="info" footnote={t('Per Unit Production')} footvalue={9887 / 1000} footunit="(RMB/PC)">
634
          <CountUp end={9887} duration={2} prefix="" separator="," decimals={2} decimal="." />
635
        </CardSummary>
636
        <CardSummary rate="+9.54%" title={t('Reporting Period Consumption CATEGORY UNIT', { 'CATEGORY': '吨标准煤', 'UNIT': '(TCE)' })}
637
          color="warning" footnote={t('Per Unit Production')} footvalue={(5890863 / 8135.56 + 9887 / 751.8) / 1000} footunit="(TCE/PC)">
638
          <CountUp end={5890863 / 8135.56 + 9887 / 751.8} duration={2} prefix="" separator="," decimal="." decimals={2} />
639
        </CardSummary>
640
        <CardSummary rate="+9.54%" title={t('Reporting Period Consumption CATEGORY UNIT', { 'CATEGORY': '二氧化碳排放', 'UNIT': '(T)' })}
641
          color="warning" footnote={t('Per Unit Production')} footvalue={((5890863 / 8135.56 + 9887 / 751.8) * 0.67) / 1000} footunit="(T/PC)">
642
          <CountUp end={(5890863 / 8135.56 + 9887 / 751.8) * 0.67} duration={2} prefix="" separator="," decimal="." decimals={2} />
643
        </CardSummary>
644
      </div>
645
      <Row noGutters>
646
        <Col className="mb-3 pr-lg-2 mb-3">
647
          <SharePie data={costShareData} title={t('Costs by Energy Category')} />
648
        </Col>
649
        <Col className="mb-3 pr-lg-2 mb-3">
650
          <SharePie data={TCEShareData} title={t('Ton of Standard Coal by Energy Category')} />
651
        </Col>
652
        <Col className="mb-3 pr-lg-2 mb-3">
653
          <SharePie data={CO2ShareData} title={t('Carbon Dioxide Emissions by Energy Category')} />
654
        </Col>
655
      </Row>
656
      <LineChart reportingTitle={t('Reporting Period Costs CATEGORY VALUE UNIT', { 'CATEGORY': '电', 'VALUE': 764.39, 'UNIT': '(RMB)' })}
657
        baseTitle={t('Base Period Costs CATEGORY VALUE UNIT', { 'CATEGORY': '电', 'VALUE': 684.87, 'UNIT': '(RMB)' })}
658
        labels={shopfloorLineChartLabels}
659
        data={shopfloorLineChartData}
660
        options={shopfloorLineChartOptions}>
661
      </LineChart>
662
663
      <LineChart reportingTitle={t('Related Parameters')}
664
        baseTitle=''
665
        labels={parameterLineChartLabels}
666
        data={parameterLineChartData}
667
        options={parameterLineChartOptions}>
668
      </LineChart>
669
670
      <br />
671
      <DetailedDataTable data={detailedDataTableData} title={t('Detailed Data')} columns={detailedDataTableColumns} pagesize={31} >
672
      </DetailedDataTable>
673
674
    </Fragment>
675
  );
676
};
677
678
export default withTranslation()(withRedirect(ShopfloorCost));
679