HomePage.js 44.6 KB
Newer Older
Deni Rinaldi's avatar
Deni Rinaldi committed
1
import React, { Component } from 'react';
d.arizona's avatar
d.arizona committed
2
import { Typography, MuiThemeProvider, createMuiTheme, Paper, TextField} from '@material-ui/core';
Deni Rinaldi's avatar
Deni Rinaldi committed
3
import MUIDataTable from "mui-datatables";
Deni Rinaldi's avatar
Deni Rinaldi committed
4
import Images from '../assets/Images';
Deni Rinaldi's avatar
Deni Rinaldi committed
5
import DonutChart from 'react-d3-donut';
d.arizona's avatar
d.arizona committed
6 7
import Constant from '../library/Constant';
import api from '../api';
d.arizona's avatar
d.arizona committed
8
import { Link } from 'react-router-dom';
d.arizona's avatar
d.arizona committed
9
import { PropagateLoader } from 'react-spinners';
d.arizona's avatar
d.arizona committed
10
import { titleCase } from '../library/Utils';
d.arizona's avatar
d.arizona committed
11
import { format } from 'date-fns';
d.arizona's avatar
d.arizona committed
12
import Autocomplete from '@material-ui/lab/Autocomplete';
Deni Rinaldi's avatar
Deni Rinaldi committed
13

Deni Rinaldi's avatar
Deni Rinaldi committed
14 15 16
var ct = require("../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable());

Deni Rinaldi's avatar
Deni Rinaldi committed
17
class HomePage extends Component {
d.arizona's avatar
d.arizona committed
18 19 20
    constructor(props) {
        super(props)
        this.state = {
d.arizona's avatar
d.arizona committed
21
            userData: null,
Deni Rinaldi's avatar
Deni Rinaldi committed
22 23 24 25 26 27
            listDashboard: [],
            listMasterBudget: [
                { nama: 'Triputra Agro Persada', status: 'complete' },
                { nama: 'Puninar Infinite Raya', status: 'complete' },
                { nama: 'Dharma Group', status: 'overdue' },
                { nama: 'Daya Group', status: 'open' },
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
28
            ],
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
29
            isApprover: true,
Deni Rinaldi's avatar
Deni Rinaldi committed
30
            listSubcoMB: [],
rifkaki's avatar
rifkaki committed
31
            listSubcoMR: [],
Deni Rinaldi's avatar
Deni Rinaldi committed
32
            valueSubmit: 0,
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
33
            listdmb: [],
Deni Rinaldi's avatar
Deni Rinaldi committed
34
            dataTableMB: [],
d.arizona's avatar
d.arizona committed
35 36 37 38 39 40
            listPeriodeMB: null,
            listPeriodeMR: null,
            listMonth: null,
            periodeMB: null,
            periodeMR: null,
            month: null,
rifkaki's avatar
rifkaki committed
41 42 43
            loading: false,
            accessMB: false,
            accessMR: false,
d.arizona's avatar
d.arizona committed
44 45 46 47
        }
    }

    componentDidMount() {
Deni Rinaldi's avatar
Deni Rinaldi committed
48
        this.setState({ loading: true })
d.arizona's avatar
d.arizona committed
49 50 51
        let userId = localStorage.getItem(Constant.USER)
        api.create().getDetailUser(userId).then((response) => {
            if (response.data) {
Deni Rinaldi's avatar
Deni Rinaldi committed
52
                if (response.data.status === 'success') {
Deni Rinaldi's avatar
Deni Rinaldi committed
53
                    this.setState({ userData: response.data.data }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
54
                        // console.log(this.state.userData)
d.arizona's avatar
d.arizona committed
55 56 57 58
                    })
                }
            }
        })
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
59 60 61 62 63 64 65 66 67
        // api.create().checkApprover().then(response => {
        //     console.log(response);
        //     if (response.data.data.is_approver === true) {
        //         this.setState({ isApprover: true }, () =>
        //             this.getDashboard())
        //     } else {
        //         this.setState({ isApprover: false })
        //     }
        // })
rifkaki's avatar
rifkaki committed
68 69
        this.getPermissionMB()
        this.getPermissionMR()
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
70
        this.getApprMat()
d.arizona's avatar
d.arizona committed
71 72
        // this.getListUserSubco()
        this.getMonth()
d.arizona's avatar
d.arizona committed
73 74
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
75
    componentDidUpdate() {
d.arizona's avatar
d.arizona committed
76
        window.onpopstate = e => {
Deni Rinaldi's avatar
Deni Rinaldi committed
77 78
            //your code...
            this.props.selectIndex('Home')
d.arizona's avatar
d.arizona committed
79 80 81
        }
    }

d.arizona's avatar
d.arizona committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    getPeriode() {
        let currentYear = new Date().getFullYear()
        let MB = []
        let MR = []
        for(var i=2000;i<=currentYear; i++) {
            MB.push({name: String(i), value: i})
            MR.push({name: String(i), value: i})
            if (i == currentYear) {
                MB.push({name: String(i+1), value: i+1})
            }
        }

        let defaultPropsMB = {
            options: MB,
            getOptionLabel: (option) => option.name,
        };

        let defaultPropsMR = {
            options: MR,
            getOptionLabel: (option) => option.name,
        };
d.arizona's avatar
d.arizona committed
103 104 105 106 107
        // console.log(MR[MR.length - 1])
        let dateNow = new Date()
        dateNow.setMonth(dateNow.getMonth() - 1);
        let yearNow = dateNow.getFullYear()
        let indexMonthMR = MR.findIndex((val) => val.value == yearNow)
d.arizona's avatar
d.arizona committed
108

d.arizona's avatar
d.arizona committed
109
        this.setState({listPeriodeMB: defaultPropsMB, periodeMB: MB[MB.length - 1], listPeriodeMR: defaultPropsMR, periodeMR: MR[indexMonthMR]}, () => {
d.arizona's avatar
d.arizona committed
110 111 112 113 114 115 116
            this.getListUserSubcoMB()
            this.getListUserSubcoMR()
        })
    }

    getMonth() {
        api.create().getMonthTransaction().then(response => {
d.arizona's avatar
d.arizona committed
117 118
            let dateNow = new Date()
            dateNow.setMonth(dateNow.getMonth() - 1);
d.arizona's avatar
d.arizona committed
119
            let month = format(dateNow, 'MMMM')
d.arizona's avatar
d.arizona committed
120
            // console.log(month);
d.arizona's avatar
d.arizona committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134
            if (response.data) {
                if (response.data.status === "success") {
                    // console.log(response);
                    let data = response.data.data
                    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,
                    };
Riri Novita's avatar
Riri Novita committed
135
                    let index = data.findIndex((val) => val.month_name == month)
d.arizona's avatar
d.arizona committed
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
                    // console.log(month)
                    // console.log(index)
                    this.setState({ listMonth: defaultProps, month: index == -1 ? monthData[0] : monthData[index] }, () => {
                        // if (this.state.isApprover === true) {
                        //     if (this.state.submittedOnly) {
                        //         console.log('masuk cuk')
                        //         this.getPeriode()
                        //     } else {
                        //         this.getLastPeriod()
                        //     }
                        this.getPeriode()
                        // } else {
                            // this.getLastPeriod()
                            // this.getPeriode()
                        // }
                    })
                } else {
                    // this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                    //     if (response.data.message.includes("Someone Logged In")) {
                    //         setTimeout(() => {
                    //             localStorage.removeItem(Constant.TOKEN)
                    //             window.location.reload();
                    //         }, 1000);
                    //     }
                    // })
                }
            } else {
                // this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
            }
        })
    }

    

rifkaki's avatar
rifkaki committed
170 171 172 173 174
    getPermissionMB() {
        let payload = {
            menu: "Master Budget & CAT"
        }
        api.create().getPermission(payload).then(response => {
d.arizona's avatar
d.arizona committed
175
            // console.log(response)
rifkaki's avatar
rifkaki committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({
                        btnCreateMB: response.data.data.create,
                        btnEditMB: response.data.data.edit,
                        load: true
                    },() => {
                        if (this.state.btnCreateMB === true && this.state.btnEditMB === true){
                            this.setState({ accessMB: true })
                        }
                    })
                } else {
                    this.setState({
                        load: true
                    })
                }
            } else {
                this.setState({ load: true })
            }
        })
    }

    getPermissionMR() {
        let payload = {
            menu: "monthly report"
        }
        api.create().getPermission(payload).then(response => {
d.arizona's avatar
d.arizona committed
203
            // console.log(response)
rifkaki's avatar
rifkaki committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({
                        btnCreateMR: response.data.data.create,
                        btnEditMR: response.data.data.edit,
                        load: true
                    },() => {
                        if (this.state.btnCreateMR === true && this.state.btnEditMR === true){
                            this.setState({ accessMR: true })
                        }
                    })
                } else {
                    this.setState({
                        load: true
                    })
                }
            } else {
                this.setState({ load: true })
            }
        })
    }
d.arizona's avatar
d.arizona committed
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
    
    getListUserSubcoMB() {
        // console.log(this.state.month.month_id)
        // console.log(this.state.periodeMR.value)
        api.create().getListUserSubcoMB(this.state.periodeMB.value).then((response) => {
            // console.log(response)
            let valueSubmit = 0
            let dataMB = []
            if (response.data) {
                if (response.data.status === "success") {
                    response.data.data.map((item, index) => {
                        if (item.is_submit === true) {
                            valueSubmit += 1
                        }
                        dataMB.push(item)
                        
                    })
                    this.setState({
                        listSubcoMB: dataMB,
                        valueSubmit,
                        loading: false
                    })
                }
            } else {
                this.setState({loading: false})
            }
        })
    }

    getListUserSubcoMR() {
        // console.log(this.state.month.month_id)
        // console.log(this.state.periodeMR.value)
        api.create().getListUserSubcoMR(this.state.month.month_id, this.state.periodeMR.value).then((response) => {
            let valueSubmitMR = 0
            let dataMR = []
d.arizona's avatar
d.arizona committed
260
            console.log(response)
d.arizona's avatar
d.arizona committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
            if (response.data) {
                if (response.data.status === "success") {
                    response.data.data.map((item, index) => {
                        if (item.is_submit === true ) {
                            valueSubmitMR += 1
                        }
                        dataMR.push(item)
                    })
                    this.setState({
                        listSubcoMR: dataMR,
                        valueSubmitMR,
                        loading: false
                    })
                }
            } else {
                this.setState({loading: false})
            }
        })
    }
rifkaki's avatar
rifkaki committed
280

Deni Rinaldi's avatar
Deni Rinaldi committed
281 282
    getListUserSubco() {
        api.create().getDashboardUser().then(response => {
d.arizona's avatar
d.arizona committed
283
            // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
284
            let valueSubmit = 0
rifkaki's avatar
rifkaki committed
285 286 287
            let valueSubmitMR = 0
            let dataMB = []
            let dataMR = []
Deni Rinaldi's avatar
Deni Rinaldi committed
288 289 290
            if (response.data) {
                if (response.data.status === "success") {
                    response.data.data.map((item, index) => {
rifkaki's avatar
rifkaki committed
291
                        if (item.is_submit === true && item.type === "master_budget") {
Deni Rinaldi's avatar
Deni Rinaldi committed
292
                            valueSubmit += 1
rifkaki's avatar
rifkaki committed
293 294 295 296 297 298 299 300
                        } else if (item.is_submit === true && item.type === "monthly_report") {
                            valueSubmitMR += 1
                        }

                        if ( item.type === "master_budget" ) {
                            dataMB.push(item)
                        } else {
                            dataMR.push(item)
Deni Rinaldi's avatar
Deni Rinaldi committed
301 302 303
                        }
                    })
                    this.setState({
rifkaki's avatar
rifkaki committed
304 305
                        listSubcoMB: dataMB,
                        listSubcoMR: dataMR,
Deni Rinaldi's avatar
Deni Rinaldi committed
306
                        valueSubmit,
rifkaki's avatar
rifkaki committed
307
                        valueSubmitMR,
Deni Rinaldi's avatar
Deni Rinaldi committed
308
                        loading: false
Deni Rinaldi's avatar
Deni Rinaldi committed
309 310 311
                    })
                }
            }
d.arizona's avatar
d.arizona committed
312 313
            // console.log(this.state.listSubcoMB)
            // console.log(this.state.listSubcoMR)
Deni Rinaldi's avatar
Deni Rinaldi committed
314 315 316
        })
    }

d.arizona's avatar
d.arizona committed
317 318
    getDashboard() {
        let listDashboard = []
d.arizona's avatar
d.arizona committed
319
        let rawData = []
d.arizona's avatar
d.arizona committed
320
        api.create().getDashboard().then((response) => {
d.arizona's avatar
d.arizona committed
321
            console.log(response);
d.arizona's avatar
d.arizona committed
322 323
            if (String(response.data.status).toLocaleLowerCase() == 'success') {
                let data = response.data.data
Deni Rinaldi's avatar
Deni Rinaldi committed
324
                data.map((item, index) => {
d.arizona's avatar
d.arizona committed
325
                    let statusConvert = item.status == 'approval_review'? 'Waiting For Review' : item.status == 'approval_proccess'? 'Waiting For Approval' : titleCase(item.status) 
rifkaki's avatar
rifkaki committed
326
                    if (this.state.isApproverMB && this.state.isApproverMR){
rifkaki's avatar
rifkaki committed
327 328 329 330 331 332 333
                        if (String(item.type_report).toLocaleLowerCase().includes("master")){
                            listDashboard.push([index + 1, item.approval_id, item.company_name, `${item.type_report} - ${item.periode}`, item.revision, item.status, statusConvert])
                            rawData.push(item)
                        } else if (String(item.type_report).toLocaleLowerCase().includes("monthly")){
                            listDashboard.push([index + 1, item.approval_id, item.company_name, `${item.type_report} ${item.periode}`, item.revision, item.status, statusConvert])
                            rawData.push(item)
                        }
rifkaki's avatar
rifkaki committed
334 335 336 337 338 339 340
                    } else if (this.state.isApproverMB) {
                        if (String(item.type_report).toLocaleLowerCase().includes("master")){
                            listDashboard.push([index + 1, item.approval_id, item.company_name, `${item.type_report} - ${item.periode}`, item.revision, item.status, statusConvert])
                            rawData.push(item)
                        }
                    } else if (this.state.isApproverMR) {
                        if (String(item.type_report).toLocaleLowerCase().includes("monthly")){
rifkaki's avatar
rifkaki committed
341
                            listDashboard.push([index + 1, item.approval_id, item.company_name, `${item.type_report} ${item.periode}`, item.revision, item.status, statusConvert])
rifkaki's avatar
rifkaki committed
342 343 344
                            rawData.push(item)
                        }
                    }
d.arizona's avatar
d.arizona committed
345
                })
d.arizona's avatar
d.arizona committed
346
                this.setState({ listDashboard, rawData })
d.arizona's avatar
d.arizona committed
347 348
            }
        })
d.arizona's avatar
d.arizona committed
349 350
    }

Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
351
    getApprMat() {
d.arizona's avatar
d.arizona committed
352
        this.setState({loading: true})
rifkaki's avatar
rifkaki committed
353 354
        let isApproverMR = false
        let isApproverMB = false
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
355
        api.create().getAM().then((response) => {
d.arizona's avatar
d.arizona committed
356
            // console.log(response);
r.kurnia's avatar
r.kurnia committed
357
            let actAMActive = []
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
358
            let actAM = response.data.data.map((item, index) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
359
                if (String(item.status).toLocaleLowerCase() == 'active') {
r.kurnia's avatar
r.kurnia committed
360
                    actAMActive.push(item)
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
361 362 363 364
                    return item
                }
            })
            let userId = localStorage.getItem(Constant.USER)
d.arizona's avatar
d.arizona committed
365
            // console.log(userId);
r.kurnia's avatar
r.kurnia committed
366
            let indexId = actAMActive.findIndex((val) => val.user_id == userId)
rifkaki's avatar
rifkaki committed
367 368 369 370 371 372 373 374
            actAMActive.map((item, index) => {
                if (item.approval_type_name === "MONTHLY_REPORT"){
                    isApproverMR = true
                } else if (item.approval_type_name === "MASTER_BUDGET"){
                    isApproverMB = true
                }
            })

Deni Rinaldi's avatar
Deni Rinaldi committed
375
            if (indexId === -1) {
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
376
                this.setState({ isApprover: false })
d.arizona's avatar
d.arizona committed
377 378
                this.getMonth()
                // this.getListUserSubco()
rifkaki's avatar
rifkaki committed
379
            }
rifkaki's avatar
rifkaki committed
380
            this.setState({ isApproverMB, isApproverMR})
Deni Rinaldi's avatar
Deni Rinaldi committed
381
            this.getDashboardMB()
d.arizona's avatar
d.arizona committed
382 383
            // this.getDashboardMB()
            this.getDashboard()
Deni Rinaldi's avatar
Deni Rinaldi committed
384
            // console.log(actAM)
d.arizona's avatar
d.arizona committed
385
            this.setState({loading: false})
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
386 387 388
        })
    }

Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
389
    getDashboardMB() {
Deni Rinaldi's avatar
Deni Rinaldi committed
390
        api.create().getDashboardMB().then((response) => {
d.arizona's avatar
d.arizona committed
391
            // console.log(response)
Deni Rinaldi's avatar
Deni Rinaldi committed
392
            if (String(response.data.status).toLocaleLowerCase() == 'success') {
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
393 394 395 396 397 398 399 400
                let data = response.data.data
                let listdmb = data.sort((a, b) => a.company_id - b.company_id).map((item, index) => {
                    return [
                        item.company_name,
                        item.master_budget,
                        item.operating_indicator
                    ]
                })
Deni Rinaldi's avatar
Deni Rinaldi committed
401
                this.setState({ dataTableMB: listdmb, loading: false })
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
402 403 404 405
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
406
    render() {
d.arizona's avatar
d.arizona committed
407 408 409 410 411 412 413 414
        const getDataMonth = (item) => {
            let months = item.months
            let dataMonth = this.state.listMonth.options
            let indexID = dataMonth.findIndex((val) => val.month_id == months)
            // console.log(dataMonth[indexID])
            return dataMonth[indexID]
        }

d.arizona's avatar
d.arizona committed
415 416 417 418 419 420 421
        const columns = ["#", "ID", "Company", "Report Type", "Revision", 
        {
            name: "",
            options: {
                display: false
            }
        }, 'Status', {
Deni Rinaldi's avatar
Deni Rinaldi committed
422 423 424
            name: "Action",
            options: {
                customBodyRender: (val, tableMeta) => {
d.arizona's avatar
d.arizona committed
425
                    // console.log(tableMeta);
Deni Rinaldi's avatar
Deni Rinaldi committed
426 427
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
428
                            <Link to={{
d.arizona's avatar
d.arizona committed
429
                                pathname: String(tableMeta.rowData[3]).toLocaleLowerCase().includes("master") ? `/home/master-budget/` : `/home/monthly-report/`,
Deni Rinaldi's avatar
Deni Rinaldi committed
430
                                state: {
Deni Rinaldi's avatar
Deni Rinaldi committed
431
                                    userType: 'approver',
d.arizona's avatar
d.arizona committed
432
                                    rawData: this.state.rawData[tableMeta.rowIndex],
d.arizona's avatar
d.arizona committed
433
                                    month: String(tableMeta.rowData[3]).toLocaleLowerCase().includes("master") ? null : getDataMonth(this.state.rawData[tableMeta.rowIndex])
Deni Rinaldi's avatar
Deni Rinaldi committed
434 435
                                }
                            }}>
d.arizona's avatar
d.arizona committed
436 437 438 439 440 441 442 443 444 445 446 447
                                <button
                                    style={{
                                        backgroundColor: 'transparent',
                                        cursor: 'pointer',
                                        borderColor: 'transparent',
                                        marginRight: 10
                                    }}
                                    onClick={() => null}
                                >
                                    <img src={Images.editCopy2} />
                                </button>
                            </Link>
Deni Rinaldi's avatar
Deni Rinaldi committed
448 449 450 451 452 453 454 455 456 457 458 459 460
                        </div >
                    );
                }
            }
        }]
        const data = [
            ["1", "TRIPUTRA AGRO PERSADA", "Laporan Bulanan - September 2020", "1 (20 Oktober 2020)", "Belum Disetujui"],
            ["2", "DAYA GROUP", "Laporan Bulanan - September 2020", "1 (20 Oktober 2020)", "Belum Disetujui"],
            ["3", "PUNINAR INFINITE RAYA", "Budget Tahunan 2021", "0 (20 Oktober 2020)", "Belum Disetujui"],
            ["4", "DHARMA GROUP", "Laporan Bulanan - September 2020", "0 (20 Oktober 2020)", "Belum Disetujui"],
            ["5", "PUNINAR INFINITE RAYA", "Budget Tahunan 2021", "0 (20 Oktober 2020)", "Belum Disetujui"],
        ]
        const options = {
d.arizona's avatar
d.arizona committed
461
            filter: true,
Deni Rinaldi's avatar
Deni Rinaldi committed
462 463 464 465 466
            sort: false,
            responsive: "scroll",
            print: false,
            download: false,
            selectableRows: false,
d.arizona's avatar
d.arizona committed
467
            viewColumns: true,
Deni Rinaldi's avatar
Deni Rinaldi committed
468
            rowsPerPage: 5,
d.arizona's avatar
d.arizona committed
469
            search: true
Deni Rinaldi's avatar
Deni Rinaldi committed
470
        }
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
471 472 473

        const columnsMB = ["Company", "Master Budget & CAT", "Operating Indicator"]

Deni Rinaldi's avatar
Deni Rinaldi committed
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
        const dataChart = [{
            count: 90,
            color: '#5198ea',
            name: 'My name',
        }, {
            count: 10,
            color: '#ffd600',
            name: 'name',
        }]
        const dataChart2 = [{
            count: 90,
            color: '#f65a4c',
            name: 'My name',
        }, {
            count: 10,
            color: '#5198ea',
            name: 'name',
        }]
        const dataChart3 = [{
            count: 90,
            color: '#4caf51',
            name: 'My name',
        }, {
            count: 10,
            color: '#f65a4c',
            name: 'name',
        }]
d.arizona's avatar
d.arizona committed
501 502 503 504 505 506 507 508 509 510
        const loadingComponent = (
            <div style={{ position: 'absolute', 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>
        );
d.arizona's avatar
d.arizona committed
511
        let bulan = format(new Date(), 'MMM')
rifkaki's avatar
rifkaki committed
512
        let tahun = new Date().getFullYear()
Deni Rinaldi's avatar
Deni Rinaldi committed
513
        return (
d.arizona's avatar
d.arizona committed
514
            <div style={{ flex: 1, backgroundColor: '#f8f8f8', minHeight: this.props.height }}>
d.arizona's avatar
d.arizona committed
515
                {this.state.loading && loadingComponent}
Deni Rinaldi's avatar
Deni Rinaldi committed
516
                {this.state.isApprover === true ?
Deni Rinaldi's avatar
Deni Rinaldi committed
517
                    <div>
Deni Rinaldi's avatar
Deni Rinaldi committed
518 519 520
                        <div className={"main-color"} style={{ height: 78, flex: 1, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
                            <Typography style={{ fontSize: '24px', color: 'white' }}>{this.state.userData === null ? '' : `Welcome, ${this.state.userData.fullname} !`}</Typography>
                        </div>
rifkaki's avatar
rifkaki committed
521 522 523 524 525
                        <div>
                            <div style={{ flex: 1, padding: 20, width: '100%' }}>
                                <div style={{ display: 'flex' }}>
                                    <Typography style={{ color: '#656565', fontSize: '16px', fontWeight: 'bold' }}>Waiting Your Approval</Typography>
                                </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
526

Deni Rinaldi's avatar
Deni Rinaldi committed
527
                            </div>
rifkaki's avatar
rifkaki committed
528 529 530

                            <div style={{ flex: 1, padding: 20, width: '100%' }}>
                                <div>
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
531 532
                                    <MuiThemeProvider theme={getMuiTheme()}>
                                        <MUIDataTable
rifkaki's avatar
rifkaki committed
533 534
                                            data={this.state.listDashboard}
                                            columns={columns}
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
535 536 537 538
                                            options={options}
                                        />
                                    </MuiThemeProvider>
                                </div>
rifkaki's avatar
rifkaki committed
539 540 541 542 543 544 545 546 547 548 549 550
                                <div style={{ marginTop: 20 }}>
                                    <Typography style={{ color: '#656565', fontSize: '16px', fontWeight: 'bold' }}>Master Budget & CAT</Typography>
                                    <div style={{ marginTop: 10, width: '100%' }}>
                                        <MuiThemeProvider theme={getMuiTheme()}>
                                            <MUIDataTable
                                                data={this.state.dataTableMB}
                                                columns={columnsMB}
                                                options={options}
                                            />
                                        </MuiThemeProvider>
                                    </div>
                                </div>
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
551
                            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
552
                            {/* <div style={{ marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
553 554 555 556 557 558 559 560 561 562 563 564 565
                                <Typography style={{ color: '#656565', fontSize: '16px', fontWeight: 'bold' }}>Status Laporan</Typography>
                                <div style={{ marginTop: 10, display: 'flex' }}>
                                    <div style={{ width: 280, height: 400, padding: 20, backgroundColor: 'white', borderRadius: 6, border: 'solid 1px #c4c4c4', marginRight: 25 }}>
                                        <Typography style={{ color: '#4b4b4b', fontSize: '24px', fontWeight: 'bold' }}>Budget Tahunan - 2021</Typography>
                                        <div style={{ textAlign: 'center' }}>
                                            <DonutChart
                                                innerRadius={70}
                                                outerRadius={100}
                                                transition={true}
                                                pieClass="pie1"
                                                displayTooltip={true}
                                                strokeWidth={3}
                                                data={dataChart} />
Deni Rinaldi's avatar
Deni Rinaldi committed
566
                                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
                                        <div style={{ display: 'flex', width: '100%', marginTop: 10 }}>
                                            <div style={{ width: '33%' }}>
                                                <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>Submit</Typography>
                                                <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>92.8 %</Typography>
                                                <div style={{ display: 'flex' }} >
                                                    <img src={Images.red} />
                                                    <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>-0.6%</Typography>
                                                </div>
                                            </div>
                                            <div style={{ width: '33%' }}>
                                                <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>On Time</Typography>
                                                <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>6.1 %</Typography>
                                                <div style={{ display: 'flex' }} >
                                                    <img src={Images.green} />
                                                    <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>0.7%</Typography>
                                                </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
583

Deni Rinaldi's avatar
Deni Rinaldi committed
584 585 586 587 588 589 590 591 592
                                            </div>
                                            <div style={{ width: '33%' }}>
                                                <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>Overdue</Typography>
                                                <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>1.1 %</Typography>
                                                <div style={{ display: 'flex' }} >
                                                    <img src={Images.green} />
                                                    <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>0.1%</Typography>
                                                </div>
                                            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
593 594
                                        </div>
                                    </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634

                                    <div style={{ width: 280, height: 400, padding: 20, backgroundColor: 'white', borderRadius: 6, border: 'solid 1px #c4c4c4', marginRight: 25 }}>
                                        <Typography style={{ color: '#4b4b4b', fontSize: '24px', fontWeight: 'bold' }}>Laporan Bulanan - Oct 2020</Typography>
                                        <div style={{ textAlign: 'center' }}>
                                            <DonutChart
                                                innerRadius={70}
                                                outerRadius={100}
                                                transition={true}
                                                pieClass="pie5"
                                                displayTooltip={true}
                                                strokeWidth={3}
                                                data={dataChart2}
                                            />
                                        </div>
                                        <div style={{ display: 'flex', width: '100%', marginTop: 10 }}>
                                            <div style={{ width: '33%' }}>
                                                <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>Submit</Typography>
                                                <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>92.8 %</Typography>
                                                <div style={{ display: 'flex' }} >
                                                    <img src={Images.red} />
                                                    <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>-0.6%</Typography>
                                                </div>
                                            </div>
                                            <div style={{ width: '33%' }}>
                                                <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>On Time</Typography>
                                                <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>6.1 %</Typography>
                                                <div style={{ display: 'flex' }} >
                                                    <img src={Images.green} />
                                                    <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>0.7%</Typography>
                                                </div>

                                            </div>
                                            <div style={{ width: '33%' }}>
                                                <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>Overdue</Typography>
                                                <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>1.1 %</Typography>
                                                <div style={{ display: 'flex' }} >
                                                    <img src={Images.green} />
                                                    <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>0.1%</Typography>
                                                </div>
                                            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
635 636
                                        </div>
                                    </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
637 638 639 640 641 642 643 644 645 646 647 648
                                    <div style={{ width: 280, height: 400, padding: 20, backgroundColor: 'white', borderRadius: 6, border: 'solid 1px #c4c4c4', }}>
                                        <Typography style={{ color: '#4b4b4b', fontSize: '24px', fontWeight: 'bold', height: 71 }}>Lainnya</Typography>
                                        <div style={{ textAlign: 'center' }}>
                                            <DonutChart
                                                innerRadius={70}
                                                outerRadius={100}
                                                transition={true}
                                                pieClass="pie2"
                                                displayTooltip={true}
                                                strokeWidth={3}
                                                data={dataChart3}
                                            />
Deni Rinaldi's avatar
Deni Rinaldi committed
649
                                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
                                        <div style={{ display: 'flex', width: '100%', marginTop: 10 }}>
                                            <div style={{ width: '33%' }}>
                                                <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>Submit</Typography>
                                                <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>92.8 %</Typography>
                                                <div style={{ display: 'flex' }} >
                                                    <img src={Images.red} />
                                                    <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>-0.6%</Typography>
                                                </div>
                                            </div>
                                            <div style={{ width: '33%' }}>
                                                <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>On Time</Typography>
                                                <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>6.1 %</Typography>
                                                <div style={{ display: 'flex' }} >
                                                    <img src={Images.green} />
                                                    <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>0.7%</Typography>
                                                </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
666

Deni Rinaldi's avatar
Deni Rinaldi committed
667 668 669 670 671 672 673 674 675
                                            </div>
                                            <div style={{ width: '33%' }}>
                                                <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>Overdue</Typography>
                                                <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>1.1 %</Typography>
                                                <div style={{ display: 'flex' }} >
                                                    <img src={Images.green} />
                                                    <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>0.1%</Typography>
                                                </div>
                                            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
676 677 678
                                        </div>
                                    </div>
                                </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
679
                            </div> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
680
                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
681
                    </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
682 683 684 685 686
                    :
                    <div>
                        <div className={"main-color"} style={{ height: 78, flex: 1, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
                            <Typography style={{ fontSize: '24px', color: 'white' }}>{this.state.userData === null ? '' : `Welcome, ${this.state.userData.fullname} !`}</Typography>
                        </div>
rifkaki's avatar
rifkaki committed
687
                        {(this.state.accessMB || this.state.accessMR) && 
d.arizona's avatar
d.arizona committed
688
                            <div style={{ flex: 1, paddingLeft: 20, paddingRight: 20, paddingTop: 20, paddingBottom: 0, width: '100%' }}>
rifkaki's avatar
rifkaki committed
689 690 691
                                <div style={{ display: 'flex' }}>
                                    <Typography style={{ color: '#656565', fontSize: '16px', fontWeight: 'bold' }}>Tasks to be Complete</Typography>
                                </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
692
                            </div>
rifkaki's avatar
rifkaki committed
693 694 695 696 697 698 699 700
                        }
                        {(this.state.accessMB === false && this.state.accessMR === false) &&
                            <div style={{ flex: 1, padding: 20, width: '100%' }}>
                                <div style={{ display: 'flex' }}>
                                    <Typography style={{ color: '#656565', fontSize: '16px', fontWeight: 'bold' }}>You don't have pending task</Typography>
                                </div>
                            </div>
                        }
rifkaki's avatar
rifkaki committed
701
                        <div style={{ display: 'inline-flex' }}>
rifkaki's avatar
rifkaki committed
702
                            {this.state.accessMB &&
rifkaki's avatar
rifkaki committed
703
                            <div style={{ flex: 1, padding: 20, width: '100%' }}>
d.arizona's avatar
d.arizona committed
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
                                <div style={{ display: 'flex' }}>
                                    <Autocomplete
                                        {...this.state.listPeriodeMB}
                                        id="periodeMB"
                                        onChange={(event, newInputValue) => this.setState({ periodeMB: newInputValue, loading: true }, () => {
                                            // if (this.state.isApprover === true) {
                                            //         this.getCompanySubmitted()
                                            // } else {
                                                // this.setState({ visibleTableHistory: false })
                                                // this.getRevision()
                                            // }\
                                            this.getListUserSubcoMB()
                                        })}
                                        disableClearable
                                        style={{ width: 250 }}
                                        renderInput={(params) => <TextField {...params} label="Periode MB" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.periodeMB}
                                    />
                                </div>
                                <Paper style={{ width: 450, padding: 20, borderRadius: 10, marginTop: 5 }}>
rifkaki's avatar
rifkaki committed
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
                                    <Typography style={{ fontWeight: 'bold', textDecorationLine: 'underline' }}>{`Master Budget ${this.state.valueSubmit}/${this.state.listSubcoMB.length}`}</Typography>
                                    {this.state.listSubcoMB.map((item, index) => {
                                        return (
                                            <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 10, paddingLeft: 10 }}>
                                                <div style={{ display: 'flex' }}>
                                                    <img src={item.is_submit === true ? Images.dotDone : item.is_overdue === true ? Images.dotOverdue : Images.dotOpen} />
                                                    <Link to={{
                                                        pathname: `/home/master-budget/`,
                                                        state: {
                                                            userType: 'user',
                                                            rawData: item
                                                        }
                                                    }}>
                                                        <button
                                                            style={{
                                                                backgroundColor: 'transparent',
                                                                cursor: 'pointer',
                                                                borderColor: 'transparent',
                                                                margin: 5,
                                                                outline: 'none'
                                                            }}>
                                                            <Typography style={{ marginLeft: 10, color: '#5198ea', fontSize: 13 }}>{item.company_name}</Typography>
                                                        </button>
                                                    </Link>
                                                </div>
                                                {item.is_overdue && (
                                                    <div style={{ backgroundColor: '#f65a4c', paddingRight: 5, paddingLeft: 5, borderRadius: 5, alignSelf: 'center' }}>
                                                        <Typography style={{ fontSize: 11, color: '#fff' }}>Overdue</Typography>
                                                    </div>
                                                )}
Deni Rinaldi's avatar
Deni Rinaldi committed
754
                                            </div>
rifkaki's avatar
rifkaki committed
755 756 757 758
                                        )
                                    })}
                                </Paper>
                            </div>
rifkaki's avatar
rifkaki committed
759 760
                            }
                            {this.state.accessMR &&
rifkaki's avatar
rifkaki committed
761
                            <div style={{ flex: 1, padding: 20, width: '100%' }}>
d.arizona's avatar
d.arizona committed
762 763 764 765 766
                                <div style={{ display: 'flex' }}>
                                    <Autocomplete
                                        {...this.state.listMonth}
                                        id="month"
                                        onChange={(event, newInputValue) => this.setState({ month: newInputValue, loading: true }, () => {
d.arizona's avatar
d.arizona committed
767
                                            this.getListUserSubcoMR()
d.arizona's avatar
d.arizona committed
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
                                            // if (this.state.isApprover === true) {
                                            //     this.getCompanySubmitted()
                                            // } else {
                                                // this.setState({ visibleTableHistory: false })
                                                // this.getRevision()
                                            // }
                                        })}
                                        disableClearable
                                        style={{ minWidth: 250, marginRight: 20 }}
                                        renderInput={(params) => <TextField {...params} label="Month" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.month}
                                    />
                                    <Autocomplete
                                        {...this.state.listPeriodeMR}
                                        id="periodeMR"
                                        onChange={(event, newInputValue) => this.setState({ periodeMR: newInputValue, loading: true }, () => {
                                            this.getListUserSubcoMR()
                                            // if (this.state.isApprover === true) {
                                            //         this.getCompanySubmitted()
                                            // } else {
                                                // this.setState({ visibleTableHistory: false })
                                                // this.getRevision()
                                            // }
                                        })}
                                        disableClearable
                                        style={{ width: 250 }}
                                        renderInput={(params) => <TextField {...params} label="Periode MR" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.periodeMR}
                                    />
                                </div>
                                <Paper style={{ width: 450, padding: 20, borderRadius: 10, marginTop: 5}}>
d.arizona's avatar
d.arizona committed
799
                                    <Typography style={{ fontWeight: 'bold', textDecorationLine: 'underline' }}>{`Monthly Report - ${bulan} ${tahun} ${this.state.valueSubmitMR}/${this.state.listSubcoMR.length}`}</Typography>
rifkaki's avatar
rifkaki committed
800 801 802 803 804 805
                                    {this.state.listSubcoMR.map((item, index) => {
                                        return (
                                            <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 10, paddingLeft: 10 }}>
                                                <div style={{ display: 'flex' }}>
                                                    <img src={item.is_submit === true ? Images.dotDone : item.is_overdue === true ? Images.dotOverdue : Images.dotOpen} />
                                                    <Link to={{
rifkaki's avatar
rifkaki committed
806
                                                        pathname: `/home/monthly-report/`,
rifkaki's avatar
rifkaki committed
807 808
                                                        state: {
                                                            userType: 'user',
d.arizona's avatar
d.arizona committed
809 810
                                                            rawData: item,
                                                            month: this.state.month
rifkaki's avatar
rifkaki committed
811 812 813 814 815 816 817 818 819 820 821 822 823
                                                        }
                                                    }}>
                                                        <button
                                                            style={{
                                                                backgroundColor: 'transparent',
                                                                cursor: 'pointer',
                                                                borderColor: 'transparent',
                                                                margin: 5,
                                                                outline: 'none'
                                                            }}>
                                                            <Typography style={{ marginLeft: 10, color: '#5198ea', fontSize: 13 }}>{item.company_name}</Typography>
                                                        </button>
                                                    </Link>
Deni Rinaldi's avatar
Deni Rinaldi committed
824
                                                </div>
rifkaki's avatar
rifkaki committed
825 826 827 828 829 830 831 832 833 834
                                                {item.is_overdue && (
                                                    <div style={{ backgroundColor: '#f65a4c', paddingRight: 5, paddingLeft: 5, borderRadius: 5, alignSelf: 'center' }}>
                                                        <Typography style={{ fontSize: 11, color: '#fff' }}>Overdue</Typography>
                                                    </div>
                                                )}
                                            </div>
                                        )
                                    })}
                                </Paper>
                            </div>
rifkaki's avatar
rifkaki committed
835
                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
836 837 838
                        </div>
                    </div>
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
839 840
            </div>
        );
841

Deni Rinaldi's avatar
Deni Rinaldi committed
842 843 844
    }
}

Deni Rinaldi's avatar
Deni Rinaldi committed
845
export default HomePage;