CashFlowMR.js 38.2 KB
Newer Older
Deni Rinaldi's avatar
Deni Rinaldi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
import { createMuiTheme, FormControlLabel, Input, MuiThemeProvider, Paper, TableCell, Tooltip, Typography, withStyles } from '@material-ui/core'
import MUIDataTable from 'mui-datatables';
import React, { Component } from 'react'
import ReactTooltip from 'react-tooltip';
import Images from '../../assets/Images';
import api from '../../api';
import NumberFormat from 'react-number-format';
import * as R from 'ramda';
import { PropagateLoader } from 'react-spinners';
import { ExcelRenderer } from 'react-excel-renderer';
import Constant from '../../library/Constant';
import UploadFile from "../../library/Upload";

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

var ct = require("../../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable3());

const options = ct.customOptionsFixedColumn();

const style = {
    position: "sticky",
    left: 0,
    zIndex: 101,
    background: "white",
};
const style2 = {
    position: "sticky",
    background: "white",
    zIndex: 100,
    top: 0
};

export default class CashFlowMR extends Component {
    constructor(props) {
        super(props)
        this.state = {
            dataTable: [],
            loading: false,
            visibleCFMR: true,
            // valueThreshold: 0,
            minValue: 0,
d.arizona's avatar
d.arizona committed
50 51
            maxValue: 0,
            viewOnly: true
Deni Rinaldi's avatar
Deni Rinaldi committed
52 53 54
        }
    }

d.arizona's avatar
d.arizona committed
55 56 57 58 59 60 61 62 63 64 65
    handleViewOnly() {
        let checkApprover = false
        let checkLastStatus = false
        let checkStatus = false
        let checkPrevRev = false

        if (this.props.isApprover) {
            checkApprover = true
        } else {
            checkApprover = false
        }
d.arizona's avatar
d.arizona committed
66

d.arizona's avatar
d.arizona committed
67 68 69 70
        if (this.props.lastStatus == 'SUBMIT' || this.props.lastStatus == 'REVISION') {
            checkLastStatus = true
        } else {
            checkLastStatus = false
d.arizona's avatar
d.arizona committed
71 72
        }

d.arizona's avatar
d.arizona committed
73 74 75 76 77
        if (this.props.prevRevision) {
            checkPrevRev = true
        } else {
            checkPrevRev = false
        }
d.arizona's avatar
d.arizona committed
78

d.arizona's avatar
d.arizona committed
79
        if (this.props.status === 'revision' || this.props.status === 'not-yet' || this.props.status === 'draft' || this.props.status === 'submitted') {
d.arizona's avatar
d.arizona committed
80 81 82 83
            checkStatus = true
        } else {
            checkStatus = false
        }
d.arizona's avatar
d.arizona committed
84 85
        // console.log(this.props.status)
        // console.log(this.props.lastStatus)
d.arizona's avatar
d.arizona committed
86 87 88 89
        // console.log(checkStatus)
        // console.log(checkLastStatus)
        // console.log(checkApprover)
        // console.log(checkPrevRev)
d.arizona's avatar
d.arizona committed
90
        this.setState({ viewOnly: !checkApprover && checkLastStatus && checkStatus && checkPrevRev })
d.arizona's avatar
d.arizona committed
91
        // this.setState({viewOnly: true})
d.arizona's avatar
d.arizona committed
92 93
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
94
    componentDidMount() {
rifkaki's avatar
rifkaki committed
95
        // this.getItemHierarki()
d.arizona's avatar
d.arizona committed
96
        console.log(this.props.PLBSFAMSubmitted)
d.arizona's avatar
d.arizona committed
97
        this.handleViewOnly()
rifkaki's avatar
rifkaki committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
        this.getSettingControl()
    }

    getSettingControl() {
        let body = {
            group: 'THRESHOLD_CONTROL',
            company_id: this.props.company.company_id,
            type: 'CASH_FLOW'
        }

        api.create().getAllSettingByType(body).then(response => {
            console.log(response)
            if (response.data) {
                if (response.data.status === 'success') {
                    this.setState({
                        minValue: response.data.data[0] ? response.data.data[0].min_value : null,
                        maxValue: response.data.data[0] ? response.data.data[0].max_value : null,
                    }, () => {
                        this.getItemHierarki()
                    })
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
120
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
rifkaki's avatar
rifkaki committed
121 122 123 124 125 126 127 128 129 130 131
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
            }
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
132 133 134 135 136 137 138 139 140
    }

    getItemHierarki() {
        let payload = {
            "report_id": this.props.report_id,
            "revision": Number(this.props.revision),
            "periode": this.props.periode,
            "company_id": this.props.company.company_id,
            "monthly_report_id": this.props.monthlyReportId,
rifkaki's avatar
rifkaki committed
141 142
            "months": this.props.month.month_id,
            "get_for": "edit"
Deni Rinaldi's avatar
Deni Rinaldi committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
        }

        api.create().getHierarkiMontlyReportCF(payload).then(response => {
            console.log(response);
            let dataTable = []
            if (response.data) {
                let res = response.data.data
                const handlePushChild = (item) => {
                    let indexIDzz = dataTable.findIndex((val) => val[1] === item.id)
                    if (indexIDzz === -1) {
                        dataTable.push([
                            item.type_report_id,
                            item.id,
                            item.parent,
                            item.formula,
                            item.level,
                            item.description,
                            { value: item.cash_flow.actual, formula: item.cash_flow.actual_formula },
                            item.order,
                        ])
                    }
                    if (item.children !== null) {
                        if (item.children.length > 0) {
                            item.children.map((items, indexs) => {
                                handlePushChild(items)
                            })
                        }
                    }
                }
                res.map((item, index) => {
                    dataTable.push([
                        item.type_report_id,
                        item.id,
                        item.parent,
                        item.formula,
                        item.level,
                        item.description,
                        { value: item.cash_flow.actual, formula: item.cash_flow.actual_formula },
                        item.order,
                    ])
                    if (item.children !== null) {
                        if (item.children.length > 0) {
                            item.children.map((items, indexs) => {
                                handlePushChild(items)
                            })
                        }
                    }
                })
d.arizona's avatar
d.arizona committed
191
                console.log(dataTable)
Deni Rinaldi's avatar
Deni Rinaldi committed
192 193 194 195 196
                this.setState({ dataTable, loading: false })
            }
        })
    }

Riri Novita's avatar
Riri Novita committed
197
    async downloadAllData() {
d.arizona's avatar
d.arizona committed
198
        let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/cash_flow/monthly_report/export_monthly_report?monthly_report_id=${this.props.monthlyReportId}&&report_id=${this.props.report_id}&&company_id=${this.props.company.company_id}&&year=${this.props.periode}&&revision=${this.props.revision}&&months=${this.props.month.month_id}`
Riri Novita's avatar
Riri Novita committed
199 200
        console.log(url);
        let res = await fetch(
d.arizona's avatar
d.arizona committed
201
            `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/cash_flow/monthly_report/export_monthly_report?monthly_report_id=${this.props.monthlyReportId === null ? "" : this.props.monthlyReportId}&&report_id=${this.props.report_id}&&company_id=${this.props.company.company_id}&&year=${this.props.periode}&&revision=${this.props.revision}&&months=${this.props.month.month_id}`
Riri Novita's avatar
Riri Novita committed
202 203 204 205 206 207 208 209 210 211 212 213
        )
        res = await res.blob()
        this.setState({ loading: false })
        if (res.size > 0) {
            let url = window.URL.createObjectURL(res);
            let a = document.createElement('a');
            a.href = url;
            a.download = 'Monthly Report Cash Flow.xlsx';
            a.click();
        }
    }

d.arizona's avatar
d.arizona committed
214 215 216 217 218 219
    payloadCF(dataTable2) {
        let listCF = []
        console.log(dataTable2)
        dataTable2.map((item, index) => {
            // if (item[6].value == "" || item[6].value == 0 || item[6].value == "0.0") {
            //     item[6].value = this.handleValueFormula(item, index)
d.arizona's avatar
d.arizona committed
220 221 222 223
            listCF.push({
                "item_report_id": item[1],
                "actual": item[0] == 1 ? "" : Number(item[6].value).toFixed(1)
            })
d.arizona's avatar
d.arizona committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
            // } else {
            //     listCF.push({
            //         "item_report_id": item[1],
            //         "actual": item[0] == 1 ? "" : Number(item[6].value).toFixed(1)
            //     })
            // }

        })
        this.createCashFlow(listCF)
    }

    createCashFlow(listCF) {
        let payload = {
            "monthly_report_id": this.props.monthlyReportId,
            "company_id": this.props.company.company_id,
            "periode": this.props.periode,
            "report_id": 13,
            "status": "submitted",
            "months": this.props.month.month_id,
            "cash_flow": listCF
        }
        this.props.createCashFlow(payload)
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
248
    render() {
Deni Rinaldi's avatar
Deni Rinaldi committed
249 250
        let dataTable2 = this.state.dataTable

d.arizona's avatar
d.arizona committed
251 252 253 254 255
        const handleValueFormula = (tableMeta, colIdx) => {
            // loading = true
            // console.log(tableMeta);
            // "@44[M-1]#BS"
            let splitFormula = String(tableMeta.rowData[3]).split(/([()@])/)
Deni Rinaldi's avatar
Deni Rinaldi committed
256 257
            let baru = []
            let anjay = []
d.arizona's avatar
d.arizona committed
258
            // console.log(splitFormula);
Deni Rinaldi's avatar
Deni Rinaldi committed
259 260
            splitFormula.map((item, index) => {
                let items = String(item).substr(Number(String(item).length) - 1, 1)
d.arizona's avatar
d.arizona committed
261 262 263 264
                let subForm = String(item).substr(0, Number(String(item).length) - 1)
                // console.log(item);
                // console.log(items);
                // console.log(subForm);
d.arizona's avatar
d.arizona committed
265

d.arizona's avatar
d.arizona committed
266
                let re = /^[a-zA-Z0-9_]+$/;
Deni Rinaldi's avatar
Deni Rinaldi committed
267
                if (item !== "") {
d.arizona's avatar
d.arizona committed
268 269 270 271 272
                    if (items == ']') {
                        baru.push(String(item))
                    } else if (!re.test(items)) {
                        baru.push(subForm)
                        baru.push(items)
Deni Rinaldi's avatar
Deni Rinaldi committed
273 274 275 276 277 278
                    } else {
                        baru.push(String(item))
                    }
                }
            })

d.arizona's avatar
d.arizona committed
279 280 281
            // console.log(baru);
            let tambahan = false
            let opet = ""
Deni Rinaldi's avatar
Deni Rinaldi committed
282
            baru.map((item, index) => {
d.arizona's avatar
d.arizona committed
283 284 285
                if (item == 'X') {
                    tambahan = true
                } else if (item == '-' || item == '+' || item == '/' || item == '*' || item == '(' || item == ')') {
Deni Rinaldi's avatar
Deni Rinaldi committed
286 287 288
                    anjay.push(item)
                } else {
                    if (String(item).includes('#')) {
d.arizona's avatar
d.arizona committed
289 290 291 292
                        if (String(item).includes('[M-1]')) {
                            let tst = '@' + String(item).replace('[M-1]', '[M1]')
                            // console.log(dataTable2[tableMeta.rowIndex]);
                            // console.log(tableMeta);
rifkaki's avatar
rifkaki committed
293
                            // console.log(tst);
d.arizona's avatar
d.arizona committed
294 295
                            let indexID = dataTable2[tableMeta.rowIndex][6].formula.findIndex((val) => val.item_formula == tst)
                            // console.log(indexID);
d.arizona's avatar
d.arizona committed
296

Deni Rinaldi's avatar
Deni Rinaldi committed
297
                            if (indexID !== -1) {
d.arizona's avatar
d.arizona committed
298
                                let valuezz = dataTable2[tableMeta.rowIndex][6].formula[indexID].value
Deni Rinaldi's avatar
Deni Rinaldi committed
299
                                anjay.push(valuezz == "" ? 0 : valuezz)
d.arizona's avatar
d.arizona committed
300
                                // console.log(valuezz);
Deni Rinaldi's avatar
Deni Rinaldi committed
301 302
                            }
                        } else {
d.arizona's avatar
d.arizona committed
303
                            let data = tableMeta.rowData[6].formula == null ? [] : tableMeta.rowData[6].formula
d.arizona's avatar
d.arizona committed
304 305
                            // console.log(data)
                            let indexID = data.findIndex((val) => val.item_formula == String(`@${item}`))
Deni Rinaldi's avatar
Deni Rinaldi committed
306
                            if (indexID !== -1) {
d.arizona's avatar
d.arizona committed
307
                                let valuezz = data[indexID].value
Deni Rinaldi's avatar
Deni Rinaldi committed
308 309 310
                                anjay.push(valuezz == "" ? 0 : valuezz)
                            }
                        }
d.arizona's avatar
d.arizona committed
311 312 313
                    } else {
                        if (String(item).includes('[M-1]')) {
                            let tst = String(item).replace('[M-1]', '')
Deni Rinaldi's avatar
Deni Rinaldi committed
314 315
                            let indexID = dataTable2.findIndex((val) => val[7] == tst)
                            if (indexID !== -1) {
d.arizona's avatar
d.arizona committed
316
                                let valuezz = dataTable2[indexID][8]
Deni Rinaldi's avatar
Deni Rinaldi committed
317 318 319
                                anjay.push(valuezz == "" ? 0 : valuezz)
                            }
                        } else {
d.arizona's avatar
d.arizona committed
320 321
                            let indexID = dataTable2.findIndex((val) => val[7] == item)
                            if (item == 'X-1') {
Deni Rinaldi's avatar
Deni Rinaldi committed
322
                                anjay.push(-1)
d.arizona's avatar
d.arizona committed
323 324 325 326
                            } else if (tambahan) {
                                if (item == '-' || item == '+' || item == '/' || item == '*') {
                                    opet = item
                                } else {
d.arizona's avatar
d.arizona committed
327
                                    anjay.push(opet == '' ? Number(item) : Number(String(opet + String(item))))
d.arizona's avatar
d.arizona committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
                                    tambahan = false
                                    opet = ""
                                }
                            } else {
                                if (indexID !== -1) {
                                    let valuezz = dataTable2[indexID][colIdx].value
                                    if (item == dataTable2[tableMeta.rowIndex][7]) {
                                        anjay.push(0)
                                    } else {
                                        anjay.push(valuezz == "" ? 0 : valuezz)
                                    }
                                } else {
                                    if (item === '(-1)') {
                                        anjay.push(-1)
                                    }
                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
344 345 346 347 348
                            }
                        }
                    }
                }
            })
d.arizona's avatar
d.arizona committed
349

d.arizona's avatar
d.arizona committed
350

Deni Rinaldi's avatar
Deni Rinaldi committed
351

d.arizona's avatar
d.arizona committed
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
            let anjay2 = []
            let kurung = false
            let item1 = []
            anjay.map((item, index) => {
                if (item == "(") {
                    kurung = true
                } else if (item == ")") {
                    kurung = false
                    anjay2.push(item1)
                    item1 = []
                } else {
                    if (kurung) {
                        item1.push(item)
                    } else {
                        anjay2.push(item)
                    }
                }
            })

Deni Rinaldi's avatar
Deni Rinaldi committed
371 372
            let total = 0
            let opt = ""
d.arizona's avatar
d.arizona committed
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
            let totalPrio = 0
            let optPrio = ""
            let prio = false
            anjay2.map((item, index) => {
                if (Array.isArray(item)) {
                    prio = true
                    item.map((items, indexs) => {
                        if (items == "+") {
                            optPrio = "tambah"
                        } else if (items == "-") {
                            optPrio = "kurang"
                        } else if (items == "*") {
                            optPrio = "kali"
                        } else if (items == "/") {
                            optPrio = "bagi"
                        } else {
                            if (optPrio == "tambah") {
                                totalPrio = Number(totalPrio) + Number(items)
                            } else if (optPrio == "kurang") {
                                totalPrio = Number(totalPrio) - Number(items)
                            } else if (optPrio == "kali") {
                                totalPrio = Number(totalPrio) * Number(items)
                            } else if (optPrio == "bagi") {
                                totalPrio = Number(totalPrio) / Number(items) == NaN ? 0 : Number(totalPrio) / Number(items)
                            } else {
                                totalPrio += Number(items)
                            }
                        }
                    })

d.arizona's avatar
d.arizona committed
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
                    // if (index == anjay2.length - 1) {
                    //     if (opt == "tambah") {
                    //         total = Number(total) + Number(totalPrio)
                    //     } else if (opt == "kurang") {
                    //         total = Number(total) - Number(totalPrio)
                    //     } else if (opt == "kali") {
                    //         total = Number(total) * Number(totalPrio)
                    //     } else if (opt == "bagi") {
                    //         total = Number(total) / Number(totalPrio) == NaN ? 0 : Number(total) / Number(totalPrio)
                    //     } else {
                    //         total += Number(totalPrio)
                    //     }
                    // }

                    // if (opt == "") {
                    //     total = Number(Number(total) + Number(totalPrio))
                    // } else {
d.arizona's avatar
d.arizona committed
420 421
                        if (opt == "tambah") {
                            total = Number(total) + Number(totalPrio)
d.arizona's avatar
d.arizona committed
422
                            totalPrio = 0
d.arizona's avatar
d.arizona committed
423 424
                        } else if (opt == "kurang") {
                            total = Number(total) - Number(totalPrio)
d.arizona's avatar
d.arizona committed
425
                            totalPrio = 0
d.arizona's avatar
d.arizona committed
426 427
                        } else if (opt == "kali") {
                            total = Number(total) * Number(totalPrio)
d.arizona's avatar
d.arizona committed
428
                            totalPrio = 0
d.arizona's avatar
d.arizona committed
429 430
                        } else if (opt == "bagi") {
                            total = Number(total) / Number(totalPrio) == NaN ? 0 : Number(total) / Number(totalPrio)
d.arizona's avatar
d.arizona committed
431
                            totalPrio = 0
d.arizona's avatar
d.arizona committed
432
                        }
d.arizona's avatar
d.arizona committed
433 434 435 436 437 438
                    // }
                    // if (tableMeta.rowData[5] == '3.2 Movement of SHL and intercompany loan (nett)') {
                    //     console.log(totalPrio)
                    //     console.log(opt)
                    //     console.log(total)
                    // }
Deni Rinaldi's avatar
Deni Rinaldi committed
439
                } else {
d.arizona's avatar
d.arizona committed
440 441 442 443
                    // const handleReturn = (x,y) => {
                        
                    //     return Number(totalXYZ)
                    // }
d.arizona's avatar
d.arizona committed
444 445 446 447
                    if (item == "+") {
                        opt = "tambah"
                        if (prio) {
                            total = Number(Number(totalPrio) + Number(total))
d.arizona's avatar
d.arizona committed
448
                            // total = handleReturn()
d.arizona's avatar
d.arizona committed
449 450 451 452 453 454 455 456
                            prio = false
                            totalPrio = 0
                            optPrio = ""
                        }
                    } else if (item == "-") {
                        opt = "kurang"
                        if (prio) {
                            total = Number(Number(totalPrio) + Number(total))
d.arizona's avatar
d.arizona committed
457
                            // total = handleReturn()
d.arizona's avatar
d.arizona committed
458 459 460 461 462 463 464 465
                            prio = false
                            totalPrio = 0
                            optPrio = ""
                        }
                    } else if (item == "*") {
                        opt = "kali"
                        if (prio) {
                            total = Number(Number(totalPrio) + Number(total))
d.arizona's avatar
d.arizona committed
466
                            // total = handleReturn()
d.arizona's avatar
d.arizona committed
467 468 469 470 471 472 473 474
                            prio = false
                            totalPrio = 0
                            optPrio = ""
                        }
                    } else if (item == "/") {
                        opt = "bagi"
                        if (prio) {
                            total = Number(Number(totalPrio) + Number(total))
d.arizona's avatar
d.arizona committed
475
                            // total = handleReturn()
d.arizona's avatar
d.arizona committed
476 477 478 479
                            prio = false
                            totalPrio = 0
                            optPrio = ""
                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
480
                    } else {
d.arizona's avatar
d.arizona committed
481 482 483 484 485 486 487 488 489 490 491
                        if (opt == "tambah") {
                            total = Number(total) + Number(item)
                        } else if (opt == "kurang") {
                            total = Number(total) - Number(item)
                        } else if (opt == "kali") {
                            total = Number(total) * Number(item)
                        } else if (opt == "bagi") {
                            total = Number(total) / Number(item) == NaN ? 0 : Number(total) / Number(item)
                        } else {
                            total += Number(item)
                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
492 493 494 495
                    }
                }
            })

d.arizona's avatar
d.arizona committed
496 497 498 499 500 501 502 503 504
            // if (tableMeta.rowData[5] == '3.2 Movement of SHL and intercompany loan (nett)' || tableMeta.rowData[5] == '3.6 Other') {
                // console.log(tableMeta.rowData[5])
                // console.log(splitFormula)
                // console.log(baru)
                // console.log(anjay)
                // console.log(anjay2)
                // console.log(total)
            // }

d.arizona's avatar
d.arizona committed
505
            dataTable2[tableMeta.rowIndex][6].value = total
Deni Rinaldi's avatar
Deni Rinaldi committed
506 507 508 509 510

            return total
        }


Deni Rinaldi's avatar
Deni Rinaldi committed
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
        let columns = [
            {
                name: "",
                options: {
                    display: false
                }
            },
            {
                name: "",
                options: {
                    display: false
                }
            },
            {
                name: "",
                options: {
                    display: false
                }
            },
            {
                name: "",
                options: {
                    display: false
                }
            },
            {
                name: "",
                options: {
                    display: false
                }
            },
            {
                name: "Account",
                options: {
                    customHeadRender: (columnMeta) => (
                        <TableCell key={columnMeta.index} style={{ ...style, top: 0, zIndex: 102, backgroundColor: '#1c71b8', width: 300 }}>
                            <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'left' }}>{columnMeta.name}</Typography>
                        </TableCell>
                    ),
                    setCellProps: () => ({ style }),
                    customBodyRender: (val, tableMeta) => {
                        return (
                            <div style={{ width: 300 }}>
                                {tableMeta.rowData[0] === null ?
                                    tableMeta.rowData[4] == 0 ?
                                        <LightTooltip title={"Report Items Not Registered"} arrow>
                                            <span style={{ fontSize: 12, fontWeight: 'bold', color: 'red' }}>{String(val).toUpperCase()}</span>
                                        </LightTooltip> :
                                        <div style={{ paddingLeft: 20 * Number(tableMeta.rowData[4]) }}>
                                            <LightTooltip title={"Report Items Not Registered"} arrow>
                                                <span style={{ fontSize: 12, color: 'red' }}>{tableMeta.rowData[0] === 4 ? "" : val}</span>
                                            </LightTooltip>
                                        </div>
                                    :
                                    tableMeta.rowData[4] == 0 ?
                                        <span style={{ fontSize: 12, fontWeight: 'bold' }}>{String(tableMeta.rowData[0] === 4 ? "" : val).toUpperCase()}</span>
                                        :
                                        <div style={{ paddingLeft: 20 * Number(tableMeta.rowData[4]) }}>
                                            <span style={{ fontSize: 12 }}>{tableMeta.rowData[0] === 4 ? "" : val}</span>
                                        </div>
                                }
                            </div>
                        )
                    }
                }
            }, {
                name: "Actual",
                options: {
                    customHeadRender: (columnMeta) => (
                        // dataTable2.length > 0 ?
                        //     <TableCell style={{ ...style2, top: 0, zIndex: 102, backgroundColor: '#1c71b8', width: 96 }}>
                        //         <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                        //     </TableCell> :
Deni Rinaldi's avatar
Deni Rinaldi committed
584 585 586
                        <TableCell style={{ ...style2, top: 0, zIndex: 102, backgroundColor: '#1c71b8', width: 96 }}>
                            <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                        </TableCell>
Deni Rinaldi's avatar
Deni Rinaldi committed
587 588 589 590 591 592 593 594 595 596
                    ),
                    setCellProps: () => ({
                        style: {
                            position: "sticky",
                            background: "white",
                            zIndex: 101,
                            left: 350
                        }
                    }),
                    customBodyRender: (value, tableMeta, updateValue) => {
d.arizona's avatar
d.arizona committed
597
                        // console.log(tableMeta);
Deni Rinaldi's avatar
Deni Rinaldi committed
598 599
                        return (
                            <div style={{ textAlign: 'right' }}>
rifkaki's avatar
rifkaki committed
600
                                {tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ?
Deni Rinaldi's avatar
Deni Rinaldi committed
601 602 603 604 605 606 607
                                    <span style={{ fontSize: 12, textAlign: 'right' }}>
                                        <NumberFormat
                                            thousandSeparator={true}
                                            style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                            type="text"
                                            placeholder=""
                                            disabled={true}
d.arizona's avatar
d.arizona committed
608
                                            value={this.props.PLBSFAMSubmitted ? Number(tableMeta.rowData[6].value).toFixed(1) : Number(handleValueFormula(tableMeta, 6)).toFixed(1)}
Deni Rinaldi's avatar
Deni Rinaldi committed
609
                                        />
d.arizona's avatar
d.arizona committed
610
                                    </span>
rifkaki's avatar
rifkaki committed
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
                                    :
                                    tableMeta.rowData[0] === 7 ?
                                        // <span style={{ fontSize: 12, textAlign: 'right' }}>
                                        //     <NumberFormat
                                        //         thousandSeparator={true}
                                        //         style={{ color: Number(handleValueFormula(tableMeta, 6)).toFixed(1) > Number(this.state.minValue) || Number(handleValueFormula(tableMeta, 6)).toFixed(1) < Number(this.state.maxValue) ? 'red' : 'black' , fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                        //         type="text"
                                        //         placeholder=""
                                        //         disabled={true}
                                        //         value={Number(handleValueFormula(tableMeta, 6)).toFixed(1)}
                                        //     />
                                        // </span> 
                                        (Number(handleValueFormula(tableMeta, 6)).toFixed(1) > Number(this.state.minValue) && Number(handleValueFormula(tableMeta, 6)).toFixed(1) < Number(this.state.maxValue)) ?
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{
                                                    fontSize: 12,
                                                    textAlign: 'right',
                                                    borderColor: 'transparent',
                                                    margin: 0,
                                                    width: 96,
                                                    backgroundColor: 'transparent',
                                                    color: 'black'
                                                }}
                                                type="text"
                                                placeholder=""
                                                disabled={true}
d.arizona's avatar
d.arizona committed
638
                                                value={this.props.PLBSFAMSubmitted ? Number(tableMeta.rowData[6].value).toFixed(1) : Number(handleValueFormula(tableMeta, 6)).toFixed(1)}
rifkaki's avatar
rifkaki committed
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
                                            /> :
                                            <LightTooltip title={this.state.minValue === null ? null : `Value Should be (${this.state.minValue}) up to (${this.state.maxValue})`} arrow>
                                                <NumberFormat
                                                    thousandSeparator={true}
                                                    style={{
                                                        fontSize: 12,
                                                        textAlign: 'right',
                                                        borderColor: 'transparent',
                                                        margin: 0,
                                                        width: 96,
                                                        backgroundColor: 'transparent',
                                                        color: 'red'
                                                    }}
                                                    type="text"
                                                    placeholder=""
                                                    disabled={true}
d.arizona's avatar
d.arizona committed
655
                                                    value={this.props.PLBSFAMSubmitted ? Number(tableMeta.rowData[6].value).toFixed(1) : Number(handleValueFormula(tableMeta, 6)).toFixed(1)}
rifkaki's avatar
rifkaki committed
656 657 658
                                                />
                                            </LightTooltip>
                                        : null}
Deni Rinaldi's avatar
Deni Rinaldi committed
659 660 661 662
                            </div>
                        )
                    }
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
663 664 665 666 667 668 669
            },
            {
                name: "",
                options: {
                    display: false
                }
            },
Deni Rinaldi's avatar
Deni Rinaldi committed
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
        ]

        const loadingComponent = (
            <div style={{ position: 'fixed', zIndex: 110, top: 0, left: 0, width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', background: 'rgba(255,255,255,0.8)' }}>
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
            </div>
        );

        return (
            <div style={{ height: this.props.height, backgroundColor: '#f8f8f8', marginBottom: 100, minHeight: 1000 }}>
                {this.state.loading && loadingComponent}
                <div className={"main-color"} style={{ height: 78, flex: 1, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
                    <Typography style={{ fontSize: '16px', color: 'white' }}>Monthly Report</Typography>
                </div>
                <div style={{ flex: 1, padding: 20, width: '100%' }}>
                    <Paper style={{ paddingTop: 10 }}>
                        <div style={{ borderBottom: 'solid 1px #c4c4c4' }} >
                            <Typography style={{ fontSize: '12px', color: '#4b4b4b', margin: 10 }}>Monthly Report - Cash Flow</Typography>
                        </div>
                        <div style={{ padding: 20 }}>
                            <div style={{ display: 'flex', justifyContent: 'space-between' }}>
                                <div>
                                    <Typography style={{ fontSize: '11px', color: '#4b4b4b' }}>{this.props.company.company_name}</Typography>
d.arizona's avatar
d.arizona committed
698
                                    <Typography style={{ fontSize: '11px', color: '#4b4b4b' }}>Period : {String(this.props.month.month_value).toLocaleUpperCase()} {this.props.periode} (rev.{this.props.revision})</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
                                    <Typography style={{ fontSize: '11px', color: '#4b4b4b' }}>in IDR mn</Typography>
                                </div>
                                <div style={{ width: '50%' }}>
                                    <div style={{ justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
                                        <a data-tip={'Download'} data-for="download">
                                            <button
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    margin: 5
                                                }}
                                                onClick={() =>
                                                    this.setState({ loading: true }, () => {
                                                        setTimeout(() => {
Riri Novita's avatar
Riri Novita committed
714
                                                            this.downloadAllData()
Deni Rinaldi's avatar
Deni Rinaldi committed
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
                                                        }, 100);
                                                    })}
                                            >
                                                <img src={Images.download} />
                                            </button>
                                        </a>
                                        <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
                                    </div>
                                </div>
                            </div>

                            <div style={{ marginTop: 20, width: this.props.width - (this.props.open === true ? 400 : 150) }}>
                                {!this.state.loading && (
                                    <MuiThemeProvider theme={getMuiTheme()}>
                                        <MUIDataTable
Deni Rinaldi's avatar
Deni Rinaldi committed
730
                                            data={dataTable2}
Deni Rinaldi's avatar
Deni Rinaldi committed
731 732 733 734 735 736 737 738 739
                                            columns={columns}
                                            options={options}
                                        />
                                    </MuiThemeProvider>
                                )}
                            </div>
                            {/* {this.props.isApprover === true || this.state.dataTable.length == 0 ? null :
                                (this.props.lastStatus === 'SUBMIT' || this.props.lastStatus === 'REVISION') && this.props.prevRevision === false && (this.props.status === 'revision' || this.props.status === 'not-yet' || this.props.status === 'draft' || this.props.status === 'submitted') ? */}
                            <div className="grid grid-2x" style={{ marginTop: 20 }}>
Riri Novita's avatar
Riri Novita committed
740
                                <div className="col-1" style={{ paddingLeft: 0 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
                                    <button
                                        type="button"
                                        onClick={() => this.setState({ loading: true }, () => {
                                            setTimeout(() => {
                                                this.props.onClickClose()
                                            }, 100);
                                        })}
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            outline: 'none'
                                        }}
                                    >
                                        <div style={{ backgroundColor: '#019ce5', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                            <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Back</Typography>
                                        </div>
                                    </button>
                                </div>
d.arizona's avatar
d.arizona committed
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
                                {this.state.viewOnly &&
                                    <div className="col-2" style={{ display: 'flex', justifyContent: 'flex-end', maxWidth: '100%' }}>
                                        <button
                                            type="button"
                                            // disabled={this.state.buttonError}
                                            onClick={() =>
                                                // this.state.buttonError ?
                                                //     this.setState({ alert: true, messageAlert: 'Data is not complete !', tipeAlert: 'warning' })
                                                //     :
                                                this.state.handleTekTekTek == 1 ? null :
                                                    this.setState({ handleTekTekTek: 1 }, () => {
                                                        this.payloadCF(dataTable2)
                                                    })}
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: this.state.buttonError === true ? 'default' : 'pointer',
                                                borderColor: 'transparent',
                                                outline: 'none',
                                            }}
                                        >
                                            <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                                <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Save & Complete</Typography>
                                            </div>
                                        </button>
                                    </div>
                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
786 787 788 789 790 791 792 793
                            </div>
                        </div>
                    </Paper>
                </div>
            </div>
        );
    }
}