DashboardCAT.js 33.4 KB
Newer Older
1
import React, { Component } from 'react'
syadziy's avatar
syadziy committed
2
import { Typography, TextField, AppBar, Paper, Tabs, Tab, Snackbar, withStyles } from '@material-ui/core'
3
import ExceutiveScoreboard from './ExceutiveScoreboard'
Deni Rinaldi's avatar
Deni Rinaldi committed
4
import StrategiMap from './StrategiMap'
Riri Novita's avatar
Riri Novita committed
5
import KPIs from './KPIs'
d.arizona's avatar
d.arizona committed
6 7 8 9 10 11 12 13 14 15
import api from '../../api'
import { Autocomplete } from '@material-ui/lab'
import { PropagateLoader } from 'react-spinners'
import MuiAlert from '@material-ui/lab/Alert';
import Constant from '../../library/Constant'
import { titleCase } from '../../library/Utils'
import { format } from 'date-fns';

const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
16 17 18 19 20 21 22

export default class DashboardCAT extends Component {
    constructor(props) {
        super(props)
        this.state = {
            periode: '2020',
            perusahaan: 'TAP Group',
d.arizona's avatar
d.arizona committed
23 24 25 26 27 28 29 30
            tab: 0,
            lastPeriod: '',
            listCompany: null,
            company: null,
            listPeriode: null,
            periode: null,
            listMonth: null,
            month: null,
d.arizona's avatar
d.arizona committed
31
            loading: true,
d.arizona's avatar
d.arizona committed
32 33
            dataDashboard: [],
            selectedKPI: [],
d.arizona's avatar
d.arizona committed
34
            listKPI: [],
d.arizona's avatar
d.arizona committed
35
            selectedMonth: [],
d.arizona's avatar
d.arizona committed
36 37 38 39 40
            rawData: null,
            reportIDCAT: null,
            monthlyReportID: null,
            revisionCAT: 0,
            tableCAT: []
d.arizona's avatar
d.arizona committed
41 42 43 44
        }
    }

    componentDidMount() {
d.arizona's avatar
d.arizona committed
45
        console.log(this.props)
d.arizona's avatar
d.arizona committed
46
        // localStorage.removeItem(Constant.DATACAT)
d.arizona's avatar
d.arizona committed
47 48 49
        this.props.selectIndex('CAT Dashboard')
        let dataStorageCAT = localStorage.getItem(Constant.DATACAT)
        if (this.props.location.state !== undefined) {
50 51 52
            if (dataStorageCAT != 'datacat' && dataStorageCAT != null) {
                this.setState({ selectedKPI: JSON.parse(dataStorageCAT).listKPI }, () => {
                    console.log(dataStorageCAT)
d.arizona's avatar
d.arizona committed
53
                    // console.log(this.props.location.state.rawData.companyId)
54
                    console.log(this.state.selectedKPI)
d.arizona's avatar
d.arizona committed
55
                    this.setState({ userType: this.props.location.state.userType, intent: 'Home', rawData: this.props.location.state.rawData }, () => {
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
                        this.getDetailUser()
                    })
                })

            } else {
                this.setState({ userType: this.props.location.state.userType, intent: 'Home', rawData: this.props.location.state.rawData }, () => {
                    this.getDetailUser()
                })
            }

            // console.log(this.state.selectedKPI)
            // console.log(dataStorageCAT)
            // console.log(this.state.company.company_id)
            // this.setState({ userType: this.props.location.state.userType, intent: 'Home', rawData: this.props.location.state.rawData, selectedKPI: this.state.selectedKPI.length == 0? [] : ((dataStorageCAT != 'datacat' && dataStorageCAT != null) ? (dataStorageCAT.companyId == this.state.company.company_id? JSON.parse(dataStorageCAT).listKPI : []) : [])}, () => {
            //     this.getDetailUser()
            // })
d.arizona's avatar
d.arizona committed
72 73 74
        } else {
            this.getDetailUser()
        }
d.arizona's avatar
d.arizona committed
75 76
    }

d.arizona's avatar
d.arizona committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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
    getMonthlyReportID() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
            "months": this.state.month.month_id,
            "is_approver": false
        }
        api.create().getMonthlyReportID(payload).then(response => {
            if (response.data.data) {
                this.setState({ monthlyReportID: response.data.data.monthly_report_id })
            } else {
                this.setState({ monthlyReportID: null })
            }
            this.getReport()
        })
    }

    getReport() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
            "report_type": "Monthly Report",
            "months": this.state.month.month_id,
        }
        api.create().getMonthlyReport(payload).then(response => {
            if (response.data.data) {
                let indexID = response.data.data.findIndex((val) => val.report_name == "CAT")
                this.setState({reportIDCAT: response.data.data[indexID].report_id, revisionCAT: response.data.data[indexID].revision}, () => {
                    console.log(this.state.reportIDCAT, this.state.revisionCAT)
                    this.getItemHierarki()
                })
            } else {
                this.setState({reportIDCAT: null})
            }
            console.log(response)
        })
    }

    getItemHierarki() {
        let payload = {
            "report_id": this.state.reportIDCAT,
            "revision": this.state.revisionCAT,
            "periode": this.state.periode.periode,
            "company_id": this.state.company.company_id,
            "monthly_report_id": this.state.monthlyReportID,
            "months": this.state.month.month_id,
            "get_for": 'view'
        }
        api.create().getHierarkiMontlyReportCAT(payload).then(response => {
            let dataTable = []
            if (response.data.data) {
                let res = response.data.data
                    const handlePushChild = (item, index, length) => {
                        let indexIDzz = dataTable.findIndex((val) => val[1] === item.id)
                        if (indexIDzz === -1) {
                            let parentTrue = item.parent_name == 'INTERNAL BUSINESS PROCESS PERSPECTIVE' || item.parent_name == 'CUSTOMER PERSPECTIVE'
                            let weight = String(item.weight).includes('%')? String(item.weight).substr(0, String(item.weight).length - 1) : String(item.weight)
                            let weightTB = String(item.corporate_annual_target.weight).includes('%')? String(item.corporate_annual_target.weight).substr(0, String(item.corporate_annual_target.weight).length - 1) : String(item.corporate_annual_target.weight)
                            // console.log(weight)
                            dataTable.push([
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
                                // item.corporate_annual_target.weight == "" ? Number(0).toFixed(1) : Number(weight).toFixed(1),
                                parentTrue ? weight : weightTB,
                                parentTrue ? item.corporate_annual_target.uom : item.uom,
                                parentTrue ? item.corporate_annual_target.jenis_kpi == "" ? null : item.corporate_annual_target.jenis_kpi : item.jenis_kpi == "" ? null : item.kpi_type,
                            ])
                        }
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    // console.log(indexs, item.children.length)
                                    handlePushChild(items, indexs, item.children.length)
                                })
                            }
                        }
                    }
                    res.map((item, index) => {
                        dataTable.push([
                            item.type_report_id,
                            item.id,
                            item.parent,
                            item.level,
                            item.description,
                            item.uom,
                            item.kpi_type == "" ? null : item.kpi_type,
                        ])
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items, indexs, item.children.length)
                                })
                            }
                        }
                    })
                this.setState({tableCAT: dataTable}, () => {
                    console.log(this.state.tableCAT)
                })
            } else {
                this.setState({tableCAT: []})
            }
        })
    }

d.arizona's avatar
d.arizona committed
185
    getDetailUser() {
d.arizona's avatar
d.arizona committed
186
        console.log(this.state.rawData)
d.arizona's avatar
d.arizona committed
187 188 189 190 191 192 193 194 195 196
        let userId = localStorage.getItem(Constant.USER)
        api.create().getDetailUser(userId).then((response) => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        this.getRole(response.data.data.role_id)
                        this.setState({ userCompany: response.data.data.company }, () => {
                            this.getCompanyActive()
                        })
                    }
d.arizona's avatar
d.arizona committed
197 198 199 200 201 202 203 204 205 206 207 208
                    else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
d.arizona's avatar
d.arizona committed
209
                }
d.arizona's avatar
d.arizona committed
210 211
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
d.arizona's avatar
d.arizona committed
212
            }
d.arizona's avatar
d.arizona committed
213 214
            //     }
            // }
d.arizona's avatar
d.arizona committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
        })
    }

    getRole(id) {
        api.create().getDetailRole(id).then((response) => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        // this.setState({ tempData: response.data.data, privileges: response.data.data.privileges })
                        // // // console.log(response.data.data)
                        if (String(response.data.data.role_name).toLocaleLowerCase() == 'superadmin') {
                            this.setState({ isAdmin: true })
                        }
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
230
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
            }
        })
    }

    getCompanyActive() {
        api.create().getPerusahaanActive().then((response) => {
            console.log(response);
            if (response.data) {
                if (response.data.status === 'success') {
                    let data = response.data.data
d.arizona's avatar
d.arizona committed
253
                    let comID = this.state.rawData != null ? this.state.rawData.companyId : 0
d.arizona's avatar
d.arizona committed
254
                    // console.log(comID)
d.arizona's avatar
d.arizona committed
255 256 257 258 259
                    let companyData = data.map((item) => {
                        return {
                            company_id: item.company_id,
                            company_name: item.company_name,
                        }
d.arizona's avatar
d.arizona committed
260 261
                    })

d.arizona's avatar
d.arizona committed
262 263 264 265 266 267 268 269 270
                    let arrayBaru = []
                    this.state.userCompany.map((item, index) => {
                        let indexID = companyData.findIndex((val) => val.company_id == item)
                        if (indexID !== -1) {
                            arrayBaru.push(companyData[indexID])
                        }
                    })

                    let defaultProps = {
Deni Rinaldi's avatar
Deni Rinaldi committed
271
                        options: arrayBaru.sort((a, b) => a.company_name.localeCompare(b.company_name)),
d.arizona's avatar
d.arizona committed
272 273 274
                        getOptionLabel: (option) => titleCase(option.company_name),
                    };
                    let index = arrayBaru.findIndex((val) => val.company_id == comID)
275

d.arizona's avatar
d.arizona committed
276
                    this.setState({ listCompany: defaultProps, company: arrayBaru.length < 1 ? companyData[0] : (index == -1 ? arrayBaru[0] : arrayBaru[index]) }, () => {
277
                        let dataStorageCAT = localStorage.getItem(Constant.DATACAT)
d.arizona's avatar
d.arizona committed
278
                        let userID = localStorage.getItem(Constant.USER)
279
                        if (dataStorageCAT != 'datacat' && dataStorageCAT != null) {
d.arizona's avatar
d.arizona committed
280 281 282 283 284 285 286 287 288 289 290
                            let arrayStorage = JSON.parse(dataStorageCAT)
                            let indexListKPI = arrayStorage.findIndex((val) => val.userID == userID)
                            let selectedKPI = []
                            let indexListKPIDetail = -1
                            if (indexListKPI != -1) {
                                indexListKPIDetail = arrayStorage[indexListKPI].listKPI.findIndex((val) => val.companyId == this.state.company.company_id)
                                if (indexListKPIDetail != -1) {
                                    selectedKPI = arrayStorage[indexListKPI].listKPI[indexListKPIDetail].list
                                }
                            }
                            this.setState({ selectedKPI })
291
                        }
d.arizona's avatar
d.arizona committed
292 293 294 295
                        this.getLastPeriod()
                    })
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
296
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listCompany: null, company: null })
            }
        })
    }

    getLastPeriod() {
        console.log(this.state.company)
        api.create().getLastPeriod(this.state.company.company_id).then(response => {
            console.log(response);
            if (response.data.status === "success") {
                this.setState({ lastPeriod: response.data.data.last_periode, latestPeriode: response.data.data.latest_periode }, () => {
                    console.log(this.state.lastPeriod)
                    this.getPeriode()
                })
            }
        })
    }

    getPeriode() {
        api.create().getPeriodeTransaction().then(response => {
            // let dateNow = new Date
            console.log(response)
            // let year = this.state.rawData ? this.state.rawData.periode : format(dateNow, 'yyyy')
            let currentYear = new Date().getFullYear()
            // // // console.log(currentYear)
            if (response.data) {
                if (response.data.status === "success") {
                    let data = []
                    console.log(response.data.data)
                    console.log(this.state.lastPeriod)
d.arizona's avatar
d.arizona committed
335
                    let periodeID = this.state.rawData != null ? this.state.rawData.periode : 0
d.arizona's avatar
d.arizona committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
                    response.data.data.map((item) => {
                        if (this.state.isApprover) {
                            if (item >= 2000 && item <= (Number(currentYear) + 1)) {
                                data.push(item)
                            }
                        } else {
                            if ((Number(item) >= 2000) && (Number(item) == this.state.lastPeriod || Number(item) < this.state.lastPeriod)) {
                                data.push(item)
                            }
                        }
                    })
                    let periodeData = data.map((item) => {
                        return {
                            periode: item,
                        }
                    })
                    let defaultProps = {
d.arizona's avatar
d.arizona committed
353
                        options: periodeData.sort((a, b) => a.periode - b.periode),
d.arizona's avatar
d.arizona committed
354 355 356
                        getOptionLabel: (option) => option.periode,
                    };
                    let periode = (this.state.lastPeriod == "" ? String(Number(currentYear) + 1) : this.state.lastPeriod)
d.arizona's avatar
d.arizona committed
357
                    let index = periodeData.sort((a, b) => a.periode - b.periode).findIndex((val) => periodeID == 0 ? val.periode === periode : val.periode == periodeID)
d.arizona's avatar
d.arizona committed
358 359 360 361 362
                    // // console.log(this.props.location.state.rawData)
                    // console.log(this.state.lastPeriod)
                    console.log(data)
                    console.log(periodeData)
                    console.log(defaultProps)
d.arizona's avatar
d.arizona committed
363
                    console.log(index)
d.arizona's avatar
d.arizona committed
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
                    this.setState({ listPeriode: defaultProps, periode: index === -1 ? periodeData[0] : periodeData[index] }, () => {
                        this.getMonth()
                    })
                }
            }
        })
    }

    getMonth() {
        api.create().getMonthTransaction().then(response => {
            let dateNow = new Date
            let month = format(dateNow, 'MMMM')
            console.log(response);
            if (response.data) {
                if (response.data.status === "success") {
                    console.log(response);
                    let data = response.data.data
d.arizona's avatar
d.arizona committed
381
                    let monthID = this.state.rawData != null ? this.state.rawData.month : 0
d.arizona's avatar
d.arizona committed
382 383 384 385 386 387 388 389 390 391
                    let monthData = data.map((item) => {
                        return {
                            month_id: item.id,
                            month_value: String(item.month_name).substr(0, 3)
                        }
                    })
                    let defaultProps = {
                        options: monthData,
                        getOptionLabel: (option) => option.month_value,
                    };
d.arizona's avatar
d.arizona committed
392
                    let index = data.findIndex((val) => monthID == 0 ? val.month_name == month : val.id == monthID)
d.arizona's avatar
d.arizona committed
393
                    console.log(index);
d.arizona's avatar
d.arizona committed
394 395 396 397 398 399
                    let selectedMonth = []
                    monthData.map((item, indexs) => {
                        if (indexs <= index) {
                            selectedMonth.push(item.month_value)
                        }
                    })
d.arizona's avatar
d.arizona committed
400

d.arizona's avatar
d.arizona committed
401
                    this.setState({ listMonth: defaultProps, month: index == -1 ? monthData[0] : monthData[index], selectedMonth }, () => {
d.arizona's avatar
d.arizona committed
402
                        this.getDasboardCAT()
d.arizona's avatar
d.arizona committed
403
                        // this.getMonthlyReportID()
d.arizona's avatar
d.arizona committed
404 405 406
                    })
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
407
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
            }
        })
    }

    getDasboardCAT() {
d.arizona's avatar
d.arizona committed
422
        this.getMonthlyReportID()
d.arizona's avatar
d.arizona committed
423
        let payload = {
d.arizona's avatar
d.arizona committed
424 425
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
d.arizona's avatar
d.arizona committed
426
            "months": this.state.month.month_id
427
        }
d.arizona's avatar
d.arizona committed
428
        let dataDashboard = []
d.arizona's avatar
d.arizona committed
429 430 431
        api.create().getDashboardCAT(payload).then((res) => {
            if (res.data.status == 'success') {
                console.log(res)
d.arizona's avatar
d.arizona committed
432
                // let resp = res.data.data
d.arizona's avatar
d.arizona committed
433
                this.setState({ dataDashboard: res.data.data }, () => {
d.arizona's avatar
d.arizona committed
434
                    setTimeout(() => {
d.arizona's avatar
d.arizona committed
435
                        this.setState({ loading: false })
d.arizona's avatar
d.arizona committed
436 437
                    }, 400);
                })
d.arizona's avatar
d.arizona committed
438
            }
d.arizona's avatar
d.arizona committed
439 440 441
            // else {
            //     this.setState({loading: false})
            // }
d.arizona's avatar
d.arizona committed
442 443 444 445 446 447
            // conole.log(JSON.stringify(payload))
        })
    }

    closeAlert() {
        this.setState({ alert: false })
448 449 450
    }

    selectTab = (event, newEvent) => {
d.arizona's avatar
d.arizona committed
451
        // console.log(newEvent)
452 453 454
        this.setState({ tab: newEvent })
    }

d.arizona's avatar
d.arizona committed
455
    setSelectedKPI(data) {
d.arizona's avatar
d.arizona committed
456
        this.setState({ selectedKPI: data }, () => {
d.arizona's avatar
d.arizona committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
            let dataStorageCAT = localStorage.getItem(Constant.DATACAT)
            let userID = localStorage.getItem(Constant.USER)
            if (dataStorageCAT != 'datacat' && dataStorageCAT != null) {
                let arrayStorage = JSON.parse(dataStorageCAT)
                if (arrayStorage.length > 0) {
                    let indexID = arrayStorage.findIndex((val) => val.userID == userID)
                    if (indexID == -1) {
                        let listKPI = []
                        listKPI.push({
                            list: this.state.selectedKPI,
                            companyId: this.state.company.company_id
                        })
                        let payloadData = {
                            userID,
                            listKPI
                        }
                        arrayStorage.push(payloadData)
                        console.log('1')
                        console.log(arrayStorage)
                    } else {
                        let listKPI = arrayStorage[indexID].listKPI
                        let indexComp = listKPI.findIndex((val) => val.companyId == this.state.company.company_id)
                        if (indexComp == -1) {
                            listKPI.push({
                                list: this.state.selectedKPI,
                                companyId: this.state.company.company_id
                            })
                            // arrayStorage.push(payloadData)
                            arrayStorage[indexID].listKPI = listKPI
                            console.log('2')
                            console.log(arrayStorage)
                        } else {
                            arrayStorage[indexID].listKPI[indexComp].list = this.state.selectedKPI
                            console.log('3')
                            console.log(arrayStorage)
                        }


                    }
                    localStorage.setItem(Constant.DATACAT, JSON.stringify(arrayStorage))
                    console.log(localStorage.getItem(Constant.DATACAT))
                }
            } else {
                let arrayStorage = []
                let listKPI = []
                listKPI.push({
                    list: this.state.selectedKPI,
                    companyId: this.state.company.company_id
                })
                let payloadData = {
                    userID: localStorage.getItem(Constant.USER),
                    listKPI
                }
                arrayStorage.push(payloadData)
                localStorage.setItem(Constant.DATACAT, JSON.stringify(arrayStorage))
                console.log('4')
                console.log(arrayStorage)
d.arizona's avatar
d.arizona committed
514 515
            }
        })
d.arizona's avatar
d.arizona committed
516 517
    }

518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
    render() {
        const perusahaan = [
            { value: 'TAP Group', label: 'TAP Group' },
            { value: '2019', label: '2019' },
            { value: '2018', label: '2018' },
            { value: '2017', label: '2017' },
            { value: '2016', label: '2016' },
        ]
        const periode = [
            { value: '2020', label: '2020' },
            { value: '2019', label: '2019' },
            { value: '2018', label: '2018' },
            { value: '2017', label: '2017' },
            { value: '2016', label: '2016' },
        ]
d.arizona's avatar
d.arizona committed
533 534 535 536 537 538 539 540 541 542 543

        const loadingComponent = (
            <div style={{ position: 'fixed', zIndex: 110, top: 0, left: 0, width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', background: 'rgba(255,255,255,0.8)' }}>
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
            </div>
        );
544
        return (
Deni Rinaldi's avatar
Deni Rinaldi committed
545
            <div className='a-s-p-mid no-header'>
d.arizona's avatar
d.arizona committed
546 547 548 549 550 551
                <Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
                    <Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
                        {this.state.messageAlert}
                    </Alert>
                </Snackbar>
                {this.state.loading && loadingComponent}
Deni Rinaldi's avatar
Deni Rinaldi committed
552
                <div className={"main-color"} style={{ padding: 27 }}>
d.arizona's avatar
d.arizona committed
553
                    <Typography style={{ fontSize: '16px', color: 'white' }}>Dashboard CAT Report</Typography>
554
                </div>
d.arizona's avatar
d.arizona committed
555
                <div style={{ padding: 20 }}>
d.arizona's avatar
d.arizona committed
556
                    <div style={{ marginTop: 0, display: 'flex' }}>
d.arizona's avatar
d.arizona committed
557 558 559
                        <Autocomplete
                            {...this.state.listCompany}
                            id="month"
560 561
                            onChange={(event, newInputValue) => this.setState({ company: newInputValue, loading: true }, () => {
                                let dataStorageCAT = localStorage.getItem(Constant.DATACAT)
d.arizona's avatar
d.arizona committed
562
                                let userID = localStorage.getItem(Constant.USER)
563
                                if (dataStorageCAT != 'datacat' && dataStorageCAT != null) {
d.arizona's avatar
d.arizona committed
564 565 566 567 568 569 570 571 572 573 574
                                    let arrayStorage = JSON.parse(dataStorageCAT)
                                    let indexListKPI = arrayStorage.findIndex((val) => val.userID == userID)
                                    let selectedKPI = []
                                    let indexListKPIDetail = -1
                                    if (indexListKPI != -1) {
                                        indexListKPIDetail = arrayStorage[indexListKPI].listKPI.findIndex((val) => val.companyId == this.state.company.company_id)
                                        if (indexListKPIDetail != -1) {
                                            selectedKPI = arrayStorage[indexListKPI].listKPI[indexListKPIDetail].list
                                        }
                                    }
                                    this.setState({ selectedKPI })
575
                                }
d.arizona's avatar
d.arizona committed
576 577 578
                                this.getDasboardCAT()
                            })}
                            disableClearable
d.arizona's avatar
d.arizona committed
579
                            style={{ width: '30%', maxWidth: 250, marginRight: 20 }}
d.arizona's avatar
d.arizona committed
580 581 582 583 584 585 586 587 588 589
                            renderInput={(params) => <TextField {...params} label="Company" margin="normal" style={{ marginTop: 7 }} />}
                            value={this.state.company}
                        />
                        <Autocomplete
                            {...this.state.listPeriode}
                            id="month"
                            onChange={(event, newInputValue) => this.setState({ periode: newInputValue, loading: true }, () => {
                                this.getDasboardCAT()
                            })}
                            disableClearable
d.arizona's avatar
d.arizona committed
590
                            style={{ width: '30%', maxWidth: 250, marginRight: 20 }}
d.arizona's avatar
d.arizona committed
591
                            renderInput={(params) => <TextField {...params} label="Periode" margin="normal" style={{ marginTop: 7 }} />}
592
                            value={this.state.periode}
d.arizona's avatar
d.arizona committed
593 594 595 596 597
                        />
                        <Autocomplete
                            {...this.state.listMonth}
                            id="month"
                            onChange={(event, newInputValue) => this.setState({ month: newInputValue, loading: true }, () => {
d.arizona's avatar
d.arizona committed
598 599 600 601 602 603 604
                                let index = this.state.listMonth.options.findIndex((val) => val.month_id == this.state.month.month_id)
                                let selectedMonth = []
                                this.state.listMonth.options.map((item, indexs) => {
                                    if (indexs <= index) {
                                        selectedMonth.push(item.month_value)
                                    }
                                })
605
                                this.setState({ selectedMonth })
d.arizona's avatar
d.arizona committed
606 607 608
                                this.getDasboardCAT()
                            })}
                            disableClearable
d.arizona's avatar
d.arizona committed
609
                            style={{ width: '30%', maxWidth: 250, marginRight: 20 }}
d.arizona's avatar
d.arizona committed
610 611 612 613
                            renderInput={(params) => <TextField {...params} label="Month" margin="normal" style={{ marginTop: 7 }} />}
                            value={this.state.month}
                        />
                    </div>
d.arizona's avatar
d.arizona committed
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
                    {/* <div style={{ marginTop: 20 }}>
                        <Autocomplete
                            {...this.state.listPeriode}
                            id="month"
                            onChange={(event, newInputValue) => this.setState({ periode: newInputValue, loading: true }, () => {
                                this.getDasboardCAT()
                            })}
                            disableClearable
                            style={{ maxWidth: 250, marginRight: 20 }}
                            renderInput={(params) => <TextField {...params} label="Periode" margin="normal" style={{ marginTop: 7 }} />}
                            value={this.state.periode}
                        />
                    </div> */}
                    {/* <div style={{ marginTop: 20 }}>
                        <Autocomplete
                            {...this.state.listMonth}
                            id="month"
                            onChange={(event, newInputValue) => this.setState({ month: newInputValue, loading: true }, () => {
                                let index = this.state.listMonth.options.findIndex((val) => val.month_id == this.state.month.month_id)
                                let selectedMonth = []
                                this.state.listMonth.options.map((item, indexs) => {
                                    if (indexs <= index) {
                                        selectedMonth.push(item.month_value)
                                    }
                                })
                                this.setState({ selectedMonth })
                                this.getDasboardCAT()
                            })}
                            disableClearable
                            style={{ maxWidth: 250, marginRight: 20 }}
                            renderInput={(params) => <TextField {...params} label="Month" margin="normal" style={{ marginTop: 7 }} />}
                            value={this.state.month}
                        />
                    </div> */}
d.arizona's avatar
d.arizona committed
648
                </div>
d.arizona's avatar
d.arizona committed
649

d.arizona's avatar
d.arizona committed
650
                {!this.state.loading && <div className="padding-20px" style={{ display: 'flex' }}>
d.arizona's avatar
d.arizona committed
651
                    <Paper style={{ marginTop: 10, minWidth: this.props.open ? this.props.width - 360 : this.props.width - 100 }}>
652
                        <AppBar position="static" style={{ borderTopRightRadius: 10, borderTopLeftRadius: 10 }}>
d.arizona's avatar
d.arizona committed
653
                            <Tabs indicatorColor="white" value={this.state.tab} onChange={this.selectTab} aria-label="simple tabs example" style={{ backgroundColor: '#354960', borderColor: 'transparent', borderTopRightRadius: 10, borderTopLeftRadius: 10 }}>
d.arizona's avatar
d.arizona committed
654 655 656
                                <Tab label="Executive Scoreboard" style={{ color: 'white', fontSize: 11, width: 50, fontWeight: 'bold', backgroundColor: this.state.tab == 0 ? '#6c84a1' : '#354960' }} />
                                <Tab label="Strategy Map" style={{ color: 'white', fontSize: 11, width: 50, fontWeight: 'bold', backgroundColor: this.state.tab == 1 ? '#6c84a1' : '#354960' }} />
                                <Tab label="KPIs" style={{ color: 'white', fontSize: 11, width: 50, fontWeight: 'bold', backgroundColor: this.state.tab == 2 ? '#6c84a1' : '#354960' }} />
657 658
                            </Tabs>
                        </AppBar>
659
                        {this.state.tab === 0 ?
d.arizona's avatar
d.arizona committed
660
                            <ExceutiveScoreboard selectedKPI={this.state.selectedKPI} selectedMonth={this.state.selectedMonth} setSelectedKPI={this.setSelectedKPI.bind(this)} height={this.props.height} data={this.state.dataDashboard} dataPayload={{ month: this.state.month, periode: this.state.periode, company: this.state.company }} />
661
                            :
662
                            this.state.tab === 1 ?
d.arizona's avatar
d.arizona committed
663
                                <StrategiMap height={this.props.height} data={this.state.dataDashboard} dataPayload={{ month: this.state.month, periode: this.state.periode, company: this.state.company }} />
664
                                :
d.arizona's avatar
d.arizona committed
665
                                <KPIs height={this.props.height} tableCAT={this.state.tableCAT} selectedMonth={this.state.selectedMonth} width={this.props.open ? this.props.width - 360 : this.props.width - 100} data={this.state.dataDashboard} dataPayload={{ month: this.state.month, periode: this.state.periode, company: this.state.company }} />
666 667
                        }
                    </Paper>
d.arizona's avatar
d.arizona committed
668
                </div>}
669 670 671 672
            </div>
        )
    }
}