ReportItems.js 70.5 KB
Newer Older
EKSAD's avatar
EKSAD committed
1
import React, { Component } from "react";
2
import { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles';
syadziy's avatar
syadziy committed
3
import Images from "../../../assets/Images";
EKSAD's avatar
EKSAD committed
4
import MUIDataTable from "mui-datatables";
5
import { InputBase, Snackbar, Tooltip, withStyles } from "@material-ui/core";
EKSAD's avatar
EKSAD committed
6
import { ExcelRenderer } from 'react-excel-renderer';
syadziy's avatar
syadziy committed
7
import UploadFile from "../../../library/Upload";
8
import MuiAlert from '@material-ui/lab/Alert';
syadziy's avatar
syadziy committed
9 10 11 12
import CreateReportItems from "./CreateReportItems";
import EditReportItems from "./EditReportItems";
import VisualReportItems from "./VisualReportItems";
import api from "../../../api";
EKSAD's avatar
EKSAD committed
13
import ReactTooltip from "react-tooltip";
syadziy's avatar
syadziy committed
14 15 16
import PopUpFailedSave from "../../../library/PopUpFailedSave";
import Constant from "../../../library/Constant";
import PopUpDelete from "../../../library/PopUpDelete";
d.arizona's avatar
d.arizona committed
17 18
import { css } from "@emotion/core";
import PropagateLoader from "react-spinners/PropagateLoader"
EKSAD's avatar
EKSAD committed
19

20 21 22 23 24 25 26 27 28
const LightTooltip = withStyles((theme) => ({
    tooltip: {
        backgroundColor: theme.palette.common.white,
        color: 'rgba(0, 0, 0, 0.87)',
        boxShadow: theme.shadows[1],
        fontSize: 11,
    },
}))(Tooltip);

syadziy's avatar
syadziy committed
29
var ct = require("../../../library/CustomTable");
EKSAD's avatar
EKSAD committed
30 31 32 33
const getMuiTheme = () => createMuiTheme(ct.customTable());
const options = ct.customOptions();
const options2 = ct.customOptions2();

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

EKSAD's avatar
EKSAD committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50
export default class ReportItems extends Component {
    constructor(props) {
        super(props)
        this.state = {
            dataTable: [],
            listData: [],
            data: [],
            search: "",
            itemReport: true,
            visualisasi: false,
            add: false,
            edit: false,
            dataLoaded: false,
            cols: null,
EKSAD's avatar
EKSAD committed
51
            rows: null,
52 53 54
            popupError: false,
            alert: false,
            tipeAlert: '',
a.bairuha's avatar
a.bairuha committed
55
            messageAlert: '',
Deni Rinaldi's avatar
Deni Rinaldi committed
56 57
            buttonCreate: false,
            buttonEdit: false,
d.arizona's avatar
d.arizona committed
58
            buttonDelete: false,
EKSAD's avatar
EKSAD committed
59
            load: false,
a.bairuha's avatar
a.bairuha committed
60 61
            judul: '',
            reportNameDelete: '',
EKSAD's avatar
EKSAD committed
62
            visibleDelete: false,
d.arizona's avatar
d.arizona committed
63 64
            invalidTemplate: false,
            loading: false
EKSAD's avatar
EKSAD committed
65
        }
d.arizona's avatar
d.arizona committed
66
        this.myRef = React.createRef()
EKSAD's avatar
EKSAD committed
67 68 69 70 71 72
        this.fileHandler = this.fileHandler.bind(this);
    }

    fileHandler = (event) => {
        let fileObj = event
        ExcelRenderer(fileObj, (err, resp) => {
EKSAD's avatar
EKSAD committed
73
            // console.log(resp)
EKSAD's avatar
EKSAD committed
74
            if (err) {
EKSAD's avatar
EKSAD committed
75
                console.log(err);
EKSAD's avatar
EKSAD committed
76 77
            }
            else {
EKSAD's avatar
EKSAD committed
78 79 80
                let isi = resp.rows.slice(3)
                let payload = []
                isi.map((item, index) => {
81
                    if (item.length > 0) {
EKSAD's avatar
EKSAD committed
82 83
                        payload.push({
                            id: index + 1,
EKSAD's avatar
EKSAD committed
84
                            report: item[0] === undefined ? "" : item[0],
EKSAD's avatar
EKSAD committed
85
                            company: item[1] === undefined ? "" : item[1],
EKSAD's avatar
EKSAD committed
86
                            orders: item[2] === undefined ? "" : item[2],
EKSAD's avatar
EKSAD committed
87
                            description: item[3] === undefined ? "" : item[3],
EKSAD's avatar
EKSAD committed
88
                            parent: item[4] === undefined ? 0 : item[4],
EKSAD's avatar
EKSAD committed
89
                            uom: item[5] === undefined ? "" : item[5],
Deni Rinaldi's avatar
Deni Rinaldi committed
90
                            weight: item[6] === undefined ? "" : item[6],
EKSAD's avatar
EKSAD committed
91 92 93 94
                            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],
a.bairuha's avatar
a.bairuha committed
95 96 97
                            kpi_type: item[11] === undefined ? "" : item[11],
                            max_ach: item[12] === undefined ? "" : item[12],
                            formula_ytd: item[13] === undefined ? "" : item[13],
EKSAD's avatar
EKSAD committed
98 99
                            start_date: item[14] === undefined ? "" : item[14],
                            end_date: item[15] === undefined ? "" : item[15],
100
                            is_can_convert_value: item[16] === undefined ? "" : item[16] === "Yes" || item[16] === "yes" || item[16] === "YES" ? 1 : 0,
EKSAD's avatar
EKSAD committed
101 102 103
                        })
                    }
                })
Riri Novita's avatar
Riri Novita committed
104
                console.log(payload);
EKSAD's avatar
EKSAD committed
105 106 107
                let body = {
                    item_report: payload
                }
EKSAD's avatar
EKSAD committed
108

109
                if (resp.rows[2].length !== 17) {
EKSAD's avatar
EKSAD committed
110 111 112 113 114
                    this.setState({ invalidTemplate: true })
                } else {
                    this.setState({ invalidTemplate: false })
                }

EKSAD's avatar
EKSAD committed
115 116
                console.log(resp.rows[1])
                this.setState({ payload: body, buttonError: false, judul: resp.rows[1][0] })
EKSAD's avatar
EKSAD committed
117 118 119 120
            }
        });
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
121
    checkUpload() {
EKSAD's avatar
EKSAD committed
122 123 124 125 126 127 128 129
        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 [
EKSAD's avatar
EKSAD committed
130
                                item.report,
EKSAD's avatar
EKSAD committed
131 132 133 134 135 136 137 138 139 140
                                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,
a.bairuha's avatar
a.bairuha committed
141 142 143
                                item.kpi_type,
                                item.max_ach,
                                item.formula_ytd,
EKSAD's avatar
EKSAD committed
144 145
                                item.start_date,
                                item.end_date,
Riri Novita's avatar
Riri Novita committed
146
                                item.is_can_convert_value == 1 ? "Yes" : "No",
147
                                item.error,
EKSAD's avatar
EKSAD committed
148 149 150 151 152 153 154 155
                            ]
                        })
                        let columns = [
                            {
                                name: "Report Type",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
156 157
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('report_type'))
EKSAD's avatar
EKSAD committed
158 159
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
EKSAD's avatar
EKSAD committed
160
                                            }
a.bairuha's avatar
a.bairuha committed
161
                                        }
EKSAD's avatar
EKSAD committed
162 163
                                        return (
                                            <div style={{ display: 'flex' }}>
164 165
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
EKSAD's avatar
EKSAD committed
166
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
167
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
168
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
a.bairuha's avatar
a.bairuha committed
169
                                                }
EKSAD's avatar
EKSAD committed
170 171 172 173 174 175 176 177 178 179
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Company Name",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
180 181
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('company'))
EKSAD's avatar
EKSAD committed
182 183
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
EKSAD's avatar
EKSAD committed
184
                                            }
a.bairuha's avatar
a.bairuha committed
185
                                        }
EKSAD's avatar
EKSAD committed
186 187
                                        return (
                                            <div style={{ display: 'flex' }}>
188 189
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
EKSAD's avatar
EKSAD committed
190
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
191
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
192
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
a.bairuha's avatar
a.bairuha committed
193
                                                }
EKSAD's avatar
EKSAD committed
194 195 196 197 198 199 200 201 202 203
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Order",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
204 205
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('orders'))
EKSAD's avatar
EKSAD committed
206 207
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
EKSAD's avatar
EKSAD committed
208
                                            }
a.bairuha's avatar
a.bairuha committed
209
                                        }
EKSAD's avatar
EKSAD committed
210 211
                                        return (
                                            <div style={{ display: 'flex' }}>
212 213
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
214 215
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
216
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === null ? "Empty" : val}</span>
a.bairuha's avatar
a.bairuha committed
217
                                                }
EKSAD's avatar
EKSAD committed
218 219 220 221 222 223 224 225 226 227
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Description",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
228 229
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('description'))
EKSAD's avatar
EKSAD committed
230 231
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
EKSAD's avatar
EKSAD committed
232
                                            }
a.bairuha's avatar
a.bairuha committed
233
                                        }
EKSAD's avatar
EKSAD committed
234 235
                                        return (
                                            <div style={{ display: 'flex' }}>
236 237
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
EKSAD's avatar
EKSAD committed
238
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
239
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
240
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
a.bairuha's avatar
a.bairuha committed
241
                                                }
EKSAD's avatar
EKSAD committed
242 243 244 245 246 247 248 249 250 251
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Parent ID",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
252 253
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('parent'))
EKSAD's avatar
EKSAD committed
254 255
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
EKSAD's avatar
EKSAD committed
256
                                            }
a.bairuha's avatar
a.bairuha committed
257
                                        }
EKSAD's avatar
EKSAD committed
258 259
                                        return (
                                            <div style={{ display: 'flex' }}>
260 261
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
262 263
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
264
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
a.bairuha's avatar
a.bairuha committed
265
                                                }
EKSAD's avatar
EKSAD committed
266 267 268 269 270 271 272 273 274 275
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "UOM",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
276 277
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('uom'))
EKSAD's avatar
EKSAD committed
278 279
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
EKSAD's avatar
EKSAD committed
280
                                            }
a.bairuha's avatar
a.bairuha committed
281
                                        }
EKSAD's avatar
EKSAD committed
282 283
                                        return (
                                            <div style={{ display: 'flex' }}>
284 285
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
286 287
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
288
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
a.bairuha's avatar
a.bairuha committed
289
                                                }
EKSAD's avatar
EKSAD committed
290 291 292 293 294 295 296 297 298 299
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Weight",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
300 301
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('weight'))
EKSAD's avatar
EKSAD committed
302 303
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
EKSAD's avatar
EKSAD committed
304
                                            }
a.bairuha's avatar
a.bairuha committed
305
                                        }
EKSAD's avatar
EKSAD committed
306 307
                                        return (
                                            <div style={{ display: 'flex' }}>
308 309
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
310 311
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
312
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
a.bairuha's avatar
a.bairuha committed
313
                                                }
EKSAD's avatar
EKSAD committed
314 315 316 317 318 319 320 321 322 323
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Data Type",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
324 325
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('type_report'))
EKSAD's avatar
EKSAD committed
326 327
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
EKSAD's avatar
EKSAD committed
328
                                            }
a.bairuha's avatar
a.bairuha committed
329
                                        }
EKSAD's avatar
EKSAD committed
330 331
                                        return (
                                            <div style={{ display: 'flex' }}>
332 333
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
EKSAD's avatar
EKSAD committed
334
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
335
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
336
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
a.bairuha's avatar
a.bairuha committed
337
                                                }
EKSAD's avatar
EKSAD committed
338 339 340 341 342 343 344 345 346 347
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Formula",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
348 349
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('formula'))
EKSAD's avatar
EKSAD committed
350 351
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
EKSAD's avatar
EKSAD committed
352
                                            }
a.bairuha's avatar
a.bairuha committed
353
                                        }
EKSAD's avatar
EKSAD committed
354 355
                                        return (
                                            <div style={{ display: 'flex' }}>
356 357
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
358 359
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
360
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
a.bairuha's avatar
a.bairuha committed
361
                                                }
EKSAD's avatar
EKSAD committed
362 363 364 365 366 367 368 369 370 371
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "True Value",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
372 373
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('condition_it_should_be'))
EKSAD's avatar
EKSAD committed
374 375
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
EKSAD's avatar
EKSAD committed
376
                                            }
a.bairuha's avatar
a.bairuha committed
377
                                        }
EKSAD's avatar
EKSAD committed
378 379
                                        return (
                                            <div style={{ display: 'flex' }}>
380 381
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
382 383
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
384
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
a.bairuha's avatar
a.bairuha committed
385
                                                }
EKSAD's avatar
EKSAD committed
386 387 388 389 390 391 392 393 394 395
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "False Condition",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
396 397
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('condition_if_wrong'))
EKSAD's avatar
EKSAD committed
398 399
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
EKSAD's avatar
EKSAD committed
400
                                            }
a.bairuha's avatar
a.bairuha committed
401
                                        }
EKSAD's avatar
EKSAD committed
402 403
                                        return (
                                            <div style={{ display: 'flex' }}>
404 405
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
406 407
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
408
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
a.bairuha's avatar
a.bairuha committed
409
                                                }
EKSAD's avatar
EKSAD committed
410 411 412 413 414
                                            </div >
                                        );
                                    }
                                }
                            },
a.bairuha's avatar
a.bairuha committed
415 416 417 418 419
                            {
                                name: "KPI Type",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
420 421
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('kpi_type'))
a.bairuha's avatar
a.bairuha committed
422 423 424 425 426 427
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
428 429
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
430 431
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
432
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
a.bairuha's avatar
a.bairuha committed
433 434 435 436 437 438 439 440 441 442 443
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Max Achievement",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
444 445
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('max_ach'))
a.bairuha's avatar
a.bairuha committed
446 447 448 449 450 451
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
452 453
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
454 455
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
456
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
a.bairuha's avatar
a.bairuha committed
457 458 459 460 461 462 463 464 465 466 467
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Formula YTD",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
468 469
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('formula_ytd'))
a.bairuha's avatar
a.bairuha committed
470 471 472 473 474 475
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
476 477
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
478 479
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
480
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
a.bairuha's avatar
a.bairuha committed
481 482 483 484 485 486
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
EKSAD's avatar
EKSAD committed
487 488 489 490 491
                            {
                                name: "Valid From",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
492 493
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('start_date'))
EKSAD's avatar
EKSAD committed
494 495
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
EKSAD's avatar
EKSAD committed
496
                                            }
a.bairuha's avatar
a.bairuha committed
497
                                        }
EKSAD's avatar
EKSAD committed
498 499
                                        return (
                                            <div style={{ display: 'flex' }}>
500 501
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
EKSAD's avatar
EKSAD committed
502
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
503
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
504
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
a.bairuha's avatar
a.bairuha committed
505
                                                }
EKSAD's avatar
EKSAD committed
506 507 508 509 510 511 512 513 514 515
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Valid To",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
516 517
                                        if (tableMeta.rowData[17] != null) {
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('end_date'))
EKSAD's avatar
EKSAD committed
518 519
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
EKSAD's avatar
EKSAD committed
520
                                            }
a.bairuha's avatar
a.bairuha committed
521
                                        }
EKSAD's avatar
EKSAD committed
522 523
                                        return (
                                            <div style={{ display: 'flex' }}>
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][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: "Convertible",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[17] != null) {
Riri Novita's avatar
Riri Novita committed
541
                                            check = tableMeta.rowData[17].findIndex((val) => val.field.includes('is_can_convert_value'))
542 543 544 545 546 547 548 549
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[17] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[17][check].message} arrow>
EKSAD's avatar
EKSAD committed
550
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
551
                                                    </LightTooltip> :
EKSAD's avatar
EKSAD committed
552
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
EKSAD's avatar
EKSAD committed
553 554 555
                                                }
                                            </div >
                                        );
EKSAD's avatar
EKSAD committed
556 557
                                    }
                                }
EKSAD's avatar
EKSAD committed
558 559 560 561 562
                            },
                            {
                                name: "",
                                options: {
                                    display: false
a.bairuha's avatar
a.bairuha committed
563
                                }
EKSAD's avatar
EKSAD committed
564 565 566 567 568 569 570
                            }
                        ]

                        // console.log(dataRow);
                        this.setState({
                            dataLoaded: true,
                            cols: columns,
Deni Rinaldi's avatar
Deni Rinaldi committed
571
                            rows: dataRow, visibleUpload: false,
EKSAD's avatar
EKSAD committed
572 573
                            itemReport: false
                        });
a.bairuha's avatar
a.bairuha committed
574
                    } else {
EKSAD's avatar
EKSAD committed
575
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
576
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
EKSAD's avatar
EKSAD committed
577 578 579 580 581 582
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
EKSAD's avatar
EKSAD committed
583
                    }
a.bairuha's avatar
a.bairuha committed
584
                } else {
EKSAD's avatar
EKSAD committed
585
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
a.bairuha's avatar
a.bairuha committed
586
                }
EKSAD's avatar
EKSAD committed
587 588 589 590 591
            } else {
                this.setState({
                    dataLoaded: false,
                    alert: true, messageAlert: response.problem, tipeAlert: 'error'
                });
EKSAD's avatar
EKSAD committed
592
            }
EKSAD's avatar
EKSAD committed
593
        })
EKSAD's avatar
EKSAD committed
594 595
    }

EKSAD's avatar
EKSAD committed
596 597
    componentDidMount() {
        this.getData()
Deni Rinaldi's avatar
Deni Rinaldi committed
598
        this.getPermission()
a.bairuha's avatar
a.bairuha committed
599 600 601 602 603 604 605
    }

    getPermission() {
        let payload = {
            menu: "report items"
        }
        api.create().getPermission(payload).then(response => {
EKSAD's avatar
EKSAD committed
606
            // console.log(response)
a.bairuha's avatar
a.bairuha committed
607 608 609
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
610 611
                        buttonCreate: response.data.data.create,
                        buttonEdit: response.data.data.edit,
d.arizona's avatar
d.arizona committed
612
                        buttonDelete: response.data.data.delete,
Deni Rinaldi's avatar
Deni Rinaldi committed
613
                        load: true
a.bairuha's avatar
a.bairuha committed
614
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
615 616
                } else {
                    this.setState({ load: true })
a.bairuha's avatar
a.bairuha committed
617 618 619
                }
            }
        })
EKSAD's avatar
EKSAD committed
620
    }
EKSAD's avatar
EKSAD committed
621 622

    getData() {
623
        this.setState({ loading: true })
EKSAD's avatar
EKSAD committed
624
        api.create().getReportItems().then((response) => {
Riri Novita's avatar
Riri Novita committed
625
            // console.log(response)
626
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
627 628 629 630
                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) => {
EKSAD's avatar
EKSAD committed
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
                            return [
                                index, 
                                item.item_report_id, 
                                item.report_name, 
                                item.company_name, 
                                item.order, 
                                item.description, 
                                item.parent !== null ? `${item.parent} - ${item.parent_name}` : "" , 
                                item.uom, 
                                item.weight, 
                                item.type_item_report_name, 
                                item.kpi_type, 
                                item.max_ach, 
                                item.formula_ytd, 
                                item.status]
a.bairuha's avatar
a.bairuha committed
646
                        })
Deni Rinaldi's avatar
Deni Rinaldi committed
647
                        this.setState({ dataTable: listData, listData: response.data.data }, () => {
d.arizona's avatar
d.arizona committed
648
                            setTimeout(() => {
649
                                this.setState({ loading: false })
d.arizona's avatar
d.arizona committed
650
                            }, 2000);
Deni Rinaldi's avatar
Deni Rinaldi committed
651
                        })
a.bairuha's avatar
a.bairuha committed
652
                    } else {
d.arizona's avatar
d.arizona committed
653
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
654
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
655 656 657 658 659 660 661
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
662
                } else {
d.arizona's avatar
d.arizona committed
663
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
664
                }
EKSAD's avatar
EKSAD committed
665
            } else {
d.arizona's avatar
d.arizona committed
666
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
EKSAD's avatar
EKSAD committed
667 668 669 670
            }
        })
    }

a.bairuha's avatar
a.bairuha committed
671
    deleteReport(payload) {
EKSAD's avatar
EKSAD committed
672
        // console.log(payload);
a.bairuha's avatar
a.bairuha committed
673 674 675 676 677 678 679 680 681
        let id = String(payload[1])
        api.create().deleteReportItems(id).then(response => {
            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
682
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
                                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' })
            }
        })
    }

EKSAD's avatar
EKSAD committed
699 700 701
    openPopUp(index, type) {
        if (type === 'edit') {
            this.setState({
EKSAD's avatar
EKSAD committed
702
                rowData: index,
EKSAD's avatar
EKSAD committed
703 704
                edit: true
            })
a.bairuha's avatar
a.bairuha committed
705 706 707 708 709 710
        } else if (type === 'delete') {
            this.setState({
                rowData: index,
                reportNameDelete: "[" + String(index[2]) + " - " + String(index[3]) + " - " + String(index[5]) + "]",
                visibleDelete: true
            })
EKSAD's avatar
EKSAD committed
711 712 713 714 715 716 717 718 719 720 721 722 723 724
        } 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);
725
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
726 727 728 729 730 731 732 733 734
                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
735
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
736 737 738 739 740 741 742
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
743
                } else {
a.bairuha's avatar
a.bairuha committed
744
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
745
                }
EKSAD's avatar
EKSAD committed
746
            } else {
747
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
EKSAD's avatar
EKSAD committed
748 749 750 751 752 753 754
            }
        })
    }

    createReportItems = (payload) => {
        this.setState({ add: false })
        api.create().createReportItems(payload).then(response => {
755
            console.log(response);
756
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
757 758 759 760 761 762
                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
763
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
764 765 766 767 768 769 770
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
771
                } else {
a.bairuha's avatar
a.bairuha committed
772
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
773
                }
EKSAD's avatar
EKSAD committed
774
            } else {
775
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
EKSAD's avatar
EKSAD committed
776 777 778 779
            }
        })
    }

EKSAD's avatar
EKSAD committed
780 781
    downloadFile = async () => {
        let res = await fetch(
d.arizona's avatar
d.arizona committed
782
            `${process.env.REACT_APP_URL_MAIN_BE}/public/attachment/download_file?fileName=ItemReportTemplate&&fileType=xlsx`
EKSAD's avatar
EKSAD committed
783 784
        )
        res = await res.blob()
EKSAD's avatar
EKSAD committed
785
        // console.log(res)
EKSAD's avatar
EKSAD committed
786 787 788 789 790 791 792 793 794 795 796
        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 () => {
        let res = await fetch(
d.arizona's avatar
d.arizona committed
797
            `${process.env.REACT_APP_URL_MAIN_BE}/public/item_report/export_item_report`
EKSAD's avatar
EKSAD committed
798 799
        )
        res = await res.blob()
EKSAD's avatar
EKSAD committed
800
        // console.log(res)
EKSAD's avatar
EKSAD committed
801 802 803 804
        if (res.size > 0) {
            let url = window.URL.createObjectURL(res);
            let a = document.createElement('a');
            a.href = url;
805
            a.download = 'Report Items.xlsx';
EKSAD's avatar
EKSAD committed
806 807 808 809
            a.click();
        }
    }

EKSAD's avatar
EKSAD committed
810 811 812
    updateReportItems = (payload) => {
        this.setState({ edit: false })
        api.create().updateReportItems(payload).then(response => {
813
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
814 815 816 817 818 819
                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
820
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
821 822 823 824 825 826 827
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
828
                } else {
a.bairuha's avatar
a.bairuha committed
829
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
830
                }
EKSAD's avatar
EKSAD committed
831
            } else {
832
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
EKSAD's avatar
EKSAD committed
833
            }
EKSAD's avatar
EKSAD committed
834
        })
EKSAD's avatar
EKSAD committed
835
    }
EKSAD's avatar
EKSAD committed
836 837 838

    uploadReportItems() {
        api.create().uploadReportItems(this.state.payload).then(response => {
839
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
840 841 842 843 844 845 846
                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
847
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
848 849 850 851 852 853 854
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
855
                } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
856
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
857
                }
858 859
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
860
            }
EKSAD's avatar
EKSAD committed
861 862
        })
    }
863

864 865 866 867
    closeAlert() {
        this.setState({ alert: false })
    }

d.arizona's avatar
d.arizona committed
868 869
    scrollToMyRef = () => window.scrollTo(0, this.myRef.current.offsetTop)

EKSAD's avatar
EKSAD committed
870 871 872 873
    render() {
        const columns = [{
            name: "Action",
            options: {
EKSAD's avatar
EKSAD committed
874
                sort: false,
EKSAD's avatar
EKSAD committed
875 876
                customBodyRender: (val, tableMeta) => {
                    return (
d.arizona's avatar
d.arizona committed
877
                        <div style={{ display: 'flex' }}>
878
                            {this.state.buttonEdit &&
d.arizona's avatar
d.arizona committed
879 880 881 882 883 884 885 886 887
                                <span>
                                    <a data-tip={'Edit'} data-for="edit">
                                        <button
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent'
                                            }}
                                            onClick={() => this.openPopUp(tableMeta.rowData, 'edit')}
888

d.arizona's avatar
d.arizona committed
889 890 891 892 893 894 895
                                        >
                                            <img src={Images.editCopy} />
                                        </button>
                                    </a>
                                    <ReactTooltip border={true} id="edit" place="bottom" type="light" effect="solid" />
                                </span>
                            }
896
                            {this.state.buttonDelete &&
d.arizona's avatar
d.arizona committed
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915
                                <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 >
EKSAD's avatar
EKSAD committed
916 917 918
                    );
                }
            }
EKSAD's avatar
EKSAD committed
919 920 921 922 923 924 925
        },
        {
            name: "ID",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
EKSAD's avatar
EKSAD committed
926
                            <span style={{ color: tableMeta.rowData[13] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
EKSAD's avatar
EKSAD committed
927 928 929 930 931 932
                        </div >
                    );
                }
            }
        },
        {
933
            name: "Report Type",
EKSAD's avatar
EKSAD committed
934 935 936 937
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
EKSAD's avatar
EKSAD committed
938
                            <span style={{ color: tableMeta.rowData[13] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
EKSAD's avatar
EKSAD committed
939 940 941 942 943 944
                        </div >
                    );
                }
            }
        },
        {
EKSAD's avatar
EKSAD committed
945
            name: "Company Name",
EKSAD's avatar
EKSAD committed
946 947 948 949
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
EKSAD's avatar
EKSAD committed
950
                            <span style={{ color: tableMeta.rowData[13] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
EKSAD's avatar
EKSAD committed
951 952 953 954 955 956 957 958 959 960 961
                        </div >
                    );
                }
            }
        },
        {
            name: "Order",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
EKSAD's avatar
EKSAD committed
962
                            <span style={{ color: tableMeta.rowData[13] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
EKSAD's avatar
EKSAD committed
963 964 965 966 967 968
                        </div >
                    );
                }
            }
        },
        {
969
            name: "Description",
EKSAD's avatar
EKSAD committed
970 971 972 973
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
EKSAD's avatar
EKSAD committed
974
                            <span style={{ color: tableMeta.rowData[13] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
EKSAD's avatar
EKSAD committed
975 976 977 978 979 980 981 982 983 984 985
                        </div >
                    );
                }
            }
        },
        {
            name: "Parent ID",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
EKSAD's avatar
EKSAD committed
986
                            <span style={{ color: tableMeta.rowData[13] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
EKSAD's avatar
EKSAD committed
987 988 989 990 991 992 993 994 995 996 997
                        </div >
                    );
                }
            }
        },
        {
            name: "UOM",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
EKSAD's avatar
EKSAD committed
998
                            <span style={{ color: tableMeta.rowData[13] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
EKSAD's avatar
EKSAD committed
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
                        </div >
                    );
                }
            }
        },
        {
            name: "Weight",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
EKSAD's avatar
EKSAD committed
1010
                            <span style={{ color: tableMeta.rowData[13] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
EKSAD's avatar
EKSAD committed
1011 1012 1013 1014 1015 1016
                        </div >
                    );
                }
            }
        },
        {
1017
            name: "Data Type",
EKSAD's avatar
EKSAD committed
1018 1019 1020 1021
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
EKSAD's avatar
EKSAD committed
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 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
                            <span style={{ color: tableMeta.rowData[13] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        },
        {
            name: "KPI Type",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[13] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        },
        {
            name: "Max Achievement",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[13] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        },
        {
            name: "Formula YTD",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[13] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
EKSAD's avatar
EKSAD committed
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
                        </div >
                    );
                }
            }
        },
        {
            name: "Status",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
EKSAD's avatar
EKSAD committed
1070
                            <span style={{ color: tableMeta.rowData[13] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
EKSAD's avatar
EKSAD committed
1071 1072 1073 1074
                        </div >
                    );
                }
            }
EKSAD's avatar
EKSAD committed
1075
        }
1076 1077 1078 1079 1080 1081 1082 1083
        ]
        const data = [
            ["", "1", "KPI", "TIA", "1", "Financial Perspective", "0", "-", "35%", "Formula", "Aktif"],
            ["", "2", "KPI", "TIA", "2", "Trading Profit", "1", "Rp Bio", "35%", "Formula", "Aktif"],
            ["", "3", "KPI", "TIA", "3", "Revenue", "1", "Rp Bio", "0%", "Formula", "Aktif"],
            ["", "4", "KPI", "TIA", "4", "EBITDA", "1", "Rp Bio", "0%", "Formula", "Non Aktif"],
            ["", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-"],
        ]
d.arizona's avatar
d.arizona committed
1084
        const loadingComponent = (
1085 1086 1087 1088 1089 1090 1091
            <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}
                />
d.arizona's avatar
d.arizona committed
1092
            </div>
1093
        );
EKSAD's avatar
EKSAD committed
1094
        return (
d.arizona's avatar
d.arizona committed
1095
            <div style={{ height: this.props.height }} ref={this.myRef}>
EKSAD's avatar
EKSAD committed
1096
                {/* <Row> */}
EKSAD's avatar
EKSAD committed
1097
                <div className={"main-color"} style={{ height: 195, width: '100%' }} />
1098 1099 1100 1101 1102
                <Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
                    <Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
                        {this.state.messageAlert}
                    </Alert>
                </Snackbar>
d.arizona's avatar
d.arizona committed
1103
                {this.state.loading && loadingComponent}
EKSAD's avatar
EKSAD committed
1104
                {this.state.itemReport === true ?
EKSAD's avatar
EKSAD committed
1105 1106 1107
                    this.state.load && (
                        <div>
                            <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', paddingRight: 25, paddingLeft: 25, marginTop: -182 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
1108 1109
                                <label style={{ color: 'white', fontSize: 16, alignSelf: 'center', width: '50%', }}>Master Data - Report Items</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' }}>
EKSAD's avatar
EKSAD committed
1110 1111 1112 1113 1114 1115 1116 1117 1118
                                        <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> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
                                <div style={{ width: '50%', justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
                                    <a data-tip={'Download Template'} data-for="template">
                                        <button
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent',
                                                margin: 5
                                            }}
                                            onClick={() => this.downloadFile()}
                                        >
                                            <img src={Images.template} />
                                        </button>
                                    </a>
                                    <ReactTooltip border={true} id="template" place="bottom" type="light" effect="solid" />
                                    {this.state.buttonCreate && (
                                        <a data-tip={'Upload'} data-for="upload">
Deni Rinaldi's avatar
Deni Rinaldi committed
1136 1137 1138 1139 1140 1141 1142
                                            <button
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    margin: 5
                                                }}
Deni Rinaldi's avatar
Deni Rinaldi committed
1143
                                                onClick={() => null}
Deni Rinaldi's avatar
Deni Rinaldi committed
1144
                                            >
Deni Rinaldi's avatar
Deni Rinaldi committed
1145
                                                <img src={Images.upload} onClick={() => this.setState({ visibleUpload: true })} />
Deni Rinaldi's avatar
Deni Rinaldi committed
1146 1147
                                            </button>
                                        </a>
Deni Rinaldi's avatar
Deni Rinaldi committed
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
                                    )}
                                    <ReactTooltip border={true} id="upload" place="bottom" type="light" effect="solid" />
                                    <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>
a.bairuha's avatar
a.bairuha committed
1163
                                    <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
Deni Rinaldi's avatar
Deni Rinaldi committed
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
                                    <a data-tip={'Visualization'} data-for="visualisasi">
                                        <button
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent',
                                                margin: 5
                                            }}
                                            onClick={() => this.setState({ visualisasi: true, itemReport: false })}
                                        >
                                            <img src={Images.visualisasi} />
                                        </button>
                                    </a>
a.bairuha's avatar
a.bairuha committed
1177
                                    <ReactTooltip border={true} id="visualisasi" place="bottom" type="light" effect="solid" />
Deni Rinaldi's avatar
Deni Rinaldi committed
1178 1179
                                    {this.state.buttonCreate && (
                                        <a data-tip={'Add New'} data-for="tambah">
Deni Rinaldi's avatar
Deni Rinaldi committed
1180 1181 1182 1183 1184
                                            <button
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
Deni Rinaldi's avatar
Deni Rinaldi committed
1185 1186
                                                    margin: 5,
                                                    marginRight: 20
Deni Rinaldi's avatar
Deni Rinaldi committed
1187 1188
                                                }}
                                            >
Deni Rinaldi's avatar
Deni Rinaldi committed
1189
                                                <img src={Images.add} onClick={() => this.setState({ add: true })} />
Deni Rinaldi's avatar
Deni Rinaldi committed
1190 1191
                                            </button>
                                        </a>
Deni Rinaldi's avatar
Deni Rinaldi committed
1192 1193
                                    )}
                                    <ReactTooltip border={true} id="tambah" place="bottom" type="light" effect="solid" />
Deni Rinaldi's avatar
Deni Rinaldi committed
1194
                                </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
                            </div>
                            <div style={{ padding: 25 }}>
                                <MuiThemeProvider theme={getMuiTheme()}>
                                    <MUIDataTable
                                        theme={getMuiTheme()}
                                        data={this.state.dataTable}
                                        columns={columns}
                                        options={options}
                                    />
                                </MuiThemeProvider>

                            </div>
EKSAD's avatar
EKSAD committed
1207
                        </div>
EKSAD's avatar
EKSAD committed
1208
                    )
1209 1210 1211
                    :
                    this.state.visualisasi == true ?
                        <VisualReportItems
Deni Rinaldi's avatar
Deni Rinaldi committed
1212 1213
                            buttonCreate={this.state.buttonCreate}
                            buttonEdit={this.state.buttonEdit}
a.bairuha's avatar
a.bairuha committed
1214
                            onClickClose={() => this.setState({ visualisasi: false, itemReport: true }, () => this.getData())}
1215
                            height={this.props.height}
EKSAD's avatar
EKSAD committed
1216
                            handleLoading={() => this.setState({ loading: true })}
d.arizona's avatar
d.arizona committed
1217
                            scrollToTop={() => this.scrollToMyRef()}
1218
                        />
Deni Rinaldi's avatar
Deni Rinaldi committed
1219 1220 1221 1222 1223 1224
                        :
                        <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 }}>
EKSAD's avatar
EKSAD committed
1225 1226 1227 1228 1229 1230 1231 1232
                                <MuiThemeProvider theme={getMuiTheme()}>
                                    <MUIDataTable
                                        theme={getMuiTheme()}
                                        data={this.state.rows}
                                        columns={this.state.cols}
                                        options={options}
                                    />
                                </MuiThemeProvider>
Deni Rinaldi's avatar
Deni Rinaldi committed
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245
                            </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"
EKSAD's avatar
EKSAD committed
1246 1247
                                    disabled={this.state.buttonError == true ? true : false}
                                    onClick={() => this.uploadReportItems()}
Deni Rinaldi's avatar
Deni Rinaldi committed
1248 1249 1250 1251 1252 1253 1254
                                    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>
EKSAD's avatar
EKSAD committed
1255 1256 1257
                        </div>
                }
                {this.state.add && (
1258
                    <CreateReportItems
EKSAD's avatar
EKSAD committed
1259
                        onClickClose={() => this.setState({ add: false })}
EKSAD's avatar
EKSAD committed
1260
                        data={this.state.listData}
EKSAD's avatar
EKSAD committed
1261
                        refresh={this.getData.bind(this)}
EKSAD's avatar
EKSAD committed
1262
                        createReportItems={this.createReportItems.bind(this)}
EKSAD's avatar
EKSAD committed
1263
                    />
1264
                )}
EKSAD's avatar
EKSAD committed
1265
                {this.state.edit && (
1266
                    <EditReportItems
EKSAD's avatar
EKSAD committed
1267
                        onClickClose={() => this.setState({ edit: false })}
EKSAD's avatar
EKSAD committed
1268
                        data={this.state.rowData}
EKSAD's avatar
EKSAD committed
1269
                        refresh={this.getData.bind(this)}
EKSAD's avatar
EKSAD committed
1270
                        updateReportItems={this.updateReportItems.bind(this)}
EKSAD's avatar
EKSAD committed
1271
                    />
1272
                )}
EKSAD's avatar
EKSAD committed
1273
                {this.state.popupError && (
1274 1275
                    <PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} />
                )}
EKSAD's avatar
EKSAD committed
1276 1277 1278
                {this.state.visibleUpload && (
                    <div className="test app-popup-show">
                        <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
1279
                            <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
EKSAD's avatar
EKSAD committed
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290
                                <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 })}
                                    >
1291
                                        <img src={Images.close} />
EKSAD's avatar
EKSAD committed
1292 1293 1294 1295 1296 1297 1298
                                    </button>
                                </div>
                            </div>
                            <UploadFile
                                type={this.state.uploadStatus}
                                percentage={this.state.percentage}
                                result={this.state.result}
1299
                                acceptedFiles={["xlsx"]}
EKSAD's avatar
EKSAD committed
1300 1301 1302 1303
                                onHandle={(dt) => {
                                    this.fileHandler(dt)
                                    this.setState({ uploadStatus: 'idle', percentage: '0' })
                                }}
EKSAD's avatar
EKSAD committed
1304
                                onUpload={() => {
r.kurnia's avatar
r.kurnia committed
1305
                                    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 ?
Deni Rinaldi's avatar
Deni Rinaldi committed
1306 1307
                                        this.checkUpload() :
                                        this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning' })
EKSAD's avatar
EKSAD committed
1308
                                }}
Deni Rinaldi's avatar
Deni Rinaldi committed
1309

EKSAD's avatar
EKSAD committed
1310 1311 1312 1313
                            />
                        </div>
                    </div>
                )}
a.bairuha's avatar
a.bairuha committed
1314 1315 1316 1317 1318 1319 1320 1321
                {this.state.visibleDelete && (
                    <PopUpDelete
                        rowData={this.state.rowData}
                        name={this.state.reportNameDelete}
                        onClickClose={() => this.setState({ visibleDelete: false })}
                        onClickDelete={this.deleteReport.bind(this)}
                    />
                )}
1322
            </div>
EKSAD's avatar
EKSAD committed
1323 1324 1325
        );
    }
}