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

Faisal Hamdi's avatar
Faisal Hamdi committed
16
var ct = require("../../library/CustomTable");
d.arizona's avatar
d.arizona committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
const getMuiTheme = () => createMuiTheme(ct.customTable());

class ReportProgress extends Component {
    constructor(props) {
        super(props)
        this.state = {
            listApproval: null,
            listCategory: {
                options: [{ name: 'Report Status', value: 'report-status' }, { name: 'Approval Progress', value: 'approval-progress' }],
                getOptionLabel: (option) => option.name,
            },
            listReportType: null,
            listQuarter: {
                options: [{ name: 'Q1', value: 'q1' }, { name: 'Q2', value: 'q2' }, { name: 'Q3', value: 'q3' }],
                getOptionLabel: (option) => option.name,
            },
            listMonth: null,
            listPeriodeMB: null,
            quarter: {
                name: 'Q1', value: 'q1'
            },
            category: {
                name: 'Report Status', value: 'report-status'
            },
            month: null,
            periodeMB: null,
            reportType: null,
        }
    }

    componentDidMount() {
        this.getMonth()
        this.getReportType()
Faisal Hamdi's avatar
Faisal Hamdi committed
50 51
        // console.log(this.state.listCategory);
        // console.log(this.state.category);
d.arizona's avatar
d.arizona committed
52 53 54 55 56 57 58
    }

    getReportType() {
        let arrayReportType = [
            {
                name: 'Master Budget',
                value: 0
Faisal Hamdi's avatar
Faisal Hamdi committed
59
            }, {
d.arizona's avatar
d.arizona committed
60 61
                name: 'Monthly Report',
                value: 1
Faisal Hamdi's avatar
Faisal Hamdi committed
62
            }, {
d.arizona's avatar
d.arizona committed
63 64
                name: 'Operating Indicator',
                value: 2
Faisal Hamdi's avatar
Faisal Hamdi committed
65
            }, {
d.arizona's avatar
d.arizona committed
66 67 68 69 70
                name: 'Rolling Outlook',
                value: 3
            },
        ]

Faisal Hamdi's avatar
Faisal Hamdi committed
71
        let arrayReportTypeFinal = this.state.category.value.includes('status') ? arrayReportType : arrayReportType.filter((val) => val.value != 2)
d.arizona's avatar
d.arizona committed
72 73 74 75
        let defaultProps = {
            options: arrayReportTypeFinal,
            getOptionLabel: (option) => option.name,
        };
Faisal Hamdi's avatar
Faisal Hamdi committed
76
        this.setState({ listReportType: defaultProps, reportType: arrayReportTypeFinal[0] }, () => {
d.arizona's avatar
d.arizona committed
77
            console.log(this.state.listReportType)
Faisal Hamdi's avatar
Faisal Hamdi committed
78
            console.log(this.state.reportType)
d.arizona's avatar
d.arizona committed
79 80 81 82 83
        })
    }


    getMonth() {
Faisal Hamdi's avatar
Faisal Hamdi committed
84
        this.setState({ loading: true })
d.arizona's avatar
d.arizona committed
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
        api.create().getMonthTransaction().then(response => {
            let dateNow = new Date()
            dateNow.setMonth(dateNow.getMonth() - 1);
            let month = format(dateNow, 'MMMM')
            // console.log(month);
            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,
                    };
                    let index = data.findIndex((val) => val.month_name == month)
                    // 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") || 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' })
            }
        })
    }

    getPeriode() {
        let currentYear = new Date().getFullYear()
        let MB = []
        for (var i = 2000; i <= currentYear; i++) {
            MB.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,
        };

        this.setState({
            listPeriodeMB: defaultPropsMB,
            periodeMB: MB[MB.length - 1],
            loading: false
        }, () => {
            console.log(this.state.listMonth)
            console.log(this.state.listPeriodeMB)
        })
    }

    render() {
Faisal Hamdi's avatar
Faisal Hamdi committed
163

Faisal Hamdi's avatar
Faisal Hamdi committed
164
        const dataTableMB = [
Faisal Hamdi's avatar
Faisal Hamdi committed
165
            ['Tax Planning', '2', 'ABA: Anugerah Buminusantara Abadi', '2021-05-03'],
Faisal Hamdi's avatar
Faisal Hamdi committed
166
            ['CAT', '1', 'ABA: Anugerah Buminusantara Abadi', '2021-05-03'],
Faisal Hamdi's avatar
Faisal Hamdi committed
167 168
            ['Profit Loss', '0', 'ABA: Anugerah Buminusantara Abadi', '2021-05-03']
        ]
Faisal Hamdi's avatar
Faisal Hamdi committed
169 170 171 172 173 174 175

        const dataTableMBStatus = [
            ['ABA: Anugerah Buminusantara Abadi', '2021', 'approved', '2', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved'],
            ['ABA: Anugerah Buminusantara Abadi', '2021', 'approved', '1', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved'],
            ['ABA: Anugerah Buminusantara Abadi', '2021', 'approved', '0', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved']
        ]

d.arizona's avatar
d.arizona committed
176 177 178 179 180 181 182 183 184 185
        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>
        );
Faisal Hamdi's avatar
Faisal Hamdi committed
186

d.arizona's avatar
d.arizona committed
187 188 189 190 191 192 193
        return (
            <div style={{ flex: 1, backgroundColor: '#f8f8f8', minHeight: this.props.height }}>
                <div>
                    <div className={"main-color"} style={{ height: 78, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
                        <Typography style={{ fontSize: '16px', color: 'white' }}>Report Status & Approval Progress Monitoring</Typography>
                    </div>
                    <div style={{ padding: 20, width: '100%' }}>
Faisal Hamdi's avatar
Faisal Hamdi committed
194
                        <Paper style={{ paddingTop: 10, paddingBottom: 50 }}>
d.arizona's avatar
d.arizona committed
195 196 197 198 199 200 201 202 203 204 205
                            <div style={{ borderBottom: 'solid 1px #c4c4c4' }} >
                                <Typography style={{ fontSize: '12px', color: '#4b4b4b', margin: 10 }}>Report Status & Approval Progress</Typography>
                            </div>
                            <div style={{ minWidth: 'max-content', padding: '20px 20px 0px 20px' }}>
                                <div style={{ marginTop: 15, display: 'flex' }}>
                                    <Autocomplete
                                        {...this.state.listCategory}
                                        id="category"
                                        onChange={(event, newInputValue) => this.setState({ category: newInputValue, loading: true }, () => {
                                            // this.getListUserSubcoRO()
                                            this.getReportType()
Faisal Hamdi's avatar
Faisal Hamdi committed
206
                                            this.setState({ loading: false })
d.arizona's avatar
d.arizona committed
207 208 209 210 211 212 213 214 215 216 217
                                        })}
                                        disableClearable
                                        style={{ minWidth: 210, marginRight: 20 }}
                                        renderInput={(params) => <TextField {...params} label="Category" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.category}
                                    />
                                    <Autocomplete
                                        {...this.state.listReportType}
                                        id="report-type"
                                        onChange={(event, newInputValue) => this.setState({ reportType: newInputValue, loading: true }, () => {
                                            // this.getListUserSubcoRO()
Faisal Hamdi's avatar
Faisal Hamdi committed
218
                                            this.setState({ loading: false })
d.arizona's avatar
d.arizona committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
                                        })}
                                        disableClearable
                                        style={{ minWidth: 210, marginRight: 20 }}
                                        renderInput={(params) => <TextField {...params} label="Report Type" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.reportType}
                                    />
                                </div>
                            </div>
                            <div style={{ minWidth: 'max-content', padding: '20px 20px 0px 20px' }}>
                                <div style={{ marginTop: 15, display: 'flex' }}>
                                    <Autocomplete
                                        {...this.state.listPeriodeMB}
                                        id="periode"
                                        onChange={(event, newInputValue) => this.setState({ periodeMB: newInputValue, loading: true }, () => {
                                            // this.getListUserSubcoRO()
Faisal Hamdi's avatar
Faisal Hamdi committed
234
                                            this.setState({ loading: false })
d.arizona's avatar
d.arizona committed
235 236 237 238 239 240 241 242 243 244 245
                                        })}
                                        disableClearable
                                        style={{ minWidth: 210, marginRight: 20 }}
                                        renderInput={(params) => <TextField {...params} label="Periode" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.periodeMB}
                                    />
                                    {this.state.reportType != null && this.state.reportType.value == 1 && <Autocomplete
                                        {...this.state.listMonth}
                                        id="month"
                                        onChange={(event, newInputValue) => this.setState({ month: newInputValue, loading: true }, () => {
                                            // this.getListUserSubcoRO()
Faisal Hamdi's avatar
Faisal Hamdi committed
246
                                            this.setState({ loading: false })
d.arizona's avatar
d.arizona committed
247 248 249 250 251 252 253 254 255 256 257
                                        })}
                                        disableClearable
                                        style={{ minWidth: 210, marginRight: 20 }}
                                        renderInput={(params) => <TextField {...params} label="Month" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.month}
                                    />}
                                    {this.state.reportType != null && this.state.reportType.value == 3 && <Autocomplete
                                        {...this.state.listQuarter}
                                        id="quarter"
                                        onChange={(event, newInputValue) => this.setState({ quarter: newInputValue, loading: true }, () => {
                                            // this.getListUserSubcoRO()
Faisal Hamdi's avatar
Faisal Hamdi committed
258
                                            this.setState({ loading: false })
d.arizona's avatar
d.arizona committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
                                        })}
                                        disableClearable
                                        style={{ minWidth: 210, marginRight: 20 }}
                                        renderInput={(params) => <TextField {...params} label="Quarter" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.quarter}
                                    />}
                                </div>
                            </div>
                            <div style={{ marginTop: 20, marginBottom: 20 }}>
                                {/* <div style={{ display: 'flex', justifyContent: 'space-between', padding: '0px 20px 10px 20px' }}>
                                    <div></div>
                                    {this.state.previewDownload && (
                                        <div style={{ width: '50%', justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
                                            <a data-tip={'Download'} data-for="download">
                                                <button
                                                    style={{
                                                        backgroundColor: 'transparent',
                                                        cursor: 'pointer',
                                                        borderColor: 'transparent',
                                                        margin: 5,
                                                        outline: 'none'
                                                    }}
                                                    onClick={() => this.setState({ loading: true }, () => {
                                                        setTimeout(() => {
                                                            this.downloadAllData()
                                                        }, 100);
                                                    })}
                                                >
                                                    <img src={Images.download} />
                                                </button>
                                            </a>
                                            <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
                                        </div>
                                    )}
                                </div> */}
                                {this.state.loading && loadingComponent}
Faisal Hamdi's avatar
Faisal Hamdi committed
295
                                {/* {this.state.previewTable && ( */}
Faisal Hamdi's avatar
Faisal Hamdi committed
296 297 298 299 300 301 302
                                <TableProgressReport
                                    width={this.props.width}
                                    height={this.props.height}
                                    open={this.props.open}
                                    // month={this.state.month.month_value}
                                    category={this.state.category ? this.state.category.value : 1}
                                    reportType={this.state.reportType ? this.state.reportType.value : 0}
Faisal Hamdi's avatar
Faisal Hamdi committed
303
                                    dataTable={this.state.category.value == 'report-status' ? dataTableMBStatus : dataTableMB}
Faisal Hamdi's avatar
Faisal Hamdi committed
304 305 306 307 308
                                    // dataTable={this.state.dataTable}
                                    periode={this.state.periode ? this.state.periode.periode : null}
                                    quarter={this.state.quarter.name}
                                    company={this.state.company}
                                />
Faisal Hamdi's avatar
Faisal Hamdi committed
309
                                {/* )} */}
d.arizona's avatar
d.arizona committed
310 311 312 313 314 315 316 317 318 319 320
                            </div>
                        </Paper>
                    </div>
                </div>
            </div>
        );

    }
}

export default ReportProgress;