ExceutiveScoreboard.js 15.7 KB
Newer Older
1 2
import React, { Component } from 'react'
import ReactSpeedometer from "react-d3-speedometer"
d.arizona's avatar
d.arizona committed
3
import { GridList, Paper, Typography, GridListTile } from '@material-ui/core'
4
import Images from '../../assets/Images'
Deni Rinaldi's avatar
Deni Rinaldi committed
5
import LineChart from 'react-linechart';
d.arizona's avatar
d.arizona committed
6 7 8
import { titleCase } from '../../library/Utils';
import NumberFormat from 'react-number-format';
import { tr } from 'date-fns/locale';
9 10 11 12 13 14 15 16 17 18 19 20

export default class ExceutiveScoreboard extends Component {
    constructor(props) {
        super(props)
        this.state = {
            listDummy: [
                { judul: "Overall", kpi: 0, rank: 'BS', value: 3.67, status: 'up' },
                { judul: "Financial", kpi: 5, rank: 'BS', value: 3.67, status: 'up' },
                { judul: "Customer Perspective", kpi: 2, rank: 'B', value: 3.05, status: 'down' },
                { judul: "Internal Perspective", kpi: 5, rank: 'C', value: 2.61, status: 'down' },
                { judul: "Financial", kpi: 5, rank: 'B+', value: 3.52, status: 'up' },
            ],
d.arizona's avatar
d.arizona committed
21 22 23
            arraySpeedo: [],
            data: [],
            newData: [],
d.arizona's avatar
d.arizona committed
24
            dataPayload: this.props.dataPayload,
d.arizona's avatar
d.arizona committed
25 26
            selectIndex: null,
            loading: false
27 28
        }
    }
d.arizona's avatar
d.arizona committed
29 30

    componentDidMount() {
d.arizona's avatar
d.arizona committed
31
        // console.log()
d.arizona's avatar
d.arizona committed
32 33
        console.log(this.state.dataPayload)
        let arrOverAll = []
d.arizona's avatar
d.arizona committed
34
        let newData = []
d.arizona's avatar
d.arizona committed
35
        let totalOverAll = 0
d.arizona's avatar
d.arizona committed
36 37
        this.setState({loading: true})
        this.olahDataChart()
d.arizona's avatar
d.arizona committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
        if (this.state.data.length > 0) {
            this.state.data.map((item,index) => {
                if(item.parent == null || item.parent == 'null') {
                    arrOverAll.push(item)
                } else {
                    totalOverAll += 
                        this.state.dataPayload.month.month_id == 1? Number(item.month1 == null? 0 : item.month1) :
                        this.state.dataPayload.month.month_id == 2? Number(item.month2 == null? 0 : item.month2) :
                        this.state.dataPayload.month.month_id == 3? Number(item.month3 == null? 0 : item.month3) :
                        this.state.dataPayload.month.month_id == 4? Number(item.month4 == null? 0 : item.month4) :
                        this.state.dataPayload.month.month_id == 5? Number(item.month5 == null? 0 : item.month5) :
                        this.state.dataPayload.month.month_id == 6? Number(item.month6 == null? 0 : item.month6) :
                        this.state.dataPayload.month.month_id == 7? Number(item.month7 == null? 0 : item.month7) :
                        this.state.dataPayload.month.month_id == 8? Number(item.month8 == null? 0 : item.month8) :
                        this.state.dataPayload.month.month_id == 9? Number(item.month9 == null? 0 : item.month9) :
                        this.state.dataPayload.month.month_id == 10? Number(item.month10 == null? 0 : item.month10) :
                        this.state.dataPayload.month.month_id == 11? Number(item.month11 == null? 0 : item.month11) : 
                        Number(item.month12 == null? 0 : item.month12) 
                }
            })
            
            let indexFinancial = arrOverAll.findIndex((val) => String(val.item_name).toLocaleLowerCase().includes('financial'))
            let indexCust = arrOverAll.findIndex((val) => String(val.item_name).toLocaleLowerCase().includes('customer'))
            let indexInternal = arrOverAll.findIndex((val) => String(val.item_name).toLocaleLowerCase().includes('internal'))
            let indexLearn = arrOverAll.findIndex((val) => String(val.item_name).toLocaleLowerCase().includes('learn'))
            let arrFinancial = []
            let arrCust = []
            let arrInternal = []
            let arrLearn = []

            console.log(indexFinancial)
            console.log(indexCust)
            console.log(indexInternal)
            console.log(indexLearn)

            if (indexFinancial != -1) {
                arrFinancial = this.state.data.filter((val) => val.parent == arrOverAll[indexFinancial].item_report_id)
            }

            if (indexCust != -1) {
                arrCust = this.state.data.filter((val) => val.parent == arrOverAll[indexCust].item_report_id)
            }

            if (indexInternal != -1) {
                arrInternal = this.state.data.filter((val) => val.parent == arrOverAll[indexInternal].item_report_id)
            }

            if (indexLearn != -1) {
                arrLearn = this.state.data.filter((val) => val.parent == arrOverAll[indexLearn].item_report_id)
            }
            
            console.log(totalOverAll)
            console.log(arrOverAll)
            console.log(arrFinancial)
            console.log(arrCust)
            console.log(arrInternal)
            console.log(arrLearn)
        }
        
    }

d.arizona's avatar
d.arizona committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
    olahDataChart() {
        let arrayChart = []
        this.state.data.map((item,index) => {
            let arrayChildChart = []
            // if (item.parent != null) {
                item.month.map((items,indexs) => {
                    arrayChildChart.push({
                        x: indexs,
                        y: items.value == null? indexs : items.value
                    })
                })
                arrayChart.push({
                    ...item, 
                    arrayChildChart: [{
                        color: "steelblue",
                        points: arrayChildChart
                    }]
                })
            // } else {
            //     arrayChart.push(item)
            // }
        })
        console.log(arrayChart)
        let arrayDataParent = arrayChart.filter((val) => val.parent == null || val.parent == 'null')
        let arrayDataChild = arrayChart.filter((val) => val.parent != null || val.parent != 'null')
        let arraySpeedo = []
        this.setState({newData: arrayChart}, () => {
            arrayDataParent.map((item,index) => {
                // console.log(arrayDataChild.filter((val) => val.parent == item.item_report_id))
                if (index == 0) {
                    arraySpeedo.push({
                        company_id: item.company_id,
                        decprev: item.decprev,
                        id: 99,
                        item_name: "Overall",
                        item_report_id: 9999,
                        arrayChildChart: [],
                        child: arrayDataChild,
                        month: item.month
                    })
                }
                arraySpeedo.push({
                    ...item, child: arrayDataChild.filter((val) => val.parent == item.item_report_id)
                })
            })

            console.log(arraySpeedo)
            arraySpeedo.map((item,index) => {
                if (item.id != 99) {
                    let indexID = arraySpeedo.findIndex((val) => item.item_report_id == val.item_report_id)
                    let indexMonthIDParent = item.month.findIndex((val) => val.name == `month${this.state.dataPayload.month.month_id}`)
                    let total = 0
                    item.child.map((items,indexs) => {
                        let specMonth = items.month.filter((val) => val.name == `month${this.state.dataPayload.month.month_id}`)
                        total += Number(specMonth[0].value)
                    })
                    arraySpeedo[indexID].month[indexMonthIDParent].value = total
                }
            })
            
            
            let totalOverAll = 0
            
            // arraySpeedo.map((item,index) => {
            //     let indexMonthIDParent = item.month.findIndex((val) => val.name == `month${this.state.dataPayload.month.month_id}`)
            //     if (item.id != 99) {
            //         totalOverAll += item.month[indexMonthIDParent].value
            //     }
            // })

            // let indexOverall = arraySpeedo.findIndex((val) => val.id == 99)
            // let indexMonthIDParent = arraySpeedo[indexOverall].month.findIndex((val) => val.name == `month${this.state.dataPayload.month.month_id}`)
            // arraySpeedo[indexOverall].month[indexMonthIDParent].value = totalOverAll

            console.log('skl', totalOverAll)
            console.log('part2', arraySpeedo)

            this.setState({arraySpeedo, loading: false})
            // arraySpeedo.map((item,index) => {
            //     if (index == 0) {
                    
            //         arraySpeedoNew.push(item)
            //     } else {
            //         arraySpeedoNew.push(item)
            //     }
            // })
        })
    }

    handleValueChild(item) {
        let data = this.state.newData.filter((val) => val.parent != null)
        let indexID = data.findIndex((val) => val.item_name == item.item_name)
        let indexMonthID = data[indexID].month.findIndex((val) => val.name == `month${this.state.dataPayload.month.month_id}`)
        return data[indexID].month[indexMonthID].value == null? 0 : data[indexID].month[indexMonthID].value
    }
    
    handleValueSpeedo(item) {
        let indexMonthID = item.month.findIndex((val) => val.name == `month${this.state.dataPayload.month.month_id}`)
        return item.month[indexMonthID].value
    }
d.arizona's avatar
d.arizona committed
199

200 201
    render() {
        let { selectIndex } = this.state
d.arizona's avatar
d.arizona committed
202
        let yuk = [1,2,3]
Deni Rinaldi's avatar
Deni Rinaldi committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216
        const data = [
            {
                color: "steelblue",
                points: [
                    { x: 1, y: 2 },
                    { x: 2, y: 1 },
                    { x: 3, y: 3 },
                    { x: 4, y: 2 },
                    { x: 5, y: 4 },
                    { x: 6, y: 5 },
                    { x: 7, y: 4 },
                ]
            }
        ];
217 218 219
        return (
            <div style={{ padding: 20 }}>
                <div style={{ display: 'flex', width: '100%', justifyContent: 'space-between', flexFlow: 'wrap' }}>
d.arizona's avatar
d.arizona committed
220
                    {/* {!this.state.loading && this.state.arraySpeedo.map((item, index) => {
221
                        return (
d.arizona's avatar
d.arizona committed
222 223
                            <div style={{ padding: 10, backgroundColor: this.state.selectIndex === index ? '#6885a6' : '#fff', borderRadius: 6, paddingBottom: 20, margin: 10, boxShadow: '0 1px 4px 0 rgba(0, 0, 0, 0.25)' }} onClick={() => this.setState({ selectIndex: index }, () => console.log(item))}>
                                <span style={{ fontSize: '17px', color: this.state.selectIndex === index ? '#fff' : '#7e8085', maxWidth: 100}}>{item.item_name}</span>
224 225 226 227
                                <div style={{ backgroundColor: 'transparent', display: 'flex', marginTop: index === 0 ? 54 : 30, placeContent: 'center' }}>
                                    <div>
                                        {index != 0 ?
                                            <div>
d.arizona's avatar
d.arizona committed
228
                                                <span style={{ textAlign: 'center', fontSize: '24px', color: selectIndex === index ? "#fff" : '#4b4b4b' }}>{item.child.length}</span>
229 230 231 232 233 234 235 236 237 238 239 240 241
                                                <span style={{ textAlign: 'center', fontSize: '11px', color: selectIndex === index ? "#fff" : '#4b4b4b' }}>KPIs</span> </div> : null}
                                        <div style={{ backgroundColor: index === 2 ? "#7cd532" : index === 3 ? "#fcff00" : index === 4 ? "#00b440" : "#00b1f7", textAlign: 'center', width: 40, height: 21 }}>
                                            <Typography style={{ textAlign: 'center' }}>{item.rank}</Typography>
                                        </div>
                                    </div>
                                </div>
                                <ReactSpeedometer
                                    maxSegmentLabels={0}
                                    segmentColors={[
                                        index === 2 ? "#7cd532" : index === 3 ? "#fcff00" : index === 4 ? "#00b440" : "#00b1f7",
                                        "#d8d8d8"
                                    ]}
                                    needleColor={this.state.selectIndex === index ? "#fff" : '#4b4b4b'}
d.arizona's avatar
d.arizona committed
242
                                    value={this.handleValueSpeedo(item)}
243
                                    maxValue={5}
d.arizona's avatar
d.arizona committed
244
                                    customSegmentStops={[0, this.handleValueSpeedo(item), 5]}
245 246 247 248 249 250 251
                                    width={200}
                                    height={140}
                                    ringWidth={25}
                                    textColor={selectIndex === index ? "#fff" : '#4b4b4b'}
                                />
                                <div style={{ backgroundColor: 'transparent', display: 'flex', marginTop: 20, placeContent: 'center' }}>
                                    <div style={{ textAlign: '-webkit-center' }}>
d.arizona's avatar
d.arizona committed
252
                                        {item.id === 99 ?
253 254 255 256 257 258
                                            <img src={Images.up} /> : <img src={Images.down} />}
                                        <Typography style={{ fontSize: 16, color: this.state.selectIndex === index ? '#fff' : '#4b4b4b' }}>vs Last Month</Typography>
                                    </div>
                                </div>
                            </div>
                        )
d.arizona's avatar
d.arizona committed
259
                    })} */}
260
                </div>
d.arizona's avatar
d.arizona committed
261
                <div style={{padding: 10, marginTop: 10,  display: 'flex', width: '100%' }}>
d.arizona's avatar
d.arizona committed
262 263
                    {/* <GridList cellHeight={250} cols={3}>
                        {this.state.newData.filter((val) => val.parent != null).map((tile) => (
d.arizona's avatar
d.arizona committed
264 265 266
                        <GridListTile key={tile} cols={1} style={{}}>
                            <div style={{ maxWidth: 566, height: 233, boxShadow: '0 1px 4px 0 rgba(0, 0, 0, 0.25)', padding: 20, marginLeft: 5, marginTop: 5, marginRight: 5, display: 'inline-grid'}}>
                                <div>
d.arizona's avatar
d.arizona committed
267 268
                                    <span style={{ fontSize: 17 }}>{titleCase(tile.item_name)}</span>
                                    <Typography style={{ fontSize: 24, fontWeight: 'bold' }}><NumberFormat value={this.handleValueChild(tile)} displayType={'text'} thousandSeparator={true} prefix={'Rp. '}/></Typography>
d.arizona's avatar
d.arizona committed
269 270 271 272 273
                                    <Typography style={{ fontSize: 16, fontWeight: 'bold' }}>In IDR mn</Typography>
                                </div>
                                <LineChart
                                    width={400}
                                    height={50}
d.arizona's avatar
d.arizona committed
274
                                    data={tile.arrayChildChart}
d.arizona's avatar
d.arizona committed
275 276 277 278 279 280 281 282 283 284
                                    yMin={0}
                                    yMax={10}
                                    hideXAxis={true}
                                    hideYAxis={true}
                                    hideXLabel={true}
                                    hideYLabel={true}
                                />
                            </div>
                        </GridListTile>
                        ))}
d.arizona's avatar
d.arizona committed
285
                    </GridList> */}
d.arizona's avatar
d.arizona committed
286 287 288
                </div>
                
                {/* <div style={{ width: 566, height: 233, boxShadow: '0 1px 4px 0 rgba(0, 0, 0, 0.25)', padding: 20, justifyContent: 'space-between', display: 'grid', margin: 10 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
                        <div>
                            <span style={{ fontSize: 17 }}>YTD Revenue</span>
                            <Typography style={{ fontSize: 24, fontWeight: 'bold' }}>1,016,489.78</Typography>
                            <Typography style={{ fontSize: 16, fontWeight: 'bold' }}>In IDR mn</Typography>
                        </div>
                        <LineChart
                            width={400}
                            height={50}
                            data={data}
                            yMin={0}
                            yMax={10}
                            hideXAxis={true}
                            hideYAxis={true}
                            hideXLabel={true}
                            hideYLabel={true}
                        />
d.arizona's avatar
d.arizona committed
305 306
                    </div> */}
                </div>
307 308 309
        )
    }
}