Parameter.js 50.3 KB
Newer Older
faisalhamdi's avatar
faisalhamdi committed
1 2 3 4
import React, { Component } from 'react';
import { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles';
import Images from '../../../assets/Images';
import MUIDataTable from "mui-datatables";
5 6
import { InputBase, Snackbar, withStyles } from "@material-ui/core";
import MuiAlert from '@material-ui/lab/Alert';
faisalhamdi's avatar
faisalhamdi committed
7
import CreateParameter from '../Parameter/CreateParameter';
8 9 10 11 12
import api from '../../../api';
import PopUpFailedSave from "../../../library/PopUpFailedSave";
import ReactTooltip from 'react-tooltip';
import UploadFile from "../../../library/Upload";
import { ExcelRenderer } from 'react-excel-renderer';
a.bairuha's avatar
a.bairuha committed
13
import Constant from '../../../library/Constant';
faisalhamdi's avatar
faisalhamdi committed
14 15 16 17

var ct = require("../../../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable());
const options = ct.customOptions();
18
const options2 = ct.customOptions2();
faisalhamdi's avatar
faisalhamdi committed
19

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

faisalhamdi's avatar
faisalhamdi committed
23 24 25 26 27 28
export default class Parameter extends Component {
    constructor(props) {
        super(props)
        this.state = {
            visibleCreate: false,
            visibleEdit: false,
29 30 31
            visibleParameter: true,
            popupError: false,
            data: [],
32 33 34
            dataTable: [],
            alert: false,
            tipeAlert: '',
Deni Rinaldi's avatar
Deni Rinaldi committed
35 36 37
            messageAlert: '',
            create: false,
            edit: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
38 39
            load: false,
            judul: ''
faisalhamdi's avatar
faisalhamdi committed
40
        }
41
        this.fileHandler = this.fileHandler.bind(this);
faisalhamdi's avatar
faisalhamdi committed
42 43 44
    }

    componentDidMount() {
45
        this.getAllParameter()
Deni Rinaldi's avatar
Deni Rinaldi committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
        this.getPermission()
    }

    getPermission() {
        let payload = {
            menu: "parameters"
        }
        api.create().getPermission(payload).then(response => {
            console.log(response)
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({
                        create: response.data.data.create,
                        edit: response.data.data.edit,
                        load: true
                    })
                } else {
                    this.setState({ load: true })
                }
            }
        })
67 68 69 70
    }

    getAllParameter() {
        api.create().getAllParameter().then(response => {
71
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
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
                if (response.ok) {
                    if (response.data.status === "success") {
                        console.log(response);
                        let data = response.data.data
                        let listData = data.map((item, index) => {
                            return [
                                item.setting_id,
                                item.setting_id,
                                item.setting_group,
                                item.setting_type,
                                item.company_name,
                                item.description,
                                item.order,
                                item.value,
                                item.min_value,
                                item.max_value,
                                item.status
                            ]
                        })
                        this.setState({ dataTable: listData, data: response.data.data })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Token")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
102
                } else {
a.bairuha's avatar
a.bairuha committed
103
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
104
                }
105
            } else {
106
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
107 108 109 110
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
111
    openPopUp(rowData, type) {
112 113
        if (type === 'edit') {
            this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
114
                rowData: rowData,
115 116 117 118
                visibleEdit: true
            })
        } else {
            this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
119
                rowData: rowData,
120 121 122 123 124 125 126 127
                visibleCreate: true
            })
        }
    }

    updateParameter = (payload) => {
        this.setState({ visibleEdit: false })
        api.create().updateParameter(payload).then(response => {
128
            console.log(response);
129
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143
                if (response.ok) {
                    if (response.data.status == 'success') {
                        this.getAllParameter()
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Token")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
144
                } else {
a.bairuha's avatar
a.bairuha committed
145
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
146
                }
147
            } else {
148
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
149 150 151 152 153 154 155
            }
        })
    }

    createParameter = (payload) => {
        this.setState({ visibleCreate: false })
        api.create().createParameter(payload).then(response => {
156
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170
                if (response.ok) {
                    if (response.data.status == 'success') {
                        this.getAllParameter()
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Token")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
171
                } else {
a.bairuha's avatar
a.bairuha committed
172
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
173
                }
174
            } else {
175
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
176 177 178 179 180 181 182 183 184 185 186 187 188 189
            }
        })
    }

    downloadFile = async () => {
        let res = await fetch(
            "https://tia.eksad.com/tia-reporting-dev/public/attachment/download_file?fileName=ParameterTemplate&&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;
Deni Rinaldi's avatar
Deni Rinaldi committed
190
            a.download = 'Template Parameter.xlsx';
191 192 193 194 195 196 197 198 199 200 201 202 203 204
            a.click();
        }
    }

    downloadDataTable = async () => {
        let res = await fetch(
            "https://tia.eksad.com/tia-reporting-dev/public/setting/export_setting"
        )
        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;
Deni Rinaldi's avatar
Deni Rinaldi committed
205
            a.download = 'Parameter.xlsx';
206 207 208 209
            a.click();
        }
    }

210 211 212 213 214 215 216
    handleInputChange(e) {
        this.setState({ search: e })
        let body = {
            "keyword": e
        }
        api.create().searchParameter(body).then(response => {
            console.log(response.data);
a.bairuha's avatar
a.bairuha committed
217
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
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
                if (response.ok) {
                    if (response.data.status == 'success') {
                        let data = response.data.data
                        let listData = data.map((item, index) => {
                            return [
                                item.setting_id,
                                item.setting_id,
                                item.setting_group,
                                item.setting_type,
                                item.company_name,
                                item.description,
                                item.order,
                                item.value,
                                item.min_value,
                                item.max_value,
                                item.status
                            ]
                        })
                        this.setState({ dataTable: listData, listData: response.data.data })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Token")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
a.bairuha's avatar
a.bairuha committed
247
                } else {
a.bairuha's avatar
a.bairuha committed
248
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
a.bairuha's avatar
a.bairuha committed
249
                }
250
            } else {
a.bairuha's avatar
a.bairuha committed
251
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
252 253 254 255
            }
        })
    }

256 257 258 259 260 261 262 263
    fileHandler = (event) => {
        let fileObj = event
        ExcelRenderer(fileObj, (err, resp) => {
            // console.log(resp)
            if (err) {
                console.log(err);
            }
            else {
Deni Rinaldi's avatar
Deni Rinaldi committed
264
                // let judul = resp.rows[2]
265 266 267 268 269 270 271 272
                let isi = resp.rows.slice(3)
                let payload = []
                isi.map((item, index) => {
                    if (item.length > 0) {
                        payload.push({
                            id: index + 1,
                            group: item[0],
                            parameter: item[1],
Deni Rinaldi's avatar
Deni Rinaldi committed
273
                            company: item[2],
274
                            description: item[3],
Deni Rinaldi's avatar
Deni Rinaldi committed
275
                            orders: item[4],
276 277 278 279 280 281 282 283 284
                            value: item[5],
                            min_value: item[6],
                            max_value: item[7],
                            start_date: item[8],
                            end_date: item[9],
                        })
                    }
                })
                let body = {
Deni Rinaldi's avatar
Deni Rinaldi committed
285
                    setting: payload
286
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
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
                console.log(resp.rows[1]);
                this.setState({ payload: body, buttonError: false, judul: resp.rows[1][0] })
            }
        });
    }

    checkUpload(){
        api.create().checkUploadParameter(this.state.payload).then(response => {
            console.log(response);
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === "success") {
                        let dataRow = response.data.data.map((item, index) => {
                            return [
                                index + 1,
                                item.group,
                                item.parameter,
                                item.company,
                                item.description,
                                item.orders,
                                item.value,
                                item.min_value,
                                item.max_value,
                                item.start_date,
                                item.end_date,
                                item.error,
                            ]
                        })
                        let columns = [
                            "Data",
                            {
                                name: "Group",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[11] != null) {
                                            check = tableMeta.rowData[11].findIndex((val) => val.field.includes('group'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
326
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
327
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
328 329 330 331 332 333 334
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[11] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[11][check].message} data-for="group">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
335
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
                                                <ReactTooltip border={true} id="group" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Parameter",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[11] != null) {
                                            check = tableMeta.rowData[11].findIndex((val) => val.field.includes('parameter'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
351
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
352
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
353 354 355 356 357 358 359
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[11] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[11][check].message} data-for="parameter">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
360
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
                                                <ReactTooltip border={true} id="parameter" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Company",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[11] != null) {
                                            check = tableMeta.rowData[11].findIndex((val) => val.field.includes('company'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
376
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
377
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
378 379 380 381 382 383 384
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[11] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[11][check].message} data-for="company">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
385
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
                                                <ReactTooltip border={true} id="company" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Description",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[11] != null) {
                                            check = tableMeta.rowData[11].findIndex((val) => val.field.includes('description'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
401
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
402
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
403 404 405 406 407 408 409
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[11] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[11][check].message} data-for="description">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
410
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
                                                <ReactTooltip border={true} id="description" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Order",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[11] != null) {
                                            check = tableMeta.rowData[11].findIndex((val) => val.field.includes('order'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
426
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
427
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
428 429 430 431 432 433 434
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[11] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[11][check].message} data-for="order">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
435
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
                                                <ReactTooltip border={true} id="order" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Value",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[11] != null) {
                                            check = tableMeta.rowData[11].findIndex((val) => val.field.includes('value'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
451
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
452
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
453 454 455 456 457 458 459
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[11] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[11][check].message} data-for="value">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
460
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
                                                <ReactTooltip border={true} id="value" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Min Value",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[11] != null) {
                                            check = tableMeta.rowData[11].findIndex((val) => val.field.includes('min_value'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
476
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
477
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
478 479 480 481 482 483 484
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[11] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[11][check].message} data-for="min_value">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
485
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
                                                <ReactTooltip border={true} id="min_value" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Max Value",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[11] != null) {
                                            check = tableMeta.rowData[11].findIndex((val) => val.field.includes('max_value'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
501
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
502
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
503 504 505 506 507 508 509
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[11] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[11][check].message} data-for="max_value">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
510
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
                                                <ReactTooltip border={true} id="max_value" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Valid To",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[11] != null) {
                                            check = tableMeta.rowData[11].findIndex((val) => val.field.includes('start_date'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
526
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
527
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
528 529 530 531 532 533 534
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[11] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[11][check].message} data-for="start_date">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
535
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
                                                <ReactTooltip border={true} id="start_date" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Valid From",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[11] != null) {
                                            check = tableMeta.rowData[11].findIndex((val) => val.field.includes('end_date'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
551 552
                                            }
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
553 554 555 556 557 558 559 560 561 562 563
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[11] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[11][check].message} data-for="enddate">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="enddate" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
a.bairuha's avatar
a.bairuha committed
564
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
565 566 567 568 569 570 571
                                }
                            },
                            {
                                name: "",
                                options: {
                                    display: false
                                }
a.bairuha's avatar
a.bairuha committed
572
                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
573 574 575
                        ]

                        console.log(dataRow);
576 577
                        this.setState({
                            dataLoaded: true,
Deni Rinaldi's avatar
Deni Rinaldi committed
578 579 580 581
                            cols: columns,
                            rows: dataRow,
                            visibleUpload: false, 
                            visibleParameter: false
582
                        });
Deni Rinaldi's avatar
Deni Rinaldi committed
583 584 585 586 587 588 589 590 591
                    } else {
                        this.setState({ dataLoaded: true, cols: [], rows: [], alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Token")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
592
                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
                } else {
                    this.setState({
                        alert: true, messageAlert: response.data.message, tipeAlert: 'error',
                        dataLoaded: true,
                        cols: [],
                        rows: []
                    });
                }
            } else {
                this.setState({
                    alert: true, messageAlert: response.problem, tipeAlert: 'error',
                    dataLoaded: true,
                    cols: [],
                    rows: []
                });
608
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
609 610

        })
faisalhamdi's avatar
faisalhamdi committed
611 612
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
613 614
    uploadParameter() {
        api.create().uploadParameter(this.state.payload).then(response => {
Deni Rinaldi's avatar
Deni Rinaldi committed
615
            console.log(response)
616
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
617 618 619 620 621 622 623 624 625 626 627 628 629 630
                if (response.ok) {
                    if (response.data.status === "success") {
                        this.getAllParameter()
                        this.setState({ visibleParameter: true, alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Token")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
631
                } else {
a.bairuha's avatar
a.bairuha committed
632
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
633
                }
634 635
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
636
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
637 638 639
        })
    }

640 641 642 643
    closeAlert() {
        this.setState({ alert: false })
    }

faisalhamdi's avatar
faisalhamdi committed
644 645 646 647
    render() {
        const columns = [{
            name: "Action",
            options: {
Deni Rinaldi's avatar
Deni Rinaldi committed
648
                sort: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
649
                filter: false,
faisalhamdi's avatar
faisalhamdi committed
650 651 652
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
653 654 655 656 657 658 659 660 661 662 663 664 665
                            {this.state.edit && (
                                <button
                                    style={{
                                        backgroundColor: 'transparent',
                                        cursor: 'pointer',
                                        borderColor: 'transparent'
                                    }}
                                    onClick={() => this.openPopUp(tableMeta.rowData, 'edit')}
                                // onClick={()=> console.log(tableMeta)}
                                >
                                    <img src={Images.editCopy} />
                                </button>
                            )}
faisalhamdi's avatar
faisalhamdi committed
666 667 668 669
                        </div >
                    );
                }
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
670
        }, {
Deni Rinaldi's avatar
Deni Rinaldi committed
671 672 673 674 675
            name: "ID",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
676
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
677 678 679 680
                        </div >
                    );
                }
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
681
        }, {
faisalhamdi's avatar
faisalhamdi committed
682 683 684 685 686
            name: "Group",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
687
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
688 689 690 691 692 693 694 695 696 697
                        </div >
                    );
                }
            }
        }, {
            name: "Parameter",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
698
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
699 700 701 702 703
                        </div >
                    );
                }
            }
        }, {
704
            name: "Company",
faisalhamdi's avatar
faisalhamdi committed
705 706 707 708
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
709
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
710 711 712 713 714
                        </div >
                    );
                }
            }
        }, {
715
            name: "Description",
faisalhamdi's avatar
faisalhamdi committed
716 717 718 719
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
720
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
721 722 723 724 725 726 727 728 729 730
                        </div >
                    );
                }
            }
        }, {
            name: "Order",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
731
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
732 733 734 735 736 737 738 739 740 741
                        </div >
                    );
                }
            }
        }, {
            name: "Value",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
742
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
743 744 745 746 747 748 749 750 751 752
                        </div >
                    );
                }
            }
        }, {
            name: "Min Value",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
753
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
754 755 756 757 758 759 760 761 762 763
                        </div >
                    );
                }
            }
        }, {
            name: "Max Value",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
764
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
765 766 767 768 769 770 771 772 773 774
                        </div >
                    );
                }
            }
        }, {
            name: "Status",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
775
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
776 777 778 779 780 781 782 783 784 785
                        </div >
                    );
                }
            }
        }]
        const data = [
            ["", "LAPORAN_BULANAN", "BALANCE_SHEET", "Default", "Range Periode Lap", "1", "-", "1", "10", "Aktif"],
            ["", "LAPORAN_BULANAN", "BALANCE_SHEET", "Puninar Group", "Range Periode Lap", "2", "-", "1", "15", "Aktif"],
            ["", "LAPORAN_BULANAN", "BALANCE_SHEET", "TAP Group", "Range Periode Lap", "3", "-", "1", "15", "Aktif"],
            ["", "LAPORAN_BULANAN", "BALANCE_SHEET", "Daya Group", "Range Periode Lap", "4", "-", "1", "20", "Non Aktif"],
786
            ["", "-", "-", "-", "-", "-"]
faisalhamdi's avatar
faisalhamdi committed
787 788 789 790
        ]
        return (
            <div style={{ height: this.props.height }}>
                {/* <Row> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
791
                <div className={"main-color"} style={{ height: 195, width: '100%' }} />
792 793 794 795 796
                <Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
                    <Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
                        {this.state.messageAlert}
                    </Alert>
                </Snackbar>
797 798
                {this.state.visibleParameter === true ?
                    <div>
Deni Rinaldi's avatar
Deni Rinaldi committed
799
                        {this.state.load && (
Deni Rinaldi's avatar
Deni Rinaldi committed
800
                            <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', paddingRight: 25, paddingLeft: 25, marginTop: -180 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
801
                                <label style={{ color: 'white', fontSize: 16, alignSelf: 'center', width: '20%', }}>Parameter</label>
Deni Rinaldi's avatar
Deni Rinaldi committed
802
                                {/* <div style={{ color: 'white', width: '50%', height: 37, display: 'flex', backgroundColor: 'white', borderWidth: 2, alignItems: 'center', borderRadius: 6, paddingLeft: 5, paddingRight: 5, alignSelf: 'center' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
803 804 805 806 807 808 809 810
                                    <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' }}
                                    />
Deni Rinaldi's avatar
Deni Rinaldi committed
811
                                </div> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
812 813 814 815 816 817 818 819 820 821 822 823 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
                                <div style={{ width: '30%', 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.create && (
                                        <a data-tip={'Upload'} data-for="upload">
                                            <button
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    margin: 5
                                                }}
                                                onClick={() => this.setState({ visibleUpload: true })}
                                            >
                                                <img src={Images.upload} />
                                            </button>
                                        </a>
                                    )}
                                    <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>
                                    <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
                                    {this.state.create && (
                                        <a data-tip={'Add New'} data-for="create">
                                            <button
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    margin: 5,
                                                    marginRight: 20
                                                }}
                                                onClick={() => this.setState({ visibleCreate: true })}
                                            >
                                                <img src={Images.add} />
                                            </button>
                                        </a>
                                    )}

                                    <ReactTooltip multiline={false} border={true} id="create" place="bottom" type="light" effect="solid" />
                                </div>
876
                            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
877 878

                        )}
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894
                        <div style={{ padding: 25 }}>
                            <MuiThemeProvider theme={getMuiTheme()}>
                                <MUIDataTable
                                    theme={getMuiTheme()}
                                    data={this.state.dataTable}
                                    columns={columns}
                                    options={options}
                                />
                            </MuiThemeProvider>

                        </div>
                    </div>
                    :
                    <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>
faisalhamdi's avatar
faisalhamdi committed
895
                        </div>
896
                        <div style={{ padding: 25 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
897
                            {this.state.dataLoaded && (
898 899 900 901 902 903 904 905
                                <MuiThemeProvider theme={getMuiTheme()}>
                                    <MUIDataTable
                                        theme={getMuiTheme()}
                                        data={this.state.rows}
                                        columns={this.state.cols}
                                        options={options2}
                                    />
                                </MuiThemeProvider>
Deni Rinaldi's avatar
Deni Rinaldi committed
906
                            )}
907 908
                        </div>
                        <div style={{ display: 'flex', width: '100%', placeContent: 'flex-end', padding: 20 }}>
faisalhamdi's avatar
faisalhamdi committed
909
                            <button
910 911 912
                                type="button"
                                onClick={() => this.setState({ visibleParameter: true })}
                                style={{ marginRight: 20 }}
faisalhamdi's avatar
faisalhamdi committed
913
                            >
914
                                <div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
915
                                    <span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
916 917 918 919
                                </div>
                            </button>
                            <button
                                type="button"
Deni Rinaldi's avatar
Deni Rinaldi committed
920 921
                                disabled={this.state.buttonError ? true : false}
                                onClick={() => this.uploadParameter()}
922 923 924
                                style={{}}
                            >
                                <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
925
                                    <span style={{ color: '#fff', fontSize: 11 }}>Save</span>
926
                                </div>
faisalhamdi's avatar
faisalhamdi committed
927 928 929
                            </button>
                        </div>
                    </div>
930
                }
faisalhamdi's avatar
faisalhamdi committed
931
                {this.state.visibleCreate && (
932
                    <CreateParameter
faisalhamdi's avatar
faisalhamdi committed
933
                        onClickClose={() => this.setState({ visibleCreate: false })}
934
                        createParameter={this.createParameter.bind(this)}
faisalhamdi's avatar
faisalhamdi committed
935 936 937 938
                    />
                )}

                {this.state.visibleEdit && (
939
                    <CreateParameter
faisalhamdi's avatar
faisalhamdi committed
940 941
                        type={"edit"}
                        onClickClose={() => this.setState({ visibleEdit: false })}
Deni Rinaldi's avatar
Deni Rinaldi committed
942
                        data={this.state.rowData}
943
                        updateParameter={this.updateParameter.bind(this)}
faisalhamdi's avatar
faisalhamdi committed
944 945
                    />
                )}
946
                {this.state.popupError && (
Deni Rinaldi's avatar
Deni Rinaldi committed
947
                    <PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} />
948 949 950 951
                )}
                {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
952
                            <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
953 954 955 956 957 958 959 960 961 962 963
                                <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 })}
                                    >
964
                                        <img src={Images.close} />
965 966 967 968 969 970 971
                                    </button>
                                </div>
                            </div>
                            <UploadFile
                                type={this.state.uploadStatus}
                                percentage={this.state.percentage}
                                result={this.state.result}
972
                                acceptedFiles={["xlsx"]}
973 974 975 976
                                onHandle={(dt) => {
                                    this.fileHandler(dt)
                                    this.setState({ uploadStatus: 'idle', percentage: '0' })
                                }}
Deni Rinaldi's avatar
Deni Rinaldi committed
977 978 979 980 981
                                onUpload={() => {
                                    this.state.judul === "MASTER DATA - PARAMETER" ?
                                        this.checkUpload() :
                                        this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning' })
                                }}
982 983 984 985
                            />
                        </div>
                    </div>
                )}
faisalhamdi's avatar
faisalhamdi committed
986 987 988 989
            </div>
        );
    }
}