OperatingIndicator.js 23.2 KB
Newer Older
EKSAD's avatar
EKSAD committed
1 2 3
import React, { Component } from 'react';
import { Typography, Paper, TextField, MenuItem, Select, FormControlLabel } from '@material-ui/core';
import MUIDataTable from 'mui-datatables';
d.arizona's avatar
d.arizona committed
4 5 6
import Images from '../../assets/Images';
import OperatingIndicatorDetail from './OperatingIndicatorDetail'
import api from '../../api';
EKSAD's avatar
EKSAD committed
7
import Autocomplete from '@material-ui/lab/Autocomplete';
d.arizona's avatar
d.arizona committed
8
import { titleCase } from '../../library/Utils';
EKSAD's avatar
EKSAD committed
9
import { ExcelRenderer } from 'react-excel-renderer';
d.arizona's avatar
d.arizona committed
10
import UploadFile from "../../library/Upload";
EKSAD's avatar
EKSAD committed
11 12 13 14 15 16 17 18 19 20
import { format } from 'date-fns';

export default class OperatingIndicator extends Component {
    constructor(props) {
        super(props)
        this.state = {
            perusahaan: 'TAP Group',
            listRevision: null,
            revision: null,
            visibleOperatingIndicator: true,
d.arizona's avatar
d.arizona committed
21
            visibleDetailOpt: false,
EKSAD's avatar
EKSAD committed
22 23 24 25 26 27
            listPeriode: null,
            periode: null,
            listCompany: null,
            company: null,
            report_id: null,
            listAttachment: [],
d.arizona's avatar
d.arizona committed
28 29
            visibleUpload: false,
            submissionID: null
EKSAD's avatar
EKSAD committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        }
        this.fileHandler = this.fileHandler.bind(this);
    }

    componentDidMount() {
        this.getCompanyActive()
    }

    getReportAttachment() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
            "revision": this.state.revision.revision,
        }
        api.create().getMasterBudgetAtt(payload).then(response => {
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({ listAttachment: response.data.data })
                }
            }
            // console.log(response);
        })
    }

    getReport() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
d.arizona's avatar
d.arizona committed
58
            "report_type": "operating indicator",
EKSAD's avatar
EKSAD committed
59
        }
d.arizona's avatar
d.arizona committed
60 61
        api.create().getAllOperatingInd(payload).then(response => {
            console.log(response);
EKSAD's avatar
EKSAD committed
62 63 64 65 66 67
            if (response.data) {
                if (response.data.status === "success") {
                    let dataTable = response.data.data.map((item, index) => {
                        return [
                            item.number,
                            item.report_name,
d.arizona's avatar
d.arizona committed
68
                            // item.revision,
EKSAD's avatar
EKSAD committed
69 70 71
                            item.current_status,
                            item.report_id,
                            item.is_can_upload,
d.arizona's avatar
d.arizona committed
72
                            // item.revision
EKSAD's avatar
EKSAD committed
73 74 75
                        ]
                    })
                    // console.log(dataTable);
d.arizona's avatar
d.arizona committed
76
                    this.setState({ dataTable, dataReport: response.data.data})
EKSAD's avatar
EKSAD 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
                }
            }
        })
    }

    getCompanyActive() {
        api.create().getPerusahaanActive().then((response) => {
            if (response.data.status === 'success') {
                let data = response.data.data
                let companyData = data.map((item) => {
                    return {
                        company_id: item.company_id,
                        company_name: item.company_name,
                    }
                })
                let defaultProps = {
                    options: companyData,
                    getOptionLabel: (option) => titleCase(option.company_name),
                };
                this.setState({ listCompany: defaultProps, company: companyData[0] }, () => {
                    this.getPeriode()
                })
            } else {
                alert(response.data.message)
            }
        })
    }

    getPeriode() {
        api.create().getPeriodeTransaction().then(response => {
            let dateNow = new Date
            let year = format(dateNow, 'yyyy')
            if (response.data) {
                if (response.data.status === "success") {
                    let data = response.data.data
                    let periodeData = data.map((item) => {
                        return {
                            periode: item,
                        }
                    })
                    let defaultProps = {
                        options: periodeData,
                        getOptionLabel: (option) => option.periode,
                    };
                    let index = data.sort((a, b) => a - b).findIndex((val) => val == year)
                    this.setState({ listPeriode: defaultProps, periode: index == -1 ? periodeData[0] : periodeData[index] }, () => {
d.arizona's avatar
d.arizona committed
123 124
                        this.getReport()
                        this.getSubmission()
EKSAD's avatar
EKSAD committed
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
                    })
                }
            }
        })
    }

    getRevision() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode
        }
        api.create().getRevision(payload).then(response => {
            console.log(response);
            if (response.data) {
                if (response.data.status === "success") {
                    let data = response.data.data
                    let revisionData = data.map((item) => {
                        return {
                            revision: item,
                        }
                    })
                    let defaultProps = {
                        options: revisionData,
                        getOptionLabel: (option) => option.revision,
                    };
                    this.setState({ listRevision: defaultProps, revision: revisionData[0] }, () => {
                        this.getReport()
                        this.getReportAttachment()
                    })
                }
            }
        })
    }

d.arizona's avatar
d.arizona committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
    getSubmission() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode
        }
        api.create().getSubmission(payload).then(response => {
            if (response) {
                if (response.data.data) {
                    this.setState({ submissionID: response.data.data.submission_id })
                } else {
                    this.setState({ submissionID: null })
                }
            }
        })
    }

EKSAD's avatar
EKSAD committed
175
    clickDetail(item, id) {
d.arizona's avatar
d.arizona committed
176 177
        let index = this.state.dataReport.findIndex((val) => val.report_name == item[1])
        if (index !== -1) {
EKSAD's avatar
EKSAD committed
178
            this.setState({
d.arizona's avatar
d.arizona committed
179
                dataDetail: {...this.state.dataReport[index], periode: this.state.periode.periode, submissionID: this.state.submissionID, company: this.state.company},
EKSAD's avatar
EKSAD committed
180
                visibleOperatingIndicator: false,
d.arizona's avatar
d.arizona committed
181
                visibleDetailOpt: true,
EKSAD's avatar
EKSAD committed
182
            })
d.arizona's avatar
d.arizona committed
183
        }
EKSAD's avatar
EKSAD committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
    }

    handleChange(value, tableMeta) {
        let data = this.state.dataTable
        data[tableMeta.rowIndex][tableMeta.columnIndex] = value
    }

    fileHandler = (event) => {
        let fileObj = event
        ExcelRenderer(fileObj, (err, resp) => {
            // console.log(resp)
            if (err) {
                console.log(err);
            }
            else {
                const formData = new FormData();
                formData.append("revision", Number(this.state.revision.revision));
                formData.append("companyId", this.state.company.company_id);
                formData.append("periode", Number(this.state.periode.periode));
                formData.append("file", event);
                this.setState({ formData })
            }
        })
    }

    uploadAttachment(formData) {
        api.create().uploadAttachment(formData).then(response => {
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({ visibleUpload: false }, () => {
                        this.getReport()
                        this.getReportAttachment()
                    })
                }
            }
            // console.log(response)
        })
    }

    render() {
        const columns = ["#", "Jenis Laporan",
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
            // {
            //     name: "Revision",
            //     options: {
            //         customBodyRender: (val, tableMeta, updateValue) => {
            //             var list = [];
            //             for (var i = 0; i <= tableMeta.rowData[6]; i++) {
            //                 list.push(i);
            //             }
            //             return (
            //                 <div style={{ display: 'flex' }}>
            //                     <FormControlLabel
            //                         style={{ margin: 0 }}
            //                         value={val}
            //                         control={
            //                             <Select
            //                                 value={val}
            //                                 onChange={event => {
            //                                     // console.log(event.target)
            //                                     updateValue(event.target.value)
            //                                     this.handleChange(event.target.value, tableMeta)
            //                                 }}
            //                                 autoWidth
            //                             >
            //                                 {list.map((item, index) =>
            //                                     <MenuItem key={index} value={item}>{item}</MenuItem>
            //                                 )}
            //                             </Select>
            //                         }
            //                     />
            //                 </div >
            //             );
            //         }
            //     }
            // }, 
EKSAD's avatar
EKSAD 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
            {
                name: "Status",
                options: {
                    customBodyRender: (val, tableMeta) => {
                        return (
                            <div style={{ display: 'flex' }}>
                                {val === "submitted" || val === "approved" ?
                                    <img src={Images.ceklis} style={{ width: 31, height: 24 }} /> :
                                    val === "revision" ? 
                                    <span>Revisi</span> :
                                    null
                                }
                            </div >
                        );
                    }
                }
            },
            {
                name: "Action",
                options: {
                    customBodyRender: (val, tableMeta) => {
                        return (
                            <div style={{ display: 'flex' }}>
                                <button
                                    style={{
                                        backgroundColor: 'transparent',
                                        cursor: tableMeta.rowData[5] ? 'pointer' : null,
                                        borderColor: 'transparent'
                                    }}
                                    onClick={() =>
d.arizona's avatar
d.arizona committed
289
                                        tableMeta.rowData[4] ? this.clickDetail(tableMeta.rowData) : null
EKSAD's avatar
EKSAD committed
290 291 292 293 294 295 296 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 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
                                    }
                                >
                                    <Typography style={{ color: tableMeta.rowData[5] ? '#5198ea' : 'GrayText', fontSize: 12, }}>Detail</Typography>
                                </button>
                            </div >
                        );
                    }
                }
            }, {
                name: "",
                options: { display: false }
            }, {
                name: "",
                options: { display: false }
            }]
        const options = {
            filter: false,
            sort: false,
            responsive: "scroll",
            print: false,
            download: false,
            selectableRows: false,
            viewColumns: false,
            rowsPerPage: 5,
            rowsPerPageOptions: [5, 25, 100],
            search: false
        }
        const periode = [
            { value: '2021', label: '2021' },
            { value: '2020', label: '2020' },
            { value: '2019', label: '2019' },
            { value: '2018', label: '2018' },
            { value: '2017', label: '2017' },
            { value: '2016', label: '2016' },
        ]
        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 revisi = [
            { value: '0', label: '0' },
            { value: '1', label: '1' },
        ]
        return (
            <div style={{ flex: 1, backgroundColor: '#f8f8f8' }}>
                {this.state.visibleOperatingIndicator && (
                    <div>
                        <div className={"main-color"} style={{ height: 78, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
                            <Typography style={{ fontSize: '16px', color: 'white' }}>Operating Indicator</Typography>
                        </div>
                        <div style={{ padding: 20, width: '100%' }}>
                            <Paper style={{ paddingTop: 10 }}>
                                <div style={{ borderBottom: 'solid 1px #c4c4c4' }} >
                                    <Typography style={{ fontSize: '12px', color: '#4b4b4b', margin: 10 }}>Operating Indicator</Typography>
                                </div>
                                <div style={{ padding: 20 }}>
                                    <div>
                                        <Autocomplete
                                            {...this.state.listPeriode}
                                            id="periode"
                                            onChange={(event, newInputValue) => this.setState({ periode: newInputValue }, () => {
                                                this.getReport()
d.arizona's avatar
d.arizona committed
355 356
                                                this.getSubmission()
                                                // this.getReportAttachment()
EKSAD's avatar
EKSAD committed
357 358 359 360 361 362 363 364 365 366 367 368 369 370
                                            })}
                                            debug
                                            disableClearable
                                            style={{ width: 250 }}
                                            renderInput={(params) => <TextField {...params} label="Periode" margin="normal" style={{ marginTop: 7 }} />}
                                            value={this.state.periode}
                                        />
                                    </div>
                                    <div style={{ marginTop: 20 }}>
                                        <Autocomplete
                                            {...this.state.listCompany}
                                            id="company"
                                            onChange={(event, newInputValue) => this.setState({ company: newInputValue }, () => {
                                                this.getReport()
d.arizona's avatar
d.arizona committed
371 372
                                                this.getSubmission()
                                                // this.getReportAttachment()
EKSAD's avatar
EKSAD committed
373 374 375 376 377 378 379 380
                                            })}
                                            debug
                                            disableClearable
                                            style={{ width: 250 }}
                                            renderInput={(params) => <TextField {...params} label="Company" margin="normal" style={{ marginTop: 7 }} />}
                                            value={this.state.company}
                                        />
                                    </div>
d.arizona's avatar
d.arizona committed
381
                                    {/* <div style={{ marginTop: 20 }}>
EKSAD's avatar
EKSAD committed
382 383 384 385 386 387 388 389 390 391 392 393 394
                                        <Autocomplete
                                            {...this.state.listRevision}
                                            id="revision"
                                            onChange={(event, newInputValue) => this.setState({ revision: newInputValue }, () => {
                                                this.getReport()
                                                this.getReportAttachment()
                                            })}
                                            debug
                                            disableClearable
                                            style={{ width: 250 }}
                                            renderInput={(params) => <TextField {...params} label="Revision" margin="normal" style={{ marginTop: 7 }} />}
                                            value={this.state.revision}
                                        />
d.arizona's avatar
d.arizona committed
395
                                    </div> */}
EKSAD's avatar
EKSAD committed
396 397 398 399 400 401 402 403

                                    <div style={{ marginTop: 20 }}>
                                        <MUIDataTable
                                            data={this.state.dataTable}
                                            columns={columns}
                                            options={options}
                                        />
                                    </div>
d.arizona's avatar
d.arizona committed
404
                                    {/* <div style={{ display: 'flex', marginTop: 20 }}>
EKSAD's avatar
EKSAD committed
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
                                        <div style={{ width: '50%' }}>
                                            <Typography style={{ fontSize: '16px', color: '#4b4b4b', fontWeight: 'bold' }}>Attachment: </Typography>
                                        </div>
                                        <div style={{ width: '50%' }}>
                                            <button
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    outline: 'none'
                                                }}
                                                onClick={() => this.setState({ visibleUpload: true })}
                                            >
                                                <Typography style={{ fontSize: '16px', color: '#5198ea' }}>Upload File</Typography>
                                            </button>
                                        </div>
                                    </div>
                                    <div style={{ display: 'flex', marginTop: 10 }}>
                                        <div style={{ width: '50%', paddingLeft: 20 }}>
                                            {this.state.listAttachment.length > 0 ?
                                                this.state.listAttachment.map((item) => {
                                                    return (
                                                        <Typography style={{ fontSize: '16px', color: '#4b4b4b' }}>{item.attachment_name}</Typography>
                                                    )
                                                })
                                                : null
                                            }
                                        </div>
                                        <div style={{ width: '50%' }}>
                                            {this.state.listAttachment.length > 0 ?
                                                this.state.listAttachment.map((item) => {
                                                    return (
                                                        <Typography style={{ fontSize: '16px', color: '#ff3939' }}>Delete</Typography>
                                                    )
                                                })
                                                : null
                                            }
                                        </div>
d.arizona's avatar
d.arizona committed
443
                                    </div> */}
EKSAD's avatar
EKSAD committed
444 445 446 447 448 449 450 451 452 453 454 455
                                </div>
                                <div style={{ borderTop: 'solid 1px #c4c4c4', padding: 10, backgroundColor: '#f5f5f5', width: '100%', display: 'flex', justifyContent: 'flex-end' }} >
                                    <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                        <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Submit</Typography>
                                    </div>
                                </div>
                            </Paper>

                        </div>
                    </div>
                )}

d.arizona's avatar
d.arizona committed
456 457 458 459 460 461 462 463 464
                {this.state.visibleDetailOpt && 
                    <OperatingIndicatorDetail
                        data={this.state.dataDetail}
                        height={this.props.height}
                        width={this.props.width}
                        onClickClose={() => this.setState({ visibleDetailOpt: false, visibleOperatingIndicator: true }, this.forceUpdate())}
                    />
                }

EKSAD's avatar
EKSAD committed
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
                {this.state.visibleUpload && (
                    <div className="test app-popup-show">
                        <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
                            <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
                                <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                                    <div className="popup-title">
                                        <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Upload File</span>
                                    </div>
                                </div>
                                <div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
                                    <button
                                        type="button"
                                        className="btn btn-circle btn-white"
                                        onClick={() => this.setState({ visibleUpload: false })}
                                    >
                                        <img src={Images.close} />
                                    </button>
                                </div>
                            </div>
                            <UploadFile
                                type={this.state.uploadStatus}
                                percentage={this.state.percentage}
                                result={this.state.result}
                                acceptedFiles={["xlsx"]}
                                onHandle={(dt) => {
                                    this.fileHandler(dt)
                                    this.setState({ uploadStatus: 'idle', percentage: '0' })
                                }}
                                onUpload={() => this.uploadAttachment(this.state.formData)}
                            />
                        </div>
                    </div>
                )}
            </div >
        );
    }
}