Perusahaan.js 41.2 KB
Newer Older
1 2 3 4 5
import React, { Component } from 'react';
import { Container, Row, Col } from "react-bootstrap";
import { makeStyles, createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles';
import { Typography } from '@material-ui/core';
import Images from '../../../assets/Images';
faisalhamdi's avatar
faisalhamdi committed
6
import UploadFile from "../../../library/Upload";
7 8
import MUIDataTable from "mui-datatables";
import { render } from '@testing-library/react';
faisalhamdi's avatar
faisalhamdi committed
9
import { ExcelRenderer } from 'react-excel-renderer';
faisalhamdi's avatar
faisalhamdi committed
10
import CreatePerusahaan from "./CreatePerusahaan";
11
import EditPerusahaan from "./EditPerusahaan"
faisalhamdi's avatar
faisalhamdi committed
12
import VisualPerusahaan from "./VisualPerusahaan";
faisalhamdi's avatar
faisalhamdi committed
13
import api from "../../../api";
14
import ReactTooltip from 'react-tooltip';
faisalhamdi's avatar
faisalhamdi committed
15 16
import MuiAlert from '@material-ui/lab/Alert';
import { TextField, InputBase, Snackbar, withStyles } from "@material-ui/core";
17
import PopUpFailedSave from '../../../library/PopUpFailedSave';
a.bairuha's avatar
a.bairuha committed
18
import Constant from '../../../library/Constant';
19 20 21 22

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

faisalhamdi's avatar
faisalhamdi committed
25 26 27
const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);

28 29 30 31 32 33
export default class Perusahaan extends Component {
    constructor(props) {
        super(props)
        this.state = {
            visibleCreate: false,
            visibleEdit: false,
faisalhamdi's avatar
faisalhamdi committed
34
            visibleVisual: false,
faisalhamdi's avatar
faisalhamdi committed
35 36 37 38 39 40 41
            dataTable: [],
            listData: [],
            data: [],
            search: "",
            visiblePerusahaan: true,
            cols: null,
            rows: null,
42
            dataLoaded: false,
faisalhamdi's avatar
faisalhamdi committed
43 44 45
            popupError: false,
            alert: false,
            tipeAlert: '',
Deni Rinaldi's avatar
Deni Rinaldi committed
46 47 48 49
            messageAlert: '',
            create: false,
            edit: false,
            load: false
50
        }
faisalhamdi's avatar
faisalhamdi committed
51 52 53 54 55 56 57 58 59 60
        this.fileHandler = this.fileHandler.bind(this);
    }

    fileHandler = (event) => {
        let fileObj = event
        ExcelRenderer(fileObj, (err, resp) => {
            if (err) {
                console.log(err);
            }
            else {
61 62 63 64 65 66 67 68
                let judul = resp.rows[2]
                let isi = resp.rows.slice(3)
                let payload = []
                isi.map((item, index) => {
                    if (item.length > 0) {
                        payload.push({
                            "id": index + 1,
                            "company_name": item[0],
69
                            "company_parent": item[1] === undefined ? null : item[1],
70 71 72 73 74 75 76 77 78 79 80 81
                            "unit_bisnis": item[2],
                            "startDate": item[3],
                            "endDate": item[4],
                        })
                    }
                })
                let body = {
                    company: payload
                }
                this.setState({ payload: body, buttonError: false })
                api.create().checkUploadPerusahaan(body).then(response => {
                    console.log(response);
a.bairuha's avatar
a.bairuha committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
                    if (response.data) {
                        if (response.ok) {
                            if (response.data.status === "success") {
                                let dataRow = response.data.data.map((item, index) => {
                                    return [
                                        index + 1,
                                        item.company_name,
                                        item.company_parent,
                                        item.unit_bisnis,
                                        item.start_date,
                                        item.end_date,
                                        item.error
                                    ]
                                })
                                let columns = [
                                    "Data",
                                    {
                                        name: "Company Name",
                                        options: {
                                            customBodyRender: (val, tableMeta) => {
                                                let check = null
                                                if (tableMeta.rowData[6] != null) {
                                                    check = tableMeta.rowData[6].findIndex((val) => val.field.includes('company_name'))
                                                    if (check > -1) {
                                                        this.setState({ buttonError: true })
                                                    }
                                                }
                                                return (
                                                    <div style={{ display: 'flex' }}>
                                                        {tableMeta.rowData[6] != null && check > -1 ?
                                                            <a data-tip={tableMeta.rowData[6][check].message} data-for="company_name">
                                                                <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="company_name" place="bottom" type="light" effect="solid" />
                                                    </div >
                                                );
120 121
                                            }
                                        }
a.bairuha's avatar
a.bairuha committed
122 123 124 125 126 127 128 129 130 131 132
                                    },
                                    {
                                        name: "Parent Company",
                                        options: {
                                            customBodyRender: (val, tableMeta) => {
                                                let check = null
                                                if (tableMeta.rowData[6] != null) {
                                                    check = tableMeta.rowData[6].findIndex((val) => val.field.includes('company_parent'))
                                                    if (check > -1) {
                                                        this.setState({ buttonError: true })
                                                    }
133
                                                }
a.bairuha's avatar
a.bairuha committed
134 135 136 137 138 139 140 141 142 143 144
                                                return (
                                                    <div style={{ display: 'flex' }}>
                                                        {tableMeta.rowData[6] != null && check > -1 ?
                                                            <a data-tip={tableMeta.rowData[6][check].message} data-for="company_parent">
                                                                <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="company_parent" place="bottom" type="light" effect="solid" />
                                                    </div >
                                                );
145 146
                                            }
                                        }
a.bairuha's avatar
a.bairuha committed
147 148 149 150 151 152 153 154 155 156 157
                                    },
                                    {
                                        name: "Unit Bisnis",
                                        options: {
                                            customBodyRender: (val, tableMeta) => {
                                                let check = null
                                                if (tableMeta.rowData[6] != null) {
                                                    check = tableMeta.rowData[6].findIndex((val) => val.field.includes('unit_bisnis'))
                                                    if (check > -1) {
                                                        this.setState({ buttonError: true })
                                                    }
158
                                                }
a.bairuha's avatar
a.bairuha committed
159 160 161 162 163 164 165 166 167 168 169
                                                return (
                                                    <div style={{ display: 'flex' }}>
                                                        {tableMeta.rowData[6] != null && check > -1 ?
                                                            <a data-tip={tableMeta.rowData[6][check].message} data-for="unit_bisnis">
                                                                <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="unit_bisnis" place="bottom" type="light" effect="solid" />
                                                    </div >
                                                );
170 171
                                            }
                                        }
a.bairuha's avatar
a.bairuha committed
172 173 174 175 176 177 178 179 180 181 182
                                    },
                                    {
                                        name: "Start Date",
                                        options: {
                                            customBodyRender: (val, tableMeta) => {
                                                let check = null
                                                if (tableMeta.rowData[6] != null) {
                                                    check = tableMeta.rowData[6].findIndex((val) => val.field.includes('start_date'))
                                                    if (check > -1) {
                                                        this.setState({ buttonError: true })
                                                    }
183
                                                }
a.bairuha's avatar
a.bairuha committed
184 185 186 187 188 189 190 191 192 193 194
                                                return (
                                                    <div style={{ display: 'flex' }}>
                                                        {tableMeta.rowData[6] != null && check > -1 ?
                                                            <a data-tip={tableMeta.rowData[6][check].message} data-for="startdate">
                                                                <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="startdate" place="bottom" type="light" effect="solid" />
                                                    </div >
                                                );
195 196
                                            }
                                        }
a.bairuha's avatar
a.bairuha committed
197 198 199 200 201 202 203 204 205 206 207
                                    },
                                    {
                                        name: "End Date",
                                        options: {
                                            customBodyRender: (val, tableMeta) => {
                                                let check = null
                                                if (tableMeta.rowData[6] != null) {
                                                    check = tableMeta.rowData[6].findIndex((val) => val.field.includes('end_date'))
                                                    if (check > -1) {
                                                        this.setState({ buttonError: true })
                                                    }
208
                                                }
a.bairuha's avatar
a.bairuha committed
209 210 211 212 213 214 215 216 217 218 219
                                                return (
                                                    <div style={{ display: 'flex' }}>
                                                        {tableMeta.rowData[6] != null && check > -1 ?
                                                            <a data-tip={tableMeta.rowData[6][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 >
                                                );
220 221
                                            }
                                        }
a.bairuha's avatar
a.bairuha committed
222 223 224 225 226 227
                                    },
                                    {
                                        name: "",
                                        options: {
                                            display: false
                                        }
228
                                    }
a.bairuha's avatar
a.bairuha committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
                                ]
        
                                console.log(dataRow);
                                this.setState({
                                    dataLoaded: true,
                                    cols: columns,
                                    rows: dataRow
                                });
                            } 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);
                                    }
                                })
246
                            }
a.bairuha's avatar
a.bairuha committed
247 248 249 250 251
                        } else {
                            this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                        }
                    } else {
                        this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
252 253 254 255
                    }
                    console.log(response);
                })

faisalhamdi's avatar
faisalhamdi committed
256 257
            }
        });
258 259 260
    }

    componentDidMount() {
faisalhamdi's avatar
faisalhamdi committed
261
        this.getData()
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
        this.getPermission()
    }

    getPermission() {
        let payload = {
            menu: "company"
        }
        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
                    })
                }
            }
        })
faisalhamdi's avatar
faisalhamdi committed
285 286 287
    }

    getData() {
faisalhamdi's avatar
faisalhamdi committed
288
        api.create().getPerusahaan().then((response) => {
faisalhamdi's avatar
faisalhamdi committed
289
            console.log(response)
faisalhamdi's avatar
faisalhamdi committed
290
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
                if (response.ok) {
                    if (response.data.status == 'success') {
                        let data = response.data.data
                        let listData = data.sort((a, b) => a.company_id - b.company_id).map((item, index) => {
                            return [index, item.company_id, item.company_name, item.parent_name, item.business_unit_name, 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);
                            }
                        })
                    }
faisalhamdi's avatar
faisalhamdi committed
308
                } else {
a.bairuha's avatar
a.bairuha committed
309
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', dataTable: [] })
faisalhamdi's avatar
faisalhamdi committed
310
                }
faisalhamdi's avatar
faisalhamdi committed
311
            } else {
faisalhamdi's avatar
faisalhamdi committed
312
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', dataTable: [] })
Deni Rinaldi's avatar
Deni Rinaldi committed
313
            }
faisalhamdi's avatar
faisalhamdi committed
314
        })
315 316
    }

faisalhamdi's avatar
faisalhamdi committed
317
    openPopUp(rowData, type) {
faisalhamdi's avatar
faisalhamdi committed
318 319
        if (type === 'edit') {
            this.setState({
faisalhamdi's avatar
faisalhamdi committed
320
                rowData: rowData,
faisalhamdi's avatar
faisalhamdi committed
321 322 323 324
                visibleEdit: true
            })
        } else {
            this.setState({
faisalhamdi's avatar
faisalhamdi committed
325
                rowData: rowData,
faisalhamdi's avatar
faisalhamdi committed
326 327 328 329 330 331 332 333 334 335 336
                visibleCreate: true
            })
        }
    }

    handleInputChange(e) {
        this.setState({ search: e })
        let body = {
            "keyword": e
        }
        api.create().searchPerusahaan(body).then(response => {
faisalhamdi's avatar
faisalhamdi committed
337
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
                if (response.ok) {
                    if (response.data.status == 'success') {
                        let data = response.data.data
                        let listData = data.map((item, index) => {
                            return [index, item.company_id, item.company_name, item.parent_name, item.business_unit_name, 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);
                            }
                        })
                    }
faisalhamdi's avatar
faisalhamdi committed
355
                } else {
a.bairuha's avatar
a.bairuha committed
356
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
faisalhamdi's avatar
faisalhamdi committed
357
                }
faisalhamdi's avatar
faisalhamdi committed
358
            } else {
faisalhamdi's avatar
faisalhamdi committed
359
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
faisalhamdi's avatar
faisalhamdi committed
360 361 362 363 364 365 366
            }
        })
    }

    updatePerusahaan = (payload) => {
        this.setState({ visibleEdit: false })
        api.create().updatePerusahaan(payload).then(response => {
faisalhamdi's avatar
faisalhamdi committed
367
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
368 369 370 371 372 373 374 375 376 377 378 379 380 381
                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' }, () => {
                            if (response.data.message.includes("Token")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
faisalhamdi's avatar
faisalhamdi committed
382
                } else {
a.bairuha's avatar
a.bairuha committed
383
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
faisalhamdi's avatar
faisalhamdi committed
384
                }
faisalhamdi's avatar
faisalhamdi committed
385
            } else {
faisalhamdi's avatar
faisalhamdi committed
386
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
faisalhamdi's avatar
faisalhamdi committed
387 388 389 390 391 392 393
            }
        })
    }

    createPerusahaan = (payload) => {
        this.setState({ visibleCreate: false })
        api.create().createPerusahaan(payload).then(response => {
faisalhamdi's avatar
faisalhamdi committed
394
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
395 396 397 398 399 400 401 402 403 404 405 406 407 408
                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' }, () => {
                            if (response.data.message.includes("Token")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
faisalhamdi's avatar
faisalhamdi committed
409
                } else {
a.bairuha's avatar
a.bairuha committed
410
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
faisalhamdi's avatar
faisalhamdi committed
411
                }
faisalhamdi's avatar
faisalhamdi committed
412
            } else {
faisalhamdi's avatar
faisalhamdi committed
413
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
faisalhamdi's avatar
faisalhamdi committed
414 415 416 417
            }
        })
    }

faisalhamdi's avatar
faisalhamdi committed
418 419
    downloadFile = async () => {
        let res = await fetch(
faisalhamdi's avatar
faisalhamdi committed
420
            "https://tia.eksad.com/tia-reporting-dev/public/attachment/download_file?fileName=CompanyTemplate&&fileType=xlsx"
faisalhamdi's avatar
faisalhamdi committed
421 422 423 424 425 426 427
        )
        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;
faisalhamdi's avatar
faisalhamdi committed
428
            a.download = 'Template Company.xlsx';
faisalhamdi's avatar
faisalhamdi committed
429 430 431 432 433 434
            a.click();
        }
    }

    downloadDataTable = async () => {
        let res = await fetch(
faisalhamdi's avatar
faisalhamdi committed
435
            "https://tia.eksad.com/tia-reporting-dev/public/company/export_company"
faisalhamdi's avatar
faisalhamdi committed
436 437 438 439 440 441 442
        )
        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;
faisalhamdi's avatar
faisalhamdi committed
443
            a.download = 'Company.xlsx';
faisalhamdi's avatar
faisalhamdi committed
444 445 446 447
            a.click();
        }
    }

448 449 450
    uploadPerusahaan() {
        api.create().uploadPerusahaan(this.state.payload).then(response => {
            console.log(response)
faisalhamdi's avatar
faisalhamdi committed
451
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
452 453 454 455 456 457 458 459 460 461 462 463 464 465
                if (response.ok) {
                    if (response.data.status == "success") {
                        this.getData()
                        this.setState({ visiblePerusahaan: 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);
                            }
                        })
                    }
faisalhamdi's avatar
faisalhamdi committed
466
                } else {
a.bairuha's avatar
a.bairuha committed
467
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
faisalhamdi's avatar
faisalhamdi committed
468 469 470 471
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
            }
472 473 474
        })
    }

faisalhamdi's avatar
faisalhamdi committed
475 476 477 478
    closeAlert() {
        this.setState({ alert: false })
    }

479 480 481 482 483 484 485
    render() {
        const columns = [{
            name: "Action",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
486 487 488 489 490 491 492 493 494 495 496 497 498
                            {this.state.edit && (
                                <button
                                    style={{
                                        backgroundColor: 'transparent',
                                        cursor: 'pointer',
                                        borderColor: 'transparent'
                                    }}
                                    // onClick={() => this.setState({ visibleEdit: true, data: tableMeta.rowData })}
                                    onClick={() => this.openPopUp(tableMeta.rowData, 'edit')}
                                >
                                    <img src={Images.editCopy} />
                                </button>
                            )}
499 500 501 502 503 504 505 506 507 508
                        </div >
                    );
                }
            }
        }, {
            name: "ID",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
509
                            <span style={{ color: tableMeta.rowData[5] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
510 511 512 513 514
                        </div >
                    );
                }
            }
        }, {
faisalhamdi's avatar
faisalhamdi committed
515
            name: "Company Name",
516 517 518 519
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
520
                            <span style={{ color: tableMeta.rowData[5] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
521 522 523 524 525
                        </div >
                    );
                }
            }
        }, {
526
            name: "Parent Company",
527 528 529 530
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
531
                            <span style={{ color: tableMeta.rowData[5] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
532 533 534 535 536
                        </div >
                    );
                }
            }
        }, {
faisalhamdi's avatar
faisalhamdi committed
537
            name: "Business Unit",
faisalhamdi's avatar
faisalhamdi committed
538 539 540 541
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
542
                            <span style={{ color: tableMeta.rowData[5] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
543 544 545 546 547 548 549 550 551 552
                        </div >
                    );
                }
            }
        }, {
            name: "Status",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
553
                            <span style={{ color: tableMeta.rowData[5] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
554 555 556 557 558 559
                        </div >
                    );
                }
            }
        }]
        const data = [
faisalhamdi's avatar
faisalhamdi committed
560 561 562 563
            ["", "1", "Triputra Agro Persada Group", "Triputra Investindo Arya", "Agrobisnis", "5", "Aktif"],
            ["", "2", "Gawi Bahandep Sawit Mekar", "Triputra Agro Persada Group", "Agrobisnis", "2", "Aktif"],
            ["", "3", "Puninar Group", "Triputra Investindo Arya", "Service", "5", "Aktif"],
            ["", "4", "Puninar Infinite Raya", "Puninar Group", "Service", "5", "Non Aktif"],
564
            ["", "-", "-", "-", "-", "-"],
565 566 567 568
        ]
        return (
            <div style={{ height: this.props.height }}>
                {/* <Row> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
569
                <div className={"main-color"} style={{ height: 195, width: '100%' }} />
faisalhamdi's avatar
faisalhamdi committed
570 571 572 573 574
                <Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
                    <Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
                        {this.state.messageAlert}
                    </Alert>
                </Snackbar>
faisalhamdi's avatar
faisalhamdi committed
575
                {this.state.visiblePerusahaan === true ?
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
                    this.state.load && (
                        <div>
                            <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', paddingRight: 25, paddingLeft: 25, marginTop: -118 }}>
                                <label style={{ color: 'white', fontSize: 16, alignSelf: 'center', width: '20%', }}>Master Data - Company</label>
                                <div style={{ color: 'white', width: '50%', height: 37, display: 'flex', backgroundColor: 'white', borderWidth: 2, alignItems: 'center', borderRadius: 6, paddingLeft: 5, paddingRight: 5, alignSelf: 'center' }}>
                                    <img src={Images.searchBlack} style={{ marginRight: 10 }} />
                                    <InputBase
                                        style={{ width: '100%' }}
                                        placeholder="Search"
                                        value={this.state.search}
                                        onChange={(e) => this.handleInputChange(e.target.value)}
                                        inputProps={{ 'aria-label': 'naked' }}
                                    />
                                </div>
                                <div style={{ width: '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" />
Deni Rinaldi's avatar
Deni Rinaldi committed
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
                                    {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>
                                    )}
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
                                    <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" />
                                    <a data-tip={'Visualization'} data-for="visual">
                                        <button
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent',
                                                margin: 5
                                            }}
                                            onClick={() => null}
                                        >
                                            <img src={Images.visualisasi} onClick={() => this.setState({ visibleVisual: true, visiblePerusahaan: false })} />
                                        </button>
                                    </a>
                                    <ReactTooltip border={true} id="visual" place="bottom" type="light" effect="solid" />
Deni Rinaldi's avatar
Deni Rinaldi committed
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
                                    {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>
                                    )}
665 666
                                    <ReactTooltip border={true} id="create" place="bottom" type="light" effect="solid" />
                                </div>
faisalhamdi's avatar
faisalhamdi committed
667
                            </div>
668 669 670 671 672 673 674 675 676
                            <div style={{ padding: 25 }}>
                                <MuiThemeProvider theme={getMuiTheme()}>
                                    <MUIDataTable
                                        theme={getMuiTheme()}
                                        data={this.state.dataTable}
                                        columns={columns}
                                        options={options}
                                    />
                                </MuiThemeProvider>
faisalhamdi's avatar
faisalhamdi committed
677

678
                            </div>
faisalhamdi's avatar
faisalhamdi committed
679
                        </div>
680
                    )
faisalhamdi's avatar
faisalhamdi committed
681
                    :
682
                    this.state.visibleVisual === true ?
683
                        <VisualPerusahaan
Deni Rinaldi's avatar
Deni Rinaldi committed
684 685
                            buttonCreate={this.state.create}
                            buttonEdit={this.state.edit}
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
                            onClickClose={() => this.setState({ visibleVisual: false, visiblePerusahaan: true })}
                            height={this.props.height}
                        />
                        :
                        <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 }}>
                                {this.state.dataLoaded && (
                                    <MuiThemeProvider theme={getMuiTheme()}>
                                        <MUIDataTable
                                            theme={getMuiTheme()}
                                            data={this.state.rows}
                                            columns={this.state.cols}
                                            options={options2}
                                        />
                                    </MuiThemeProvider>
                                )}
                            </div>
                            <div style={{ display: 'flex', width: '100%', placeContent: 'flex-end', padding: 20 }}>
                                <button
                                    type="button"
                                    onClick={() => this.setState({ visiblePerusahaan: true })}
                                    style={{ marginRight: 20 }}
                                >
                                    <div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
a.bairuha's avatar
a.bairuha committed
713
                                        <span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
714 715 716 717 718 719 720 721
                                    </div>
                                </button>
                                <button
                                    type="button"
                                    onClick={() => this.state.buttonError ? this.setState({ popupError: true }) : this.uploadPerusahaan()}
                                    style={{}}
                                >
                                    <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
a.bairuha's avatar
a.bairuha committed
722
                                        <span style={{ color: '#fff', fontSize: 11 }}>Save</span>
723 724
                                    </div>
                                </button>
faisalhamdi's avatar
faisalhamdi committed
725
                            </div>
726
                        </div>
faisalhamdi's avatar
faisalhamdi committed
727
                }
728

729 730 731
                {this.state.visibleCreate && (
                    <CreatePerusahaan
                        onClickClose={() => this.setState({ visibleCreate: false })}
faisalhamdi's avatar
faisalhamdi committed
732 733
                        type={"create"}
                        createPerusahaan={this.createPerusahaan.bind(this)}
734 735 736 737
                    />
                )}

                {this.state.visibleEdit && (
faisalhamdi's avatar
faisalhamdi committed
738
                    <CreatePerusahaan
739 740
                        type={"edit"}
                        onClickClose={() => this.setState({ visibleEdit: false })}
faisalhamdi's avatar
faisalhamdi committed
741
                        data={this.state.rowData}
faisalhamdi's avatar
faisalhamdi committed
742
                        updatePerusahaan={this.updatePerusahaan.bind(this)}
743 744
                    />
                )}
faisalhamdi's avatar
faisalhamdi committed
745

faisalhamdi's avatar
faisalhamdi committed
746 747 748 749 750 751 752 753 754
                {/* {this.state.visibleEdit && (
                    <EditPerusahaan
                        type={"edit"}
                        onClickClose={() => this.setState({ visibleEdit: false })}
                        data={this.state.listData[this.state.selectIndex]}
                        updatePerusahaan={this.updatePerusahaan.bind(this)}
                    />
                )} */}

755 756 757 758
                {this.state.popupError && (
                    <PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} />
                )}

faisalhamdi's avatar
faisalhamdi committed
759 760 761
                {this.state.visibleUpload && (
                    <div className="test app-popup-show">
                        <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
faisalhamdi's avatar
faisalhamdi committed
762
                            <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
faisalhamdi's avatar
faisalhamdi committed
763 764 765 766 767 768 769 770 771 772 773
                                <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 })}
                                    >
Deni Rinaldi's avatar
Deni Rinaldi committed
774
                                        <img src={Images.close} />
faisalhamdi's avatar
faisalhamdi committed
775 776 777 778 779 780 781
                                    </button>
                                </div>
                            </div>
                            <UploadFile
                                type={this.state.uploadStatus}
                                percentage={this.state.percentage}
                                result={this.state.result}
faisalhamdi's avatar
faisalhamdi committed
782
                                acceptedFiles={["xlsx"]}
faisalhamdi's avatar
faisalhamdi committed
783 784 785 786 787 788 789 790 791
                                onHandle={(dt) => {
                                    this.fileHandler(dt)
                                    this.setState({ uploadStatus: 'idle', percentage: '0' })
                                }}
                                onUpload={() => this.setState({ visibleUpload: false, visiblePerusahaan: false })}
                            />
                        </div>
                    </div>
                )}
792 793 794
            </div>
        );
    }
faisalhamdi's avatar
faisalhamdi committed
795
}