OperatingIndicator.js 56.7 KB
Newer Older
EKSAD's avatar
EKSAD committed
1
import React, { Component } from 'react';
qorri_di's avatar
qorri_di committed
2
import { Typography, Paper, TextField, MenuItem, Select, FormControlLabel, createMuiTheme, withStyles, Checkbox, MuiThemeProvider } from '@material-ui/core';
EKSAD's avatar
EKSAD committed
3
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';
EKSAD's avatar
EKSAD committed
8
import MuiAlert from '@material-ui/lab/Alert';
d.arizona's avatar
d.arizona committed
9
import { titleCase } from '../../library/Utils';
EKSAD's avatar
EKSAD committed
10
import { ExcelRenderer } from 'react-excel-renderer';
d.arizona's avatar
d.arizona committed
11
import UploadFile from "../../library/Upload";
EKSAD's avatar
EKSAD committed
12
import { format } from 'date-fns';
EKSAD's avatar
EKSAD committed
13
import Constant from '../../library/Constant';
Riri Novita's avatar
Riri Novita committed
14
import OperatingIndicatorMR from '../MonthlyReport/OperatingIndicatorMR';
Riri Novita's avatar
Riri Novita committed
15
import OperatingIndicatorRO from '../RollingOutlook/OperatingIndicatorRO';
qorri_di's avatar
qorri_di committed
16 17
import { PhotoSizeSelectLargeTwoTone, ThreeSixty } from '@material-ui/icons';
import { startTransition } from 'react';
EKSAD's avatar
EKSAD committed
18

d.arizona's avatar
d.arizona committed
19 20 21
var ct = require("../../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable());

EKSAD's avatar
EKSAD committed
22 23 24
const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);

qorri_di's avatar
qorri_di committed
25 26 27 28 29 30 31 32 33 34
const CustomCheckbox = withStyles({
    root: {
        color: '#5198ea',
        '&$checked': {
            color: '#5198ea',
        },
    },
    checked: {},
})((props) => <Checkbox color="default" {...props} />);

EKSAD's avatar
EKSAD committed
35 36 37 38 39 40 41 42
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
43
            visibleDetailOpt: false,
Riri Novita's avatar
Riri Novita committed
44 45
            visibleDetailMonthly: false,
            visibleDetailRolling: false,
EKSAD's avatar
EKSAD committed
46 47
            listPeriode: null,
            periode: null,
Riri Novita's avatar
Riri Novita committed
48
            month: null,
qorri_di's avatar
qorri_di committed
49
            quartal: null,
EKSAD's avatar
EKSAD committed
50 51 52 53
            listCompany: null,
            company: null,
            report_id: null,
            listAttachment: [],
d.arizona's avatar
d.arizona committed
54
            visibleUpload: false,
EKSAD's avatar
EKSAD committed
55 56 57
            operatingIndID: null,
            alert: false,
            tipeAlert: '',
d.arizona's avatar
d.arizona committed
58 59 60
            messageAlert: '',
            buttonCreate: true,
            buttonEdit: true,
Deni Rinaldi's avatar
Deni Rinaldi committed
61 62
            buttonDelete: true,
            lastPeriod: '',
d.arizona's avatar
d.arizona committed
63
            latestPeriode: '',
qorri_di's avatar
qorri_di committed
64 65 66 67 68 69
            statusDetail: '',
            selectReport: [],
            isCheckAll: false,
            downloadedFileReportId: null,
            arrayReport: [],
            popupDownload: false
EKSAD's avatar
EKSAD committed
70 71 72 73 74
        }
        this.fileHandler = this.fileHandler.bind(this);
    }

    componentDidMount() {
EKSAD's avatar
EKSAD committed
75
        this.getDetailUser()
d.arizona's avatar
d.arizona committed
76 77 78 79 80 81 82 83
        this.getPermission()
    }

    getPermission() {
        let payload = {
            menu: "operating indicator"
        }
        api.create().getPermission(payload).then(response => {
Riri Novita's avatar
Riri Novita committed
84
            console.log(response)
d.arizona's avatar
d.arizona committed
85 86 87 88 89 90 91 92 93
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({
                        buttonCreate: response.data.data.create,
                        buttonEdit: response.data.data.edit,
                        buttonDelete: response.data.data.delete,
                        load: true
                    })
                } else {
Riri Novita's avatar
Riri Novita committed
94
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
95
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
96 97 98 99 100 101
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
d.arizona's avatar
d.arizona committed
102 103 104 105 106 107
                }
            }
        })
    }

    getLastPeriod() {
Riri Novita's avatar
Riri Novita committed
108
        api.create().getLastPeriodOI(this.state.company.company_id).then(response => {
EKSAD's avatar
EKSAD committed
109
            // console.log(response);
d.arizona's avatar
d.arizona committed
110 111 112 113 114 115
            if (response.data.status === "success") {
                this.setState({ lastPeriod: response.data.data.last_periode, latestPeriode: response.data.data.latest_periode }, () => {
                    this.getPeriode()
                })
            }
        })
EKSAD's avatar
EKSAD committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129
    }

    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 })
                }
            }
EKSAD's avatar
EKSAD committed
130
            // console.log(response);
EKSAD's avatar
EKSAD committed
131 132 133 134 135 136 137
        })
    }

    getReport() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
d.arizona's avatar
d.arizona committed
138
            "report_type": "operating indicator",
EKSAD's avatar
EKSAD committed
139
        }
Riri Novita's avatar
Riri Novita committed
140
        console.log(payload);
d.arizona's avatar
d.arizona committed
141
        api.create().getAllOperatingInd(payload).then(response => {
Riri Novita's avatar
Riri Novita committed
142
            console.log(response);
EKSAD's avatar
EKSAD committed
143 144 145 146 147 148
            if (response.data) {
                if (response.data.status === "success") {
                    let dataTable = response.data.data.map((item, index) => {
                        return [
                            item.number,
                            item.report_name,
Riri Novita's avatar
Riri Novita committed
149
                            item.current_status === 'closed' ? "CLOSED" : item.current_status,
EKSAD's avatar
EKSAD committed
150
                            item.report_id,
EKSAD's avatar
EKSAD committed
151
                            item.is_can_upload
EKSAD's avatar
EKSAD committed
152 153
                        ]
                    })
EKSAD's avatar
EKSAD committed
154
                    // console.log(dataTable);
Deni Rinaldi's avatar
Deni Rinaldi committed
155
                    this.setState({ dataTable, dataReport: response.data.data })
Riri Novita's avatar
Riri Novita committed
156 157
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
158
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
159 160 161 162 163 164
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
EKSAD's avatar
EKSAD committed
165
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
166
            }
EKSAD's avatar
EKSAD committed
167 168 169
        })
    }

EKSAD's avatar
EKSAD committed
170 171 172 173 174 175
    getDetailUser() {
        let userId = localStorage.getItem(Constant.USER)
        api.create().getDetailUser(userId).then((response) => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
Deni Rinaldi's avatar
Deni Rinaldi committed
176
                        this.setState({ userCompany: response.data.data.company }, () => {
EKSAD's avatar
EKSAD committed
177
                            this.getCompanyActive()
Deni Rinaldi's avatar
Deni Rinaldi committed
178
                        })
Riri Novita's avatar
Riri Novita committed
179 180
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
181
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
182 183 184 185 186 187
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
EKSAD's avatar
EKSAD committed
188 189
                    }
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
190
            }
EKSAD's avatar
EKSAD committed
191 192 193
        })
    }

EKSAD's avatar
EKSAD committed
194 195
    getCompanyActive() {
        api.create().getPerusahaanActive().then((response) => {
EKSAD's avatar
EKSAD committed
196 197 198
            if (response.data) {
                if (response.data.status === 'success') {
                    let data = response.data.data
d.arizona's avatar
d.arizona committed
199 200 201 202
                    let compActive = []
                    let userCompActive = []
                    this.state.userCompany.map((item, index) => {
                        let indeks = data.findIndex((val) => val.company_id == item)
Deni Rinaldi's avatar
Deni Rinaldi committed
203
                        if (indeks !== -1 && String(data[indeks].status).toLocaleLowerCase() == 'active') {
d.arizona's avatar
d.arizona committed
204 205 206 207
                            userCompActive.push(item)
                        }
                    })

Deni Rinaldi's avatar
Deni Rinaldi committed
208
                    data.map((item, index) => {
d.arizona's avatar
d.arizona committed
209 210 211 212 213
                        if (String(item.status).toLocaleLowerCase() == 'active') {
                            compActive.push(item)
                        }
                    })

Deni Rinaldi's avatar
Deni Rinaldi committed
214 215
                    if (compActive.length == userCompActive.length) {
                        this.setState({ superUser: false })
d.arizona's avatar
d.arizona committed
216
                    } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
217
                        this.setState({ superUser: true })
d.arizona's avatar
d.arizona committed
218 219
                    }

EKSAD's avatar
EKSAD committed
220 221 222 223 224 225
                    let companyData = data.map((item) => {
                        return {
                            company_id: item.company_id,
                            company_name: item.company_name,
                        }
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
226

EKSAD's avatar
EKSAD committed
227
                    let arrayBaru = []
Deni Rinaldi's avatar
Deni Rinaldi committed
228
                    this.state.userCompany.map((item, index) => {
EKSAD's avatar
EKSAD committed
229 230 231 232 233
                        let indexID = companyData.findIndex((val) => val.company_id == item)
                        if (indexID !== -1) {
                            arrayBaru.push(companyData[indexID])
                        }
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
234

d.arizona's avatar
d.arizona committed
235
                    if (arrayBaru.length > 0) {
Riri Novita's avatar
Riri Novita committed
236
                        arrayBaru = arrayBaru.sort((a, b) => a.company_name.localeCompare(b.company_name))
d.arizona's avatar
d.arizona committed
237 238
                    }

EKSAD's avatar
EKSAD committed
239 240 241 242
                    let defaultProps = {
                        options: arrayBaru,
                        getOptionLabel: (option) => titleCase(option.company_name),
                    };
Deni Rinaldi's avatar
Deni Rinaldi committed
243 244

                    this.setState({ listCompany: defaultProps, company: arrayBaru.length < 1 ? companyData[0] : arrayBaru[0] }, () => {
Riri Novita's avatar
Riri Novita committed
245
                        this.getLastPeriod()
EKSAD's avatar
EKSAD committed
246 247 248
                    })
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
249
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
EKSAD's avatar
EKSAD committed
250 251 252 253 254 255 256
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
EKSAD's avatar
EKSAD committed
257
            } else {
EKSAD's avatar
EKSAD committed
258
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listCompany: null, company: null })
EKSAD's avatar
EKSAD committed
259 260 261 262 263 264 265 266
            }
        })
    }

    getPeriode() {
        api.create().getPeriodeTransaction().then(response => {
            let dateNow = new Date
            let year = format(dateNow, 'yyyy')
d.arizona's avatar
d.arizona committed
267
            let currentYear = new Date().getFullYear()
EKSAD's avatar
EKSAD committed
268 269
            if (response.data) {
                if (response.data.status === "success") {
d.arizona's avatar
d.arizona committed
270 271 272 273 274 275
                    let data = []
                    response.data.data.map((item) => {
                        if (this.state.isApprover) {
                            if (item >= 2000 && item <= (Number(currentYear) + 1)) {
                                data.push(item)
                            }
EKSAD's avatar
EKSAD committed
276
                            // console.log('bibim')
d.arizona's avatar
d.arizona committed
277 278 279 280
                        } else {
                            if ((item >= 2000) && (item == this.state.lastPeriod || item < this.state.lastPeriod)) {
                                data.push(item)
                            }
EKSAD's avatar
EKSAD committed
281
                            // console.log('bubum')
d.arizona's avatar
d.arizona committed
282 283
                        }
                    })
EKSAD's avatar
EKSAD committed
284 285 286
                    // console.log(this.state.lastPeriod)
                    // console.log(this.state.lastPeriod)
                    // console.log(this.state.isApprover)
EKSAD's avatar
EKSAD committed
287 288 289 290 291 292 293 294 295
                    let periodeData = data.map((item) => {
                        return {
                            periode: item,
                        }
                    })
                    let defaultProps = {
                        options: periodeData,
                        getOptionLabel: (option) => option.periode,
                    };
EKSAD's avatar
EKSAD committed
296
                    // console.log(defaultProps)
Deni Rinaldi's avatar
Deni Rinaldi committed
297
                    let periode = (this.state.lastPeriod == "" ? String(Number(currentYear) + 1) : this.state.lastPeriod)
d.arizona's avatar
d.arizona committed
298
                    let index = data.sort((a, b) => a - b).findIndex((val) => val === periode)
EKSAD's avatar
EKSAD committed
299
                    this.setState({ listPeriode: defaultProps, periode: index == -1 ? periodeData[0] : periodeData[index] }, () => {
d.arizona's avatar
d.arizona committed
300
                        this.getOperatingID()
EKSAD's avatar
EKSAD committed
301 302 303 304 305 306
                    })
                }
            }
        })
    }

d.arizona's avatar
d.arizona committed
307
    getOperatingID() {
qorri_di's avatar
qorri_di committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
        this.setState({ selectReport: [], isCheckAll: false }, () => {
            let payload = {
                "company_id": this.state.company.company_id,
                "periode": this.state.periode.periode
            }
            api.create().getOpetratingIndID(payload).then(response => {
                console.log(response);
                if (response) {
                    // console.log(response.data.data)
                    this.getLatestPeriodSubmit()
                    if (response.data.data) {
                        this.setState({ operatingIndID: response.data.data.operating_indicator_id })
                    } else {
                        this.setState({ operatingIndID: null })
                    }
d.arizona's avatar
d.arizona committed
323
                } else {
qorri_di's avatar
qorri_di committed
324 325 326 327 328 329 330 331
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
d.arizona's avatar
d.arizona committed
332
                }
qorri_di's avatar
qorri_di committed
333
            })
d.arizona's avatar
d.arizona committed
334 335 336
        })
    }

d.arizona's avatar
d.arizona committed
337 338 339 340 341
    getLatestPeriodSubmit() {
        let body = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
342
        api.create().getSubmitOI(body).then(response => {
EKSAD's avatar
EKSAD committed
343
            // console.log(response);
d.arizona's avatar
d.arizona committed
344 345 346
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({ isSubmit: response.data.data.is_can_submit }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
347
                        this.getReport()
d.arizona's avatar
d.arizona committed
348 349 350 351 352 353 354
                        // this.getOperatingID()
                    })
                }
            }
        })
    }

EKSAD's avatar
EKSAD committed
355
    clickDetail(item, id) {
d.arizona's avatar
d.arizona committed
356 357
        let index = this.state.dataReport.findIndex((val) => val.report_name == item[1])
        if (index !== -1) {
Riri Novita's avatar
Riri Novita committed
358 359 360 361 362 363 364 365 366 367 368 369 370 371
            // this.setState({
            //     statusDetail: String(item[2]).toLocaleLowerCase(),
            //     dataDetail: { ...this.state.dataReport[index], periode: this.state.periode.periode, operatingIndID: this.state.operatingIndID, company: this.state.company },
            //     visibleOperatingIndicator: false,
            //     visibleDetailOpt: true,
            // })
            if (String(item[1]).toLocaleLowerCase().includes("master budget")) {
                this.setState({
                    statusDetail: String(item[2]).toLocaleLowerCase(),
                    dataDetail: { ...this.state.dataReport[index], periode: this.state.periode.periode, operatingIndID: this.state.operatingIndID, company: this.state.company },
                    visibleOperatingIndicator: false,
                    visibleDetailOpt: true,
                    visibleDetailMonthly: false,
                    visibleDetailRolling: false
Riri Novita's avatar
Riri Novita committed
372

Riri Novita's avatar
Riri Novita committed
373 374
                })
            } else if (String(item[1]).toLocaleLowerCase().includes("monthly report")) {
Riri Novita's avatar
Riri Novita committed
375
                console.log(item);
Riri Novita's avatar
Riri Novita committed
376 377 378 379 380 381 382 383 384 385 386 387
                let month = String(item[1]).toLocaleLowerCase().includes('jan') ? 1 :
                    String(item[1]).toLocaleLowerCase().includes('feb') ? 2 :
                        String(item[1]).toLocaleLowerCase().includes('mar') ? 3 :
                            String(item[1]).toLocaleLowerCase().includes('apr') ? 4 :
                                String(item[1]).toLocaleLowerCase().includes('may') ? 5 :
                                    String(item[1]).toLocaleLowerCase().includes('jun') ? 6 :
                                        String(item[1]).toLocaleLowerCase().includes('jul') ? 7 :
                                            String(item[1]).toLocaleLowerCase().includes('aug') ? 8 :
                                                String(item[1]).toLocaleLowerCase().includes('sep') ? 9 :
                                                    String(item[1]).toLocaleLowerCase().includes('oct') ? 10 :
                                                        String(item[1]).toLocaleLowerCase().includes('nov') ? 11 :
                                                            String(item[1]).toLocaleLowerCase().includes('dec') ? 12 : null
Riri Novita's avatar
Riri Novita committed
388 389
                this.setState({
                    statusDetail: String(item[2]).toLocaleLowerCase(),
Riri Novita's avatar
Riri Novita committed
390
                    dataDetail: { ...this.state.dataReport[index], periode: this.state.periode.periode, operatingIndID: this.state.operatingIndID, company: this.state.company, status: item[2] },
Riri Novita's avatar
Riri Novita committed
391 392 393
                    visibleOperatingIndicator: false,
                    visibleDetailOpt: false,
                    visibleDetailMonthly: true,
Riri Novita's avatar
Riri Novita committed
394
                    visibleDetailRolling: false,
Riri Novita's avatar
Riri Novita committed
395
                    months: month
Riri Novita's avatar
Riri Novita committed
396

Riri Novita's avatar
Riri Novita committed
397
                })
Riri Novita's avatar
Riri Novita committed
398

Riri Novita's avatar
Riri Novita committed
399
            } else if (String(item[1]).toLocaleLowerCase().includes("rolling outlook")) {
qorri_di's avatar
qorri_di committed
400 401 402
                let quarter = String(item[1]).toLocaleLowerCase().includes('q1') ? "q1" :
                    String(item[1]).toLocaleLowerCase().includes('q2') ? "q2" :
                        String(item[1]).toLocaleLowerCase().includes('q3') ? "q3" : null
Riri Novita's avatar
Riri Novita committed
403 404
                this.setState({
                    statusDetail: String(item[2]).toLocaleLowerCase(),
Riri Novita's avatar
Riri Novita committed
405
                    dataDetail: { ...this.state.dataReport[index], periode: this.state.periode.periode, operatingIndID: this.state.operatingIndID, company: this.state.company, status: item[2] },
Riri Novita's avatar
Riri Novita committed
406 407 408
                    visibleOperatingIndicator: false,
                    visibleDetailOpt: false,
                    visibleDetailMonthly: false,
Riri Novita's avatar
Riri Novita committed
409 410 411
                    visibleDetailRolling: true,
                    quartal: quarter

Riri Novita's avatar
Riri Novita committed
412
                })
Riri Novita's avatar
Riri Novita committed
413 414 415 416 417 418 419 420
            } else {
                this.setState({
                    statusDetail: String(item[2]).toLocaleLowerCase(),
                    dataDetail: { ...this.state.dataReport[index], periode: this.state.periode.periode, operatingIndID: this.state.operatingIndID, company: this.state.company },
                    visibleOperatingIndicator: false,
                    visibleDetailOpt: false,
                    visibleDetailMonthly: false,
                    visibleDetailRolling: true
Riri Novita's avatar
Riri Novita committed
421

Riri Novita's avatar
Riri Novita committed
422 423 424
                })

            }
d.arizona's avatar
d.arizona committed
425
        }
EKSAD's avatar
EKSAD committed
426 427 428 429 430 431 432 433 434 435
    }

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

    fileHandler = (event) => {
        let fileObj = event
        ExcelRenderer(fileObj, (err, resp) => {
EKSAD's avatar
EKSAD committed
436
            // console.log(resp)
EKSAD's avatar
EKSAD committed
437
            if (err) {
EKSAD's avatar
EKSAD committed
438
                // console.log(err);
EKSAD's avatar
EKSAD committed
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
            }
            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()
                    })
Riri Novita's avatar
Riri Novita committed
459 460
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
461
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
462 463 464 465 466 467
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
EKSAD's avatar
EKSAD committed
468 469
                }
            }
EKSAD's avatar
EKSAD committed
470
            // console.log(response)
EKSAD's avatar
EKSAD committed
471 472 473
        })
    }

d.arizona's avatar
d.arizona committed
474 475
    saveOperatingInd(payload) {
        api.create().createOpetaingInd(payload).then((response) => {
Riri Novita's avatar
Riri Novita committed
476
            console.log(response);
d.arizona's avatar
d.arizona committed
477
            this.getReport()
d.arizona's avatar
d.arizona committed
478
            this.getOperatingID()
d.arizona's avatar
d.arizona committed
479 480 481
        })
    }

Riri Novita's avatar
Riri Novita committed
482 483
    saveMonthlyOI(payload) {
        api.create().createMonthlyReportOI(payload).then((response) => {
Riri Novita's avatar
Riri Novita committed
484
            console.log(response);
Riri Novita's avatar
Riri Novita committed
485 486 487 488 489
            this.getReport()
            this.getOperatingID()
        })
    }

Riri Novita's avatar
Riri Novita committed
490
    saveRollingOI(payload) {
Riri Novita's avatar
Riri Novita committed
491
        api.create().createRollingOI(payload).then((response) => {
Riri Novita's avatar
Riri Novita committed
492 493 494 495 496 497
            console.log(response);
            this.getReport()
            this.getOperatingID()
        })
    }

qorri_di's avatar
qorri_di committed
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 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 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
    handleSelectAll(data) {
        if (this.state.isCheckAll) {
            let checkAll = []
            this.setState({ selectReport: checkAll, isCheckAll: false })
        } else {
            let checkAll = this.state.selectReport
            data.map((item) => {
                if (item[4]) {
                    if (!this.state.selectReport.includes(item[3])) {
                        checkAll.push(item[3])
                    }
                }
            })
            console.log(checkAll);
            this.setState({ selectReport: checkAll, isCheckAll: true })
        }
    }

    handleItemChecked(item) {
        let indexID = this.state.selectReport.findIndex((val) => val === item.rowData[3])
        return indexID === -1 ? false : true
    }

    handleItemClick(item) {
        let indexID = this.state.selectReport.findIndex((val) => val === item.rowData[3])
        let selectReport = this.state.selectReport
        if (indexID === -1) {
            selectReport.push(item.rowData[3])
        } else {
            selectReport.splice(indexID, 1)
        }
        let isCheckAll = selectReport.length === this.state.dataTable.length
        this.setState({ selectReport, isCheckAll })
        console.log(selectReport);
    }

    handleDownloadReport(tableMeta) {
        let { selectReport, company, periode, month } = this.state
        let payload = {
            "company_id": company.company_id,
            "year": periode.periode,
            "report_id": selectReport,
            "month": "",
            "quartal": "",
            "type_report_name": "Operating Indicator"
        }
        console.log(payload);
        api.create().createDownloadFile(payload).then((response) => {
            console.log(response)
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        let data = response.data.data
                        this.setState({ downloadedFileReportId: data.downloadedFileReportId, popupDownload: true }, () => this.handleGenerateReport(tableMeta))
                    } 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' })
                }
            } else {
                // this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error'})
                alert(response.problem)
            }
        })
    }

    // componentDidUpdate = (prevProps, prevState) => {
    //     if (this.state.selectReport.length > 0 && (this.state.arrayReport.length == this.state.selectReport.length)) {
    //         setTimeout(() => {
    //             this.handleZip()
    //         }, 200);
    //     }
    // }

    async handleGenerateReport(data) {
        let { selectReport, operatingIndID, company, periode, downloadedFileReportId } = this.state
        if (selectReport.length > 0) {
            let result = []
            console.log('mulai hit')
            for (const items of selectReport) {
                let datas = data.findIndex((val) => val[3] == items)
                let report = data[datas]
                let quarter = String(report[1]).toLocaleLowerCase().includes('q1') ? "q1" :
                    String(report[1]).toLocaleLowerCase().includes('q2') ? "q2" :
                        String(report[1]).toLocaleLowerCase().includes('q3') ? "q3" : null

                let month = String(report[1]).toLocaleLowerCase().includes('jan') ? 1 :
                    String(report[1]).toLocaleLowerCase().includes('feb') ? 2 :
                        String(report[1]).toLocaleLowerCase().includes('mar') ? 3 :
                            String(report[1]).toLocaleLowerCase().includes('apr') ? 4 :
                                String(report[1]).toLocaleLowerCase().includes('may') ? 5 :
                                    String(report[1]).toLocaleLowerCase().includes('jun') ? 6 :
                                        String(report[1]).toLocaleLowerCase().includes('jul') ? 7 :
                                            String(report[1]).toLocaleLowerCase().includes('aug') ? 8 :
                                                String(report[1]).toLocaleLowerCase().includes('sep') ? 9 :
                                                    String(report[1]).toLocaleLowerCase().includes('oct') ? 10 :
                                                        String(report[1]).toLocaleLowerCase().includes('nov') ? 11 :
                                                            String(report[1]).toLocaleLowerCase().includes('dec') ? 12 : null

                if (String(report[1]).toLocaleLowerCase().includes('master budget')) {
                    let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/operating_indicator/master_budget/export_master_budget?operating_indicator_id=${operatingIndID == null ? "" : operatingIndID}&&report_id=${report[3]}&&company_id=${company.company_id}&&year=${periode.periode}&&download_file_report_id=${downloadedFileReportId}`
                    console.log(url);
                    let res = await fetch(
                        `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/operating_indicator/master_budget/export_master_budget?operating_indicator_id=${operatingIndID == null ? "" : operatingIndID}&&report_id=${report[3]}&&company_id=${company.company_id}&&year=${periode.periode}&&download_file_report_id=${downloadedFileReportId}`
                    )

                    if (res.status === 200) {
                        result = [...result, res];
                    }

                } else if (String(report[1]).toLocaleLowerCase().includes('monthly report')) {
                    let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/operating_indicator/monthly_report/export_monthly_report?operating_indicator_id=${operatingIndID == null ? "" : operatingIndID}&&report_id=${report[3]}&&company_id=${company.company_id}&&year=${periode.periode}&&months=${month}&&download_file_report_id=${downloadedFileReportId}`
                    let res = await fetch(
                        `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/operating_indicator/monthly_report/export_monthly_report?operating_indicator_id=${operatingIndID === null ? "" : operatingIndID}&&report_id=${report[3]}&&company_id=${company.company_id}&&year=${periode.periode}&&months=${month}&&download_file_report_id=${downloadedFileReportId}`
                    )

                    if (res.status === 200) {
                        result = [...result, res];
                    }

                } else if (String(report[1]).toLocaleLowerCase().includes('rolling outlook')) {
                    let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/operating_indicator/rolling_outlook/export_rolling_outlook?operating_indicator_id=${operatingIndID == null ? "" : operatingIndID}&&report_id=${report[3]}&&company_id=${company.company_id}&&year=${periode.periode}&&quartal=${quarter}&&download_file_report_id=${downloadedFileReportId}`
                    let res = await fetch(
                        `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/operating_indicator/rolling_outlook/export_rolling_outlook?operating_indicator_id=${operatingIndID === null ? "" : operatingIndID}&&report_id=${report[3]}&&company_id=${company.company_id}&&year=${periode.periode}&&quartal=${quarter}&&download_file_report_id=${downloadedFileReportId}`
                    )

                    if (res.status === 200) {
                        result = [...result, res];
                    }
                }
            }

            console.log('ini result', result);
            // every untuk cek ke setiap result di dalam array
            if (result.every((e) => e.status == 200)) {
                this.handleZip();
            }

            // selectReport.map(async (items) => {
            //     let datas = data.findIndex((val) => val[3] == items)
            //     let report = data[datas]
            //     let quarter = String(report[1]).toLocaleLowerCase().includes('q1') ? "q1" :
            //         String(report[1]).toLocaleLowerCase().includes('q2') ? "q2" :
            //             String(report[1]).toLocaleLowerCase().includes('q3') ? "q3" : null

            //     let month = String(report[1]).toLocaleLowerCase().includes('jan') ? 1 :
            //         String(report[1]).toLocaleLowerCase().includes('feb') ? 2 :
            //             String(report[1]).toLocaleLowerCase().includes('mar') ? 3 :
            //                 String(report[1]).toLocaleLowerCase().includes('apr') ? 4 :
            //                     String(report[1]).toLocaleLowerCase().includes('may') ? 5 :
            //                         String(report[1]).toLocaleLowerCase().includes('jun') ? 6 :
            //                             String(report[1]).toLocaleLowerCase().includes('jul') ? 7 :
            //                                 String(report[1]).toLocaleLowerCase().includes('aug') ? 8 :
            //                                     String(report[1]).toLocaleLowerCase().includes('sep') ? 9 :
            //                                         String(report[1]).toLocaleLowerCase().includes('oct') ? 10 :
            //                                             String(report[1]).toLocaleLowerCase().includes('nov') ? 11 :
            //                                                 String(report[1]).toLocaleLowerCase().includes('dec') ? 12 : null

            //     // console.log(report);

            //     if (String(report[1]).toLocaleLowerCase().includes('master budget')) {
            //         let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/operating_indicator/master_budget/export_master_budget?operating_indicator_id=${operatingIndID == null ? "" : operatingIndID}&&report_id=${report[3]}&&company_id=${company.company_id}&&year=${periode.periode}&&download_file_report_id=${downloadedFileReportId}`
            //         let res = await fetch(
            //             `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/operating_indicator/master_budget/export_master_budget?operating_indicator_id=${operatingIndID == null ? "" : operatingIndID}&&report_id=${report[3]}&&company_id=${company.company_id}&&year=${periode.periode}&&download_file_report_id=${downloadedFileReportId}`
            //         )
            //         // console.log(url);
            //         console.log(res);
            //         if (res.status === 200) {
            //             this.setState({ arrayReport: [...this.state.arrayReport, items] })
            //         }
            //     } else if (String(report[1]).toLocaleLowerCase().includes('monthly report')) {
            //         let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/operating_indicator/monthly_report/export_monthly_report?operating_indicator_id=${operatingIndID == null ? "" : operatingIndID}&&report_id=${report[3]}&&company_id=${company.company_id}&&year=${periode.periode}&&months=${month}&&download_file_report_id=${downloadedFileReportId}`
            //         let res = await fetch(
            //             `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/operating_indicator/monthly_report/export_monthly_report?operating_indicator_id=${operatingIndID === null ? "" : operatingIndID}&&report_id=${report[3]}&&company_id=${company.company_id}&&year=${periode.periode}&&months=${month}&&download_file_report_id=${downloadedFileReportId}`
            //         )
            //         // console.log(url);
            //         console.log(res);
            //         if (res.status === 200) {
            //             this.setState({ arrayReport: [...this.state.arrayReport, items] })
            //         }
            //     } else if (String(report[1]).toLocaleLowerCase().includes('rolling outlook')) {
            //         let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/operating_indicator/rolling_outlook/export_rolling_outlook?operating_indicator_id=${operatingIndID == null ? "" : operatingIndID}&&report_id=${report[3]}&&company_id=${company.company_id}&&year=${periode.periode}&&quartal=${quarter}&&download_file_report_id=${downloadedFileReportId}`
            //         let res = await fetch(
            //             `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/operating_indicator/rolling_outlook/export_rolling_outlook?operating_indicator_id=${operatingIndID === null ? "" : operatingIndID}&&report_id=${report[3]}&&company_id=${company.company_id}&&year=${periode.periode}&&quartal=${quarter}&&download_file_report_id=${downloadedFileReportId}`
            //         )
            //         // console.log(url);
            //         console.log(res);
            //         if (res.status === 200) {
            //             this.setState({ arrayReport: [...this.state.arrayReport, items] })
            //         }
            //     }

            // })
        } else {
            // alert("Anda harus memilih report yang ingin di download terlebih dahulu!")
        }
    }

    async handleZip() {
        console.log('mulai zip')
        api.create().createZipReport(this.state.downloadedFileReportId).then((response) => {
            console.log(response)
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        this.setState({ arrayReport: [] })
                    } 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' })
                }
            } else {
                // this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error'})
                alert(response.problem)
            }
        })
    }

EKSAD's avatar
EKSAD committed
732
    render() {
EKSAD's avatar
EKSAD committed
733
        const columns = ["#", "Report Type",
d.arizona's avatar
d.arizona committed
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
            // {
            //     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 => {
EKSAD's avatar
EKSAD committed
751
            //                                     // console.log(event.target)
d.arizona's avatar
d.arizona committed
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
            //                                     updateValue(event.target.value)
            //                                     this.handleChange(event.target.value, tableMeta)
            //                                 }}
            //                                 autoWidth
            //                             >
            //                                 {list.map((item, index) =>
            //                                     <MenuItem key={index} value={item}>{item}</MenuItem>
            //                                 )}
            //                             </Select>
            //                         }
            //                     />
            //                 </div >
            //             );
            //         }
            //     }
qorri_di's avatar
qorri_di committed
767
            // }, 
EKSAD's avatar
EKSAD committed
768 769 770 771 772 773 774
            {
                name: "Status",
                options: {
                    customBodyRender: (val, tableMeta) => {
                        return (
                            <div style={{ display: 'flex' }}>
                                {val === "submitted" || val === "approved" ?
EKSAD's avatar
EKSAD committed
775 776 777 778 779 780 781 782 783 784 785 786 787 788
                                    <span>COMPLETED</span> :
                                    val === "draft" ?
                                        <span>DRAFT</span> :
                                        val === "revision" ?
                                            <span>REVISION</span> :
                                            val === "approval_proccess" ?
                                                <span>APPROVAL PROCCESS</span> :
                                                val === "approval_review" ?
                                                    <span>APPROVAL REVIEW</span> :
                                                    val === "not-yet" ?
                                                        <span>OPEN</span> :
                                                        val === "CLOSED" ?
                                                            <span>CLOSED</span> :
                                                            <img src={Images.cross} style={{ width: 31, height: 24 }} />
EKSAD's avatar
EKSAD committed
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
                                }
                            </div >
                        );
                    }
                }
            },
            {
                name: "Action",
                options: {
                    customBodyRender: (val, tableMeta) => {
                        return (
                            <div style={{ display: 'flex' }}>
                                <button
                                    style={{
                                        backgroundColor: 'transparent',
EKSAD's avatar
EKSAD committed
804
                                        cursor: tableMeta.rowData[4] ? 'pointer' : null,
EKSAD's avatar
EKSAD committed
805 806 807
                                        borderColor: 'transparent'
                                    }}
                                    onClick={() =>
qorri_di's avatar
qorri_di committed
808 809 810 811
                                        tableMeta.rowData[4] ?
                                            this.clickDetail(tableMeta.rowData, tableMeta.rowData[1], tableMeta.rowData[3], tableMeta.rowData[2])
                                            :
                                            null
EKSAD's avatar
EKSAD committed
812 813
                                    }
                                >
EKSAD's avatar
EKSAD committed
814
                                    <Typography style={{ color: tableMeta.rowData[4] ? '#5198ea' : 'GrayText', fontSize: 12, }}>Detail</Typography>
EKSAD's avatar
EKSAD committed
815 816 817 818 819
                                </button>
                            </div >
                        );
                    }
                }
qorri_di's avatar
qorri_di committed
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835
            }, {
                name: "Download",
                options: {
                    customBodyRender: (val, tableMeta) => {
                        // console.log(tableMeta);
                        return (
                            <div style={{ display: 'flex' }}>
                                <CustomCheckbox
                                    checked={this.handleItemChecked(tableMeta)}
                                    onChange={() => tableMeta.rowData[4] ? this.handleItemClick(tableMeta) : null}
                                    disabled={tableMeta.rowData[4] ? false : true}
                                />
                            </div >
                        );
                    }
                }
EKSAD's avatar
EKSAD committed
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
            }, {
                name: "",
                options: { display: false }
            }, {
                name: "",
                options: { display: false }
            }]
        const options = {
            filter: false,
            sort: false,
            responsive: "scroll",
            print: false,
            download: false,
            selectableRows: false,
            viewColumns: false,
EKSAD's avatar
EKSAD committed
851 852
            rowsPerPage: 50,
            pagination: false,
EKSAD's avatar
EKSAD committed
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
            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 }}>
Riri Novita's avatar
Riri Novita committed
880
                            <Typography style={{ fontSize: '16px', color: 'white' }}>Operating Indicator Submission</Typography>
EKSAD's avatar
EKSAD committed
881 882 883 884 885 886 887 888 889 890 891 892
                        </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 }, () => {
d.arizona's avatar
d.arizona committed
893
                                                this.getOperatingID()
d.arizona's avatar
d.arizona committed
894
                                                // this.getReportAttachment()
EKSAD's avatar
EKSAD committed
895
                                            })}
EKSAD's avatar
EKSAD committed
896 897
                                            // debug
                                            clearOnEscape
EKSAD's avatar
EKSAD committed
898 899
                                            disableClearable
                                            style={{ width: 250 }}
EKSAD's avatar
EKSAD committed
900
                                            renderInput={(params) => <TextField {...params} label="Period" margin="normal" style={{ marginTop: 7 }} />}
EKSAD's avatar
EKSAD committed
901 902 903 904 905 906 907 908
                                            value={this.state.periode}
                                        />
                                    </div>
                                    <div style={{ marginTop: 20 }}>
                                        <Autocomplete
                                            {...this.state.listCompany}
                                            id="company"
                                            onChange={(event, newInputValue) => this.setState({ company: newInputValue }, () => {
d.arizona's avatar
d.arizona committed
909
                                                this.getOperatingID()
d.arizona's avatar
d.arizona committed
910
                                                // this.getReportAttachment()
EKSAD's avatar
EKSAD committed
911
                                            })}
EKSAD's avatar
EKSAD committed
912
                                            clearOnEscape
EKSAD's avatar
EKSAD committed
913 914
                                            disableClearable
                                            style={{ width: 250 }}
Deni Rinaldi's avatar
Deni Rinaldi committed
915 916 917 918 919 920
                                            renderInput={(params) =>
                                                <TextField
                                                    {...params}
                                                    label="Company"
                                                    margin="normal"
                                                    style={{ marginTop: 7 }}
EKSAD's avatar
EKSAD committed
921
                                                />}
EKSAD's avatar
EKSAD committed
922 923 924 925
                                            value={this.state.company}
                                        />
                                    </div>
                                    <div style={{ marginTop: 20 }}>
qorri_di's avatar
qorri_di committed
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
                                        <div style={{ display: 'flex', justifyContent: 'flex-end', margin: '20px 15px' }}>
                                            <button
                                                className="button"
                                                type="button"
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    outline: 'none',
                                                    marginRight: 20
                                                }}
                                                onClick={() => this.handleSelectAll(this.state.dataTable)}
                                            >
                                                <div style={{ backgroundColor: '#fff', width: 100, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #354960' }}>
                                                    <Typography style={{ fontSize: '11px', color: '#354960', textAlign: 'center' }}>Check All</Typography>
                                                </div>
                                            </button>
                                            <button
                                                type="button"
                                                disabled={this.state.buttonError}
                                                onClick={() => this.handleDownloadReport(this.state.dataTable)}
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    borderColor: 'transparent',
                                                    outline: 'none',
                                                }}
                                            >
                                                <div style={{ backgroundColor: '#354960', width: 100, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                                    <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Download</Typography>
                                                </div>
                                            </button>
                                        </div>
d.arizona's avatar
d.arizona committed
958 959 960 961 962 963 964
                                        <MuiThemeProvider theme={getMuiTheme()}>
                                            <MUIDataTable
                                                data={this.state.dataTable}
                                                columns={columns}
                                                options={options}
                                            />
                                        </MuiThemeProvider>
EKSAD's avatar
EKSAD committed
965 966
                                    </div>
                                </div>
EKSAD's avatar
EKSAD committed
967
                                {/* {this.state.isSubmit && (
Deni Rinaldi's avatar
Deni Rinaldi committed
968 969 970 971
                                    <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>
EKSAD's avatar
EKSAD committed
972
                                    </div>
EKSAD's avatar
EKSAD committed
973
                                )} */}
EKSAD's avatar
EKSAD committed
974 975 976 977 978 979
                            </Paper>

                        </div>
                    </div>
                )}

Deni Rinaldi's avatar
Deni Rinaldi committed
980
                {this.state.visibleDetailOpt &&
d.arizona's avatar
d.arizona committed
981
                    <OperatingIndicatorDetail
d.arizona's avatar
d.arizona committed
982
                        open={this.props.open}
d.arizona's avatar
d.arizona committed
983 984 985
                        data={this.state.dataDetail}
                        height={this.props.height}
                        width={this.props.width}
d.arizona's avatar
d.arizona committed
986 987 988 989
                        onClickClose={() => this.setState({ visibleDetailOpt: false, visibleOperatingIndicator: true }, () => {
                            this.getOperatingID()
                            this.forceUpdate()
                        })}
Deni Rinaldi's avatar
Deni Rinaldi committed
990
                        getReport={() => this.getOperatingID()}
d.arizona's avatar
d.arizona committed
991
                        saveOperatingInd={this.saveOperatingInd.bind(this)}
Riri Novita's avatar
Riri Novita committed
992
                        isSubmit={this.state.statusDetail == 'closed' ? false : this.state.isSubmit}
Deni Rinaldi's avatar
Deni Rinaldi committed
993
                        permission={{ create: this.state.buttonCreate, edit: this.state.buttonEdit, delete: this.state.buttonDelete }}
d.arizona's avatar
d.arizona committed
994 995
                    />
                }
Riri Novita's avatar
Riri Novita committed
996 997 998 999 1000 1001
                {this.state.visibleDetailMonthly &&
                    <OperatingIndicatorMR
                        open={this.props.open}
                        data={this.state.dataDetail}
                        height={this.props.height}
                        width={this.props.width}
Riri Novita's avatar
Riri Novita committed
1002
                        months={this.state.months}
Riri Novita's avatar
Riri Novita committed
1003 1004 1005 1006 1007 1008
                        company={this.state.company}
                        onClickClose={() => this.setState({ visibleDetailMonthly: false, visibleOperatingIndicator: true }, () => {
                            this.getOperatingID()
                            this.forceUpdate()
                        })}
                        getReport={() => this.getOperatingID()}
Riri Novita's avatar
Riri Novita committed
1009
                        saveMonthlyOI={this.saveMonthlyOI.bind(this)}
Riri Novita's avatar
Riri Novita committed
1010
                        isSubmit={this.state.statusDetail == 'closed' ? false : this.state.isSubmit}
Riri Novita's avatar
Riri Novita committed
1011 1012 1013
                        permission={{ create: this.state.buttonCreate, edit: this.state.buttonEdit, delete: this.state.buttonDelete }}
                    />
                }
d.arizona's avatar
d.arizona committed
1014

Riri Novita's avatar
Riri Novita committed
1015 1016 1017 1018 1019 1020
                {this.state.visibleDetailRolling &&
                    <OperatingIndicatorRO
                        open={this.props.open}
                        data={this.state.dataDetail}
                        height={this.props.height}
                        width={this.props.width}
Riri Novita's avatar
Riri Novita committed
1021
                        quartal={this.state.quartal}
Riri Novita's avatar
Riri Novita committed
1022 1023 1024 1025 1026 1027 1028
                        company={this.state.company}
                        onClickClose={() => this.setState({ visibleDetailRolling: false, visibleOperatingIndicator: true }, () => {
                            this.getOperatingID()
                            this.forceUpdate()
                        })}
                        getReport={() => this.getOperatingID()}
                        saveRollingOI={this.saveRollingOI.bind(this)}
Riri Novita's avatar
Riri Novita committed
1029
                        isSubmit={this.state.statusDetail == 'closed' ? false : this.state.isSubmit}
Riri Novita's avatar
Riri Novita committed
1030 1031 1032 1033
                        permission={{ create: this.state.buttonCreate, edit: this.state.buttonEdit, delete: this.state.buttonDelete }}
                    />
                }

EKSAD's avatar
EKSAD committed
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
                {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>
                )}
qorri_di's avatar
qorri_di committed
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095

                {this.state.popupDownload && (
                    <div className="test app-popup-show">
                        <div className="popup-content border-radius" style={{ background: '#D9D9D9', borderRadius: 10, width: 609, height: 276 }}>
                            <div>
                                <div style={{ justifyContent: 'center', fontSize: 20, color: '#33508B', margin: '70px 20px' }}>Download Operating Indicator {this.state.company.company_name} {this.state.periode.periode} In Progress, silahkan cek status dan unduh report di menu <b>Download Report</b></div>
                                <div style={{ display: 'flex', justifyContent: 'flex-end' }}>
                                    <button
                                        className="button"
                                        type="button"
                                        style={{
                                            background: '#F6F7F9',
                                            cursor: 'pointer',
                                            border: '1px solid #3549609e',
                                            outline: 'none',
                                            marginRight: 20,
                                            borderRadius: 3
                                        }}
                                        onClick={() => this.setState({ popupDownload: false })}
                                    >
                                        <div style={{ backgroundColor: '#fff', width: 105, height: 30, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #3549609e' }}>
                                            <Typography style={{ fontSize: '15px', color: '#354960', textAlign: 'center' }}>Close</Typography>
                                        </div>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                )}
EKSAD's avatar
EKSAD committed
1096 1097 1098 1099
            </div >
        );
    }
}