MasterDataCAT.js 65.8 KB
Newer Older
Riri Novita's avatar
Riri Novita committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 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 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 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 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 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
import React, { Component } from "react";
import { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles';
import Images from "../../../assets/Images";
import MUIDataTable from "mui-datatables";
import { InputBase, Snackbar, Tooltip, withStyles } from "@material-ui/core";
import { ExcelRenderer } from 'react-excel-renderer';
import UploadFile from "../../../library/Upload";
import MuiAlert from '@material-ui/lab/Alert';
import CreateMasterDataCAT from "./CreateMasterDataCAT";
import EditMasterDataCAT from "./EditMasterDataCAT";
import VisualMasterDataCAT from "./VisualMasterDataCAT";
import api from '../../../api';
import ReactTooltip from "react-tooltip";
import PopUpFailedSave from "../../../library/PopUpFailedSave";
import Constant from "../../../library/Constant";
import PopUpDelete from "../../../library/PopUpDelete";
import { css } from "@emotion/core";
import PropagateLoader from "react-spinners/PropagateLoader"

const LightTooltip = withStyles((theme) => ({
    tooltip: {
        backgroundColor: theme.palette.common.white,
        color: 'rgba(0, 0, 0, 0.87)',
        boxShadow: theme.shadows[1],
        fontSize: 11,
    },
}))(Tooltip);

var ct = require("../../../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable());
const options = ct.customOptions();
const options2 = ct.customOptions2();

const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);

export default class MasterDataCAT extends Component {
    constructor(props) {
        super(props)
        this.state = {
            dataTable: [],
            listData: [],
            data: [],
            search: "",
            itemReport: true,
            visualisasi: false,
            add: false,
            edit: false,
            dataLoaded: false,
            cols: null,
            rows: null,
            popupError: false,
            alert: false,
            tipeAlert: '',
            messageAlert: '',
            buttonCreate: false,
            buttonEdit: false,
            buttonDelete: false,
            load: false,
            judul: '',
            reportNameDelete: '',
            visibleDelete: false,
            invalidTemplate: false,
            loading: false
        }
        this.myRef = React.createRef()
        this.fileHandler = this.fileHandler.bind(this);
    }

    fileHandler = (event) => {
        let fileObj = event
        ExcelRenderer(fileObj, (err, resp) => {
            // console.log(resp)
            if (err) {
                console.log(err);
            }
            else {
                let isi = resp.rows.slice(3)
                let payload = []
                isi.map((item, index) => {
                    if (item.length > 0) {
                        payload.push({
                            id: index + 1,
                            report: item[0] === undefined ? "" : item[0],
                            company: item[1] === undefined ? "" : item[1],
                            orders: item[2] === undefined ? "" : item[2],
                            description: item[3] === undefined ? "" : item[3],
                            parent: item[4] === undefined ? 0 : item[4],
                            uom: item[5] === undefined ? "" : item[5],
                            weight: item[6] === undefined ? "" : item[6],
                            type_report: item[7] === undefined ? "" : item[7],
                            formula: item[8] === undefined ? "" : item[8],
                            condition_it_should_be: item[9] === undefined ? "" : item[9],
                            condition_if_wrong: item[10] === undefined ? "" : item[10],
                            kpi_type: item[11] === undefined ? "" : item[11],
                            max_ach: item[12] === undefined ? "" : item[12],
                            formula_ytd: item[13] === undefined ? "" : item[13],
                            start_date: item[14] === undefined ? "" : item[14],
                            end_date: item[15] === undefined ? "" : item[15],
                        })
                    }
                })
                let body = {
                    item_report: payload
                }

                if (resp.rows[2].length !== 16) {
                    this.setState({ invalidTemplate: true })
                } else {
                    this.setState({ invalidTemplate: false })
                }

                console.log(resp.rows[1])
                this.setState({ payload: body, buttonError: false, judul: resp.rows[1][0] })
            }
        });
    }

    checkUpload() {
        api.create().checkUploadReportItems(this.state.payload).then(response => {
            console.log(response)
            let dataRow = []
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === "success") {
                        dataRow = response.data.data.map((item, index) => {
                            return [
                                item.report,
                                item.company,
                                item.orders,
                                item.description,
                                item.parent,
                                item.uom,
                                item.weight,
                                item.type_report,
                                item.formula,
                                item.condition_it_should_be,
                                item.condition_if_wrong,
                                item.kpi_type,
                                item.max_ach,
                                item.formula_ytd,
                                item.start_date,
                                item.end_date,
                                item.error
                            ]
                        })
                        let columns = [
                            {
                                name: "Report Type",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('report_type'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Company Name",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('company'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Order",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('orders'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === null ? "Empty" : val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Description",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('description'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Parent ID",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('parent'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "UOM",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('uom'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Weight",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('weight'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Data Type",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('type_report'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Formula",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('formula'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "True Value",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('condition_it_should_be'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "False Condition",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('condition_if_wrong'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "KPI Type",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('kpi_type'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Max Achievement",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('max_ach'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Formula YTD",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('formula_ytd'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Valid From",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('start_date'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Valid To",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[16] != null) {
                                            check = tableMeta.rowData[16].findIndex((val) => val.field.includes('end_date'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[16] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[16][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "",
                                options: {
                                    display: false
                                }
                            }
                        ]

                        // console.log(dataRow);
                        this.setState({
                            dataLoaded: true,
                            cols: columns,
                            rows: dataRow, visibleUpload: false,
                            itemReport: false
                        });
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
549
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
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
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
            } else {
                this.setState({
                    dataLoaded: false,
                    alert: true, messageAlert: response.problem, tipeAlert: 'error'
                });
            }
        })
    }

    componentDidMount() {
        this.getData()
        this.getPermission()
    }

    getPermission() {
        let payload = {
            menu: "report items"
        }
        api.create().getPermission(payload).then(response => {
            // console.log(response)
            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 {
                    this.setState({ load: true })
                }
            }
        })
    }

    getData() {
        this.setState({ loading: true })
597 598
        api.create().getAllMasterDataCat().then((response) => {
            console.log(response)
Riri Novita's avatar
Riri Novita committed
599 600 601 602 603 604 605 606
            if (response.data) {
                if (response.ok) {
                    if (response.data.status == 'success') {
                        let data = response.data.data
                        let listData = data.sort((a, b) => a.item_report_id - b.item_report_id).map((item, index) => {
                            return [
                                index, 
                                item.item_report_id, 
rifkaki's avatar
rifkaki committed
607
                                item.item_report_name,
Riri Novita's avatar
Riri Novita committed
608
                                item.company_name, 
609
                                item.report_name,
Riri Novita's avatar
Riri Novita committed
610
                                item.weight, 
611
                                item.years,
rifkaki's avatar
rifkaki committed
612
                                item.status,
rifkaki's avatar
rifkaki committed
613
                                item.company_id
rifkaki's avatar
rifkaki committed
614
                            ]
Riri Novita's avatar
Riri Novita committed
615 616 617 618 619 620
                        })
                        this.setState({ dataTable: listData, listData: response.data.data }, () => {
                            setTimeout(() => {
                                this.setState({ loading: false })
                            }, 2000);
                        })
621
                        console.log(this.state.dataTable)
Riri Novita's avatar
Riri Novita committed
622 623
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
624
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
            }
        })
    }

    deleteReport(payload) {
rifkaki's avatar
rifkaki committed
642 643 644 645 646
        console.log(payload);
        let idCompany = payload[8]
        let years = payload[6]
        api.create().deleteMasterDataCat(idCompany, years).then(response => {
            console.log(response)
Riri Novita's avatar
Riri Novita committed
647 648 649 650 651 652 653
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === "success") {
                        this.getData()
                        this.setState({ visibleDelete: false, alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
654
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
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
                                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' })
            }
        })
    }

    openPopUp(index, type) {
        if (type === 'edit') {
            this.setState({
                rowData: index,
                edit: true
            })
        } else if (type === 'delete') {
            this.setState({
                rowData: index,
rifkaki's avatar
rifkaki committed
680
                reportNameDelete: "[" + String(index[3]) + " - " + String(index[6]) + "] ",
Riri Novita's avatar
Riri Novita committed
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
                visibleDelete: true
            })
        } else {
            this.setState({
                add: true
            })
        }
    }

    handleInputChange(e) {
        this.setState({ search: e })
        let body = {
            "keyword": e
        }
        api.create().searchReportItems(body).then(response => {
            // console.log(response.data);
            if (response.data) {
                if (response.ok) {
                    if (response.data.status == 'success') {
                        let data = response.data.data
                        let listData = data.map((item, index) => {
                            return [index, item.item_report_id, item.report_name, item.company_name, item.order, item.description, item.parent, item.uom, item.weight, item.type_item_report_name, item.status]
                        })
                        this.setState({ dataTable: listData, listData: response.data.data })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
707
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
                                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' })
            }
        })
    }

    createReportItems = (payload) => {
faisalhamdi's avatar
faisalhamdi committed
725
        this.setState({ add: false, edit: false })
726
        api.create().saveMasterDataCat(payload).then(response => {
Riri Novita's avatar
Riri Novita committed
727 728 729 730 731 732 733 734
            // console.log(response);
            if (response.data) {
                if (response.ok) {
                    if (response.data.status == 'success') {
                        this.getData()
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
735
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
                                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' })
            }
        })
    }

faisalhamdi's avatar
faisalhamdi committed
752 753 754 755 756 757 758 759 760 761 762 763
    updateReportItems = (payload) => {
        this.setState({ add: false, edit: false })
        api.create().updateMasterDataCat(payload).then(response => {
            console.log(payload);
            console.log(response);
            if (response.data) {
                if (response.ok) {
                    if (response.data.status == 'success') {
                        this.getData()
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
764
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
faisalhamdi's avatar
faisalhamdi committed
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
                                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' })
            }
        })
    }

Riri Novita's avatar
Riri Novita committed
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
    downloadFile = async () => {
        let res = await fetch(
            `${process.env.REACT_APP_URL_MAIN_BE}/public/attachment/download_file?fileName=ItemReportTemplate&&fileType=xlsx`
        )
        res = await res.blob()
        // console.log(res)
        if (res.size > 0) {
            let url = window.URL.createObjectURL(res);
            let a = document.createElement('a');
            a.href = url;
            a.download = 'Template Report Item.xlsx';
            a.click();
        }
    }

    downloadDataTable = async () => {
rifkaki's avatar
rifkaki committed
797
        let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/item_report_company/export_item_report_company`
rifkaki's avatar
rifkaki committed
798
        console.log(url)
Riri Novita's avatar
Riri Novita committed
799
        let res = await fetch(
rifkaki's avatar
rifkaki committed
800
            `${process.env.REACT_APP_URL_MAIN_BE}/public/item_report_company/export_item_report_company`
Riri Novita's avatar
Riri Novita committed
801 802 803 804 805 806 807
        )
        res = await res.blob()
        // console.log(res)
        if (res.size > 0) {
            let url = window.URL.createObjectURL(res);
            let a = document.createElement('a');
            a.href = url;
rifkaki's avatar
rifkaki committed
808
            a.download = 'Master Data - CAT.xlsx';
Riri Novita's avatar
Riri Novita committed
809 810 811 812 813 814 815 816 817 818 819 820 821 822
            a.click();
        }
    }

    uploadReportItems() {
        api.create().uploadReportItems(this.state.payload).then(response => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === "success") {
                        // alert(response.data.message)
                        this.getData()
                        this.setState({ itemReport: true, alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
823
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 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 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901
                                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' })
            }
        })
    }

    closeAlert() {
        this.setState({ alert: false })
    }

    scrollToMyRef = () => window.scrollTo(0, this.myRef.current.offsetTop)

    render() {
        const columns = [{
            name: "Action",
            options: {
                sort: false,
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            {this.state.buttonEdit &&
                                <span>
                                    <a data-tip={'Edit'} data-for="edit">
                                        <button
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent'
                                            }}
                                            onClick={() => this.openPopUp(tableMeta.rowData, 'edit')}

                                        >
                                            <img src={Images.editCopy} />
                                        </button>
                                    </a>
                                    <ReactTooltip border={true} id="edit" place="bottom" type="light" effect="solid" />
                                </span>
                            }
                            {this.state.buttonDelete &&
                                <span>
                                    <a data-tip={'Delete'} data-for="delete">
                                        <button
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent',
                                                marginLeft: 15
                                            }}
                                            // onClick={() => console.log(tableMeta)}
                                            onClick={() => this.openPopUp(tableMeta.rowData, 'delete')}
                                        >
                                            <img src={Images.delete} />
                                        </button>
                                    </a>
                                    <ReactTooltip border={true} id="delete" place="bottom" type="light" effect="solid" />
                                </span>
                            }
                        </div >
                    );
                }
            }
        },
        {
            name: "ID",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
902
                            <span style={{ color: tableMeta.rowData[7] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
Riri Novita's avatar
Riri Novita committed
903 904 905 906 907 908
                        </div >
                    );
                }
            }
        },
        {
rifkaki's avatar
rifkaki committed
909
            name: "Report Name",
Riri Novita's avatar
Riri Novita committed
910 911 912 913
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
rifkaki's avatar
rifkaki committed
914
                            <span style={{ color: tableMeta.rowData[7] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{tableMeta.rowData[4]}</span>
Riri Novita's avatar
Riri Novita committed
915 916 917 918 919 920
                        </div >
                    );
                }
            }
        },
        {
rifkaki's avatar
rifkaki committed
921
            name: "Item Report Name",
Riri Novita's avatar
Riri Novita committed
922 923 924 925
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
rifkaki's avatar
rifkaki committed
926
                            <span style={{ color: tableMeta.rowData[7] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{tableMeta.rowData[2]}</span>
Riri Novita's avatar
Riri Novita committed
927 928 929 930 931 932
                        </div >
                    );
                }
            }
        },
        {
rifkaki's avatar
rifkaki committed
933
            name: "Year",
Riri Novita's avatar
Riri Novita committed
934 935 936 937
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
rifkaki's avatar
rifkaki committed
938
                            <span style={{ color: tableMeta.rowData[7] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{tableMeta.rowData[6]}</span>
Riri Novita's avatar
Riri Novita committed
939 940 941 942 943 944
                        </div >
                    );
                }
            }
        },
        {
rifkaki's avatar
rifkaki committed
945
            name: "Company Name",
Riri Novita's avatar
Riri Novita committed
946 947 948 949
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
rifkaki's avatar
rifkaki committed
950
                            <span style={{ color: tableMeta.rowData[7] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{tableMeta.rowData[3]}</span>
Riri Novita's avatar
Riri Novita committed
951 952 953 954 955 956
                        </div >
                    );
                }
            }
        },
        {
rifkaki's avatar
rifkaki committed
957
            name: "Weight",
Riri Novita's avatar
Riri Novita committed
958 959 960 961
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
rifkaki's avatar
rifkaki committed
962
                            <span style={{ color: tableMeta.rowData[7] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{tableMeta.rowData[5]}</span>
Riri Novita's avatar
Riri Novita committed
963 964 965 966 967 968 969 970 971 972 973
                        </div >
                    );
                }
            }
        },
        {
            name: "Status",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
rifkaki's avatar
rifkaki committed
974
                            <span style={{ color: tableMeta.rowData[7] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{tableMeta.rowData[7]}</span>
Riri Novita's avatar
Riri Novita committed
975 976 977 978
                        </div >
                    );
                }
            }
rifkaki's avatar
rifkaki committed
979 980 981 982 983 984
        },
        {
            name: "company id",
            options: {
                display: false
            }
Riri Novita's avatar
Riri Novita committed
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
        }
        ]
        const loadingComponent = (
            <div style={{ position: 'absolute', zIndex: 110, top: 0, left: 0, width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', background: 'rgba(255,255,255,0.8)' }}>
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
            </div>
        );
        return (
            <div style={{ height: this.props.height }} ref={this.myRef}>
                {/* <Row> */}
                <div className={"main-color"} style={{ height: 195, width: '100%' }} />
                <Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
                    <Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
                        {this.state.messageAlert}
                    </Alert>
                </Snackbar>
                {this.state.loading && loadingComponent}
                {this.state.itemReport === true ?
                    this.state.load && (
                        <div>
                            <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', paddingRight: 25, paddingLeft: 25, marginTop: -182 }}>
                                <label style={{ color: 'white', fontSize: 16, alignSelf: 'center', width: '50%', }}>Master Data - CAT</label>
                                {/* <div style={{ color: 'white', width: '50%', height: 37, display: 'flex', backgroundColor: 'white', borderWidth: 2, alignItems: 'center', borderRadius: 6, paddingLeft: 5, paddingRight: 5, alignSelf: 'center' }}>
                                        <img src={Images.searchBlack} style={{ marginRight: 10 }} />
                                        <InputBase
                                            style={{ width: '100%' }}
                                            placeholder="Search"
                                            value={this.state.search}
                                            onChange={(e) => this.handleInputChange(e.target.value)}
                                            inputProps={{ 'aria-label': 'naked' }}
                                        />
                                    </div> */}
                                <div style={{ width: '50%', justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
rifkaki's avatar
rifkaki committed
1023
                                    {/* <a data-tip={'Download Template'} data-for="template">
Riri Novita's avatar
Riri Novita committed
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
                                        <button
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent',
                                                margin: 5
                                            }}
                                            onClick={() => this.downloadFile()}
                                        >
                                            <img src={Images.template} />
                                        </button>
                                    </a>
rifkaki's avatar
rifkaki committed
1036 1037
                                    <ReactTooltip border={true} id="template" place="bottom" type="light" effect="solid" /> */}
                                    {/* {this.state.buttonCreate && (
Riri Novita's avatar
Riri Novita committed
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
                                        <a data-tip={'Upload'} data-for="upload">
                                            <button
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    margin: 5
                                                }}
                                                onClick={() => null}
                                            >
                                                <img src={Images.upload} onClick={() => this.setState({ visibleUpload: true })} />
                                            </button>
                                        </a>
                                    )}
rifkaki's avatar
rifkaki committed
1052
                                    <ReactTooltip border={true} id="upload" place="bottom" type="light" effect="solid" /> */}
Riri Novita's avatar
Riri Novita committed
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
                                    <a data-tip={'Download'} data-for="download">
                                        <button
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent',
                                                margin: 5
                                            }}
                                            onClick={() => this.downloadDataTable()}
                                        >
                                            <img src={Images.download} />
                                        </button>
                                    </a>
                                    <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
rifkaki's avatar
rifkaki committed
1067
                                    {/* <a data-tip={'Visualization'} data-for="visualisasi">
Riri Novita's avatar
Riri Novita committed
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
                                        <button
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent',
                                                margin: 5
                                            }}
                                            onClick={() => this.setState({ visualisasi: true, itemReport: false })}
                                        >
                                            <img src={Images.visualisasi} />
                                        </button>
                                    </a>
rifkaki's avatar
rifkaki committed
1080
                                    <ReactTooltip border={true} id="visualisasi" place="bottom" type="light" effect="solid" /> */}
Riri Novita's avatar
Riri Novita committed
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
                                    {this.state.buttonCreate && (
                                        <a data-tip={'Add New'} data-for="tambah">
                                            <button
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    margin: 5,
                                                    marginRight: 20
                                                }}
                                            >
                                                <img src={Images.add} onClick={() => this.setState({ add: true })} />
                                            </button>
                                        </a>
                                    )}
                                    <ReactTooltip border={true} id="tambah" place="bottom" type="light" effect="solid" />
                                </div>
                            </div>
                            <div style={{ padding: 25 }}>
                                <MuiThemeProvider theme={getMuiTheme()}>
                                    <MUIDataTable
                                        theme={getMuiTheme()}
                                        data={this.state.dataTable}
                                        columns={columns}
                                        options={options}
                                    />
                                </MuiThemeProvider>

                            </div>
                        </div>
                    )
                    :
                    this.state.visualisasi == true ?
                        <VisualMasterDataCAT
                            buttonCreate={this.state.buttonCreate}
                            buttonEdit={this.state.buttonEdit}
                            onClickClose={() => this.setState({ visualisasi: false, itemReport: true }, () => this.getData())}
                            height={this.props.height}
                            handleLoading={() => this.setState({ loading: true })}
                            scrollToTop={() => this.scrollToMyRef()}
                        />
                        :
                        <div>
                            <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', paddingRight: 25, paddingLeft: 25, marginTop: -150 }}>
                                <label style={{ color: 'white', fontSize: 16, alignSelf: 'center' }}>Preview Data</label>
                            </div>
                            <div style={{ padding: 25 }}>
                                <MuiThemeProvider theme={getMuiTheme()}>
                                    <MUIDataTable
                                        theme={getMuiTheme()}
                                        data={this.state.rows}
                                        columns={this.state.cols}
                                        options={options}
                                    />
                                </MuiThemeProvider>
                            </div>
                            <div style={{ display: 'flex', width: '100%', placeContent: 'flex-end', padding: 20 }}>
                                <button
                                    type="button"
                                    onClick={() => this.setState({ itemReport: true })}
                                    style={{ marginRight: 20 }}
                                >
                                    <div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                        <span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
                                    </div>
                                </button>
                                <button
                                    type="button"
                                    disabled={this.state.buttonError == true ? true : false}
                                    onClick={() => this.uploadReportItems()}
                                    style={{}}
                                >
                                    <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                        <span style={{ color: '#fff', fontSize: 11 }}>Save</span>
                                    </div>
                                </button>
                            </div>
                        </div>
                }
                {this.state.add && (
                    <CreateMasterDataCAT
                        onClickClose={() => this.setState({ add: false })}
                        data={this.state.listData}
                        refresh={this.getData.bind(this)}
                        createReportItems={this.createReportItems.bind(this)}
                    />
                )}
                {this.state.edit && (
                    <EditMasterDataCAT
                        onClickClose={() => this.setState({ edit: false })}
                        data={this.state.rowData}
                        refresh={this.getData.bind(this)}
faisalhamdi's avatar
faisalhamdi committed
1173
                        updateReportItems={this.updateReportItems.bind(this)}
Riri Novita's avatar
Riri Novita committed
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228
                    />
                )}
                {this.state.popupError && (
                    <PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} />
                )}
                {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={() => {
                                    String(this.state.judul).includes("MASTER") && String(this.state.judul).includes("DATA") && String(this.state.judul).includes("REPORT") && String(this.state.judul).includes("ITEMS") && !this.state.invalidTemplate ?
                                        this.checkUpload() :
                                        this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning' })
                                }}

                            />
                        </div>
                    </div>
                )}
                {this.state.visibleDelete && (
                    <PopUpDelete
                        rowData={this.state.rowData}
                        name={this.state.reportNameDelete}
                        onClickClose={() => this.setState({ visibleDelete: false })}
                        onClickDelete={this.deleteReport.bind(this)}
                    />
                )}
            </div>
        );
    }
}