SubHolding.js 213 KB
Newer Older
faisalhamdi's avatar
faisalhamdi committed
1
import React, { Component } from 'react'
faisalhamdi's avatar
faisalhamdi committed
2
import { Typography, MenuItem, TextField, AppBar, Paper, Tabs, Tab, Snackbar, withStyles } from '@material-ui/core'
Deni Rinaldi's avatar
Deni Rinaldi committed
3 4 5 6 7 8
import Constant from '../../library/Constant'
import api from '../../api'
import { titleCase } from '../../library/Utils'
import { Autocomplete } from '@material-ui/lab'
import TableSubHolding from './TableSubHolding'
import { PropagateLoader } from 'react-spinners'
Deni Rinaldi's avatar
Deni Rinaldi committed
9 10
import ReactTooltip from 'react-tooltip'
import Images from '../../assets/Images'
faisalhamdi's avatar
faisalhamdi committed
11
import MuiAlert from '@material-ui/lab/Alert';
d.arizona's avatar
d.arizona committed
12
import * as R from 'ramda'
d.arizona's avatar
d.arizona committed
13
import { format } from 'date-fns';
faisalhamdi's avatar
faisalhamdi committed
14 15 16

const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
faisalhamdi's avatar
faisalhamdi committed
17 18 19 20 21 22 23 24

export default class SubHolding extends Component {
    constructor(props) {
        super(props)
        this.state = {
            periode: '2020',
            perusahaan: 'TAP Group',
            laporan: 'Balance Sheet - Montly',
Deni Rinaldi's avatar
Deni Rinaldi committed
25 26 27 28 29 30
            tab: 0,
            listCompany: null,
            company: null,
            listPeriode: null,
            periode: null,
            reportType: [
idlanirined's avatar
idlanirined committed
31
                { value: 2, label: 'DB Balance Sheet' },
Deni Rinaldi's avatar
Deni Rinaldi committed
32
                { value: 3, label: 'DB Profit & Loss' },
idlanirined's avatar
idlanirined committed
33
                { value: 1, label: 'DB Profit & Loss Detail' },
Deni Rinaldi's avatar
Deni Rinaldi committed
34
                { value: 4, label: 'DB Ratio' },
35 36
                { value: 5, label: 'DB Tax Planning' },
                { value: 21, label: 'DB Operating Indicator' },
Riri Novita's avatar
Riri Novita committed
37
                { value: 6, label: 'Cash Flow - Summary' },
Riri Novita's avatar
Riri Novita committed
38 39
                { value: 7, label: 'Balance Sheet - Summary' },
                { value: 8, label: 'Profit Loss - Summary' },
Riri Novita's avatar
Riri Novita committed
40
                { value: 9, label: 'Financial Ratio - Summary' },
faisalhamdi's avatar
faisalhamdi committed
41 42
                { value: 10, label: 'CAT Performance Quarterly' },
                { value: 11, label: 'CAT Performance Appraisal' },
Deni Rinaldi's avatar
Deni Rinaldi committed
43 44
            ],
            report: null,
Deni Rinaldi's avatar
Deni Rinaldi committed
45
            loading: false,
d.arizona's avatar
d.arizona committed
46
            previewTable: false,
d.arizona's avatar
d.arizona committed
47 48 49 50 51 52
            OPID: null,
            listMonths: null,
            listUom: null,
            listQuarter: null,
            month: null,
            quarter: null,
Riri Novita's avatar
Riri Novita committed
53 54 55
            uom: null,
            approveMB: false,
            approveMonthly: false
faisalhamdi's avatar
faisalhamdi committed
56 57 58 59 60 61 62
        }
    }

    selectTab = (event, newEvent) => {
        this.setState({ tab: newEvent })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
63 64 65
    componentDidMount() {
        this.getDetailUser()
        this.setState({ report: this.state.reportType[0], loading: true })
Riri Novita's avatar
Riri Novita committed
66
        // this.getApproveMB()
Deni Rinaldi's avatar
Deni Rinaldi committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    }

    getDetailUser() {
        let userId = localStorage.getItem(Constant.USER)
        api.create().getDetailUser(userId).then((response) => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        this.setState({ userCompany: response.data.data.company }, () => {
                            this.getCompanyActive()
                        })
                    }
                }
            }
        })
    }

Riri Novita's avatar
Riri Novita committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    getApproveMB() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
        }
        api.create().getFullApproveMB(payload).then((response) => {
            console.log(response);
            if (response.data) {
                if (response.data.status == "success") {
                    this.setState({ approveMB: response.data.data.is_master_budget_approve})
                }
                
            }
        })
    }

    getApproveMonthly() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
        }
        api.create().getFullApproveMonthly(payload).then((response) => {
Riri Novita's avatar
Riri Novita committed
106
            console.log(payload);
Riri Novita's avatar
Riri Novita committed
107 108 109
            console.log(response);
            if (response.data) {
                if (response.data.status == "success") {
Riri Novita's avatar
Riri Novita committed
110
                    console.log(response.data.data);
Riri Novita's avatar
Riri Novita committed
111
                    let approveMonthly = 
Riri Novita's avatar
Riri Novita committed
112 113
                    this.state.month.month_id == 1?
                        response.data.data.januari.is_approve :
Riri Novita's avatar
Riri Novita committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
                    this.state.month.month_id == 2? 
                        response.data.data.februari.is_approve :
                    this.state.month.month_id == 3? 
                        response.data.data.march.is_approve :
                    this.state.month.month_id == 4? 
                        response.data.data.april.is_approve :
                    this.state.month.month_id == 5? 
                        response.data.data.may.is_approve :
                    this.state.month.month_id == 6? 
                        response.data.data.june.is_approve :
                    this.state.month.month_id == 7? 
                        response.data.data.july.is_approve :
                    this.state.month.month_id == 8? 
                        response.data.data.august.is_approve :
                    this.state.month.month_id == 9? 
                        response.data.data.september.is_approve :
                    this.state.month.month_id == 10? 
                        response.data.data.october.is_approve :
                    this.state.month.month_id == 11? 
                        response.data.data.november.is_approve :
Riri Novita's avatar
Riri Novita committed
134
                        response.data.data.december.is_approve 
Riri Novita's avatar
Riri Novita committed
135 136

                    this.setState({ approveMonthly })
Riri Novita's avatar
Riri Novita committed
137
                    }
Riri Novita's avatar
Riri Novita committed
138 139 140 141 142
                
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
143 144
    getCompanyActive() {
        api.create().getPerusahaanActive().then((response) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
145
            // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
            if (response.data) {
                if (response.data.status === 'success') {
                    let data = response.data.data
                    let comID = this.state.rawData ? this.state.rawData.company_id : 0
                    let companyData = data.map((item) => {
                        return {
                            company_id: item.company_id,
                            company_name: item.company_name,
                        }
                    })

                    let arrayBaru = []
                    this.state.userCompany.map((item, index) => {
                        let indexID = companyData.findIndex((val) => val.company_id == item)
                        if (indexID !== -1) {
                            arrayBaru.push(companyData[indexID])
                        }
                    })

d.arizona's avatar
d.arizona committed
165 166 167 168
                    if (arrayBaru.length > 0) {
                        arrayBaru = arrayBaru.sort((a,b) => a.company_name.localeCompare(b.company_name))
                    }

Deni Rinaldi's avatar
Deni Rinaldi committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
                    let defaultProps = {
                        options: arrayBaru,
                        getOptionLabel: (option) => titleCase(option.company_name),
                    };
                    let index = arrayBaru.findIndex((val) => val.company_id == comID)
                    this.setState({ listCompany: defaultProps, company: arrayBaru.length < 1 ? companyData[0] : (index == -1 ? arrayBaru[0] : arrayBaru[index]) }, () => {
                        this.getLastPeriod()
                    })
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                        if (response.data.message.includes("Someone Logged In")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listCompany: null, company: null })
            }
        })
    }

    getLastPeriod() {
        api.create().getLastPeriod(this.state.company.company_id).then(response => {
Riri Novita's avatar
Riri Novita committed
195
            console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
            if (response.data.status === "success") {
                this.setState({ lastPeriod: response.data.data.last_periode, latestPeriode: response.data.data.latest_periode }, () => {
                    this.getPeriode()
                })
            }
        })
    }

    getPeriode() {
        api.create().getPeriodeTransaction().then(response => {
            let currentYear = new Date().getFullYear()
            // console.log(currentYear)
            if (response.data) {
                if (response.data.status === "success") {
                    let data = []
d.arizona's avatar
d.arizona committed
211
                    let listMonths = []
Deni Rinaldi's avatar
Deni Rinaldi committed
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
                    response.data.data.map((item) => {
                        if (this.state.isApprover) {
                            if (item >= 2000 && item <= (Number(currentYear) + 1)) {
                                data.push(item)
                            }
                        } else {
                            if ((item >= 2000) && (item == this.state.lastPeriod || item < this.state.lastPeriod)) {
                                data.push(item)
                            }
                        }
                    })
                    let periodeData = data.map((item) => {
                        return {
                            periode: item,
                        }
                    })
                    let defaultProps = {
                        options: periodeData,
                        getOptionLabel: (option) => option.periode,
                    };
Riri Novita's avatar
Riri Novita committed
232 233
                    console.log(this.state.lastPeriod)
                    let periode = (this.state.lastPeriod == "" ? String(Number(currentYear)) : this.state.latestPeriode)
d.arizona's avatar
d.arizona committed
234 235 236 237 238
                    let dateNow = new Date()
                    dateNow.setMonth(dateNow.getMonth() - 1);
                    let yearNow = dateNow.getFullYear()
                    console.log(yearNow)
                    console.log(periode)
d.arizona's avatar
d.arizona committed
239
                    let index = data.sort((a, b) => a - b).findIndex((val) => val == (String(this.state.report.label).toLocaleLowerCase().includes('summary') ? yearNow : periode))
d.arizona's avatar
d.arizona committed
240

Deni Rinaldi's avatar
Deni Rinaldi committed
241 242 243
                    // console.log(data)
                    // console.log(this.state.latestPeriode)
                    // console.log(periodeData)
d.arizona's avatar
d.arizona committed
244
                    console.log(index)
Deni Rinaldi's avatar
Deni Rinaldi committed
245
                    this.setState({ listPeriode: defaultProps, periode: index === -1 ? periodeData[0] : periodeData[index] }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
246
                        // this.getDataTable()
247
                        // this.getSubmission()
d.arizona's avatar
d.arizona committed
248
                        this.getMonth()
Deni Rinaldi's avatar
Deni Rinaldi committed
249 250 251 252 253 254 255 256 257 258 259
                        // if (this.state.isApprover === true) {
                        //     this.getCompanySubmitted()
                        // } else {
                        //     this.getRevision()
                        // }
                    })
                }
            }
        })
    }

d.arizona's avatar
d.arizona committed
260 261
    getMonth() {
        api.create().getMonthTransaction().then(response => {
d.arizona's avatar
d.arizona committed
262 263 264
            let dateNow = new Date()
            dateNow.setMonth(dateNow.getMonth() - 1);
            let month = format(dateNow, 'MMMM') 
d.arizona's avatar
d.arizona committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
            console.log(response);
            if (response.data) {
                if (response.data.status === "success") {
                    // console.log(response);
                    let data = response.data.data
                    let monthData = data.map((item) => {
                        return {
                            month_id: item.id,
                            month_value: String(item.month_name).substr(0, 3)
                        }
                    })
                    let defaultProps = {
                        options: monthData,
                        getOptionLabel: (option) => option.month_value,
                    };
                    let index = data.findIndex((val) => val.month_name == month)

                    let listQuarter = [
d.arizona's avatar
d.arizona committed
283 284 285 286
                        { name: 'Q1', value: '3' },
                        { name: 'Q2', value: '6' },
                        { name: 'Q3', value: '9' },
                        { name: 'Q4', value: '12' },
d.arizona's avatar
d.arizona committed
287 288
                    ]

d.arizona's avatar
d.arizona committed
289
                    let listUom = [{ value: 'Mio IDR' }]
d.arizona's avatar
d.arizona committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312

                    let defaultPropsQuarter = {
                        options: listQuarter,
                        getOptionLabel: (option) => option.name,
                    };

                    let defaultPropsUom = {
                        options: listUom,
                        getOptionLabel: (option) => option.value,
                    };
                    // console.log(month)
                    // console.log(index)
                    this.setState({ listMonths: defaultProps, month: index == -1 ? monthData[0] : monthData[index], listQuarter: defaultPropsQuarter, quarter: listQuarter[0], listUom: defaultPropsUom, uom: listUom[0] }, () => {
                        // if (this.state.isApprover === true) {
                        //     if (this.state.submittedOnly) {
                        //         console.log('masuk cuk')
                        //         this.getPeriode()
                        //     } else {
                        //         this.getLastPeriod()
                        //     }
                        // this.getPeriode()
                        this.getReportType()
                        // } else {
d.arizona's avatar
d.arizona committed
313 314
                        // this.getLastPeriod()
                        // this.getPeriode()
d.arizona's avatar
d.arizona committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
                        // }
                    })
                } else {
                    // this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                    //     if (response.data.message.includes("Someone Logged In")) {
                    //         setTimeout(() => {
                    //             localStorage.removeItem(Constant.TOKEN)
                    //             window.location.reload();
                    //         }, 1000);
                    //     }
                    // })
                }
            } else {
                // this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
            }
        })
    }

333 334 335 336 337 338
    getReportType() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
            "report_type": "Master Budget",
        }
Riri Novita's avatar
Riri Novita committed
339 340
        this.getApproveMB()
        this.getApproveMonthly()
341 342 343 344 345 346 347
        api.create().getReportTypeBody(payload).then(response => {
            console.log(response);
            if (response.data) {
                if (response.data.status === "success") {
                    if (this.state.report.value === 2) {
                        response.data.data.map((item, index) => {
                            if (item.report_name === 'Balance Sheet') {
d.arizona's avatar
d.arizona committed
348
                                this.setState({ revisionType: item.revision }, () => {
349 350 351 352 353 354 355
                                    this.getSubmission()
                                })
                            }
                        })
                    } else if (this.state.report.value === 1) {
                        response.data.data.map((item, index) => {
                            if (item.report_name === 'Profit Loss') {
d.arizona's avatar
d.arizona committed
356
                                this.setState({ revisionType: item.revision }, () => {
357 358 359 360
                                    this.getSubmission()
                                })
                            }
                        })
361 362 363
                    } else if (this.state.report.value === 5) {
                        response.data.data.map((item, index) => {
                            if (item.report_name === 'Tax Planning') {
d.arizona's avatar
d.arizona committed
364
                                this.setState({ revisionType: item.revision }, () => {
365 366 367 368
                                    this.getSubmission()
                                })
                            }
                        })
369
                    } else {
d.arizona's avatar
d.arizona committed
370
                        this.setState({ revisionType: 0 }, () => {
371 372 373
                            this.getSubmission()
                        })
                    }
faisalhamdi's avatar
faisalhamdi committed
374 375 376 377 378 379 380 381 382
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                        if (response.data.message.includes("Someone Logged In")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
383
                }
faisalhamdi's avatar
faisalhamdi committed
384
            } else {
d.arizona's avatar
d.arizona committed
385
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
386 387 388 389
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
390 391
    getSubmission() {
        this.setState({ loading: true })
Deni Rinaldi's avatar
Deni Rinaldi committed
392 393
        let payload = {
            "company_id": this.state.company.company_id,
Deni Rinaldi's avatar
Deni Rinaldi committed
394 395
            "periode": this.state.periode.periode,
            "is_approver": true
Deni Rinaldi's avatar
Deni Rinaldi committed
396
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
397
        api.create().getSubmission(payload).then(response => {
398
            console.log(response)
Deni Rinaldi's avatar
Deni Rinaldi committed
399 400 401 402 403 404 405 406 407 408
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({
                        submissionID: response.data.data.submission_id,
                        lastRevision: response.data.data.last_revision,
                    }, () => {
                        this.getDataTable()
                    })
                } else {
                    this.setState({ submissionID: null, loading: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
409
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
410 411 412 413 414 415 416
            }
        })
    }

    getDataTable() {
        let payload = {
            "report_id": this.state.report.value,
417
            "revision": this.state.revisionType,
Deni Rinaldi's avatar
Deni Rinaldi committed
418 419 420 421
            "periode": this.state.periode.periode,
            "company_id": this.state.company.company_id,
            "submission_id": this.state.submissionID
        }
idlanirined's avatar
idlanirined committed
422
        if (this.state.report.value === 1) {
423
            api.create().getAllReportPLDetail(payload).then(response => {
Riri Novita's avatar
Riri Novita committed
424
                console.log(response);
idlanirined's avatar
idlanirined committed
425 426
                let dataTable = []
                if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
                    if (response.data.status === 'success') {
                        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,
                                    item.profit_loss.total_actual_before === null ? "0" : item.profit_loss.total_actual_before === "" ? "0" : item.profit_loss.total_actual_before,
                                    item.profit_loss.january,
                                    item.profit_loss.february,
                                    item.profit_loss.march,
                                    item.profit_loss.april,
                                    item.profit_loss.may,
                                    item.profit_loss.june,
                                    item.profit_loss.july,
                                    item.profit_loss.august,
                                    item.profit_loss.september,
                                    item.profit_loss.october,
                                    item.profit_loss.november,
                                    item.profit_loss.december,
                                    item.profit_loss.total_current_year,
                                    item.profit_loss.total_next_year,
                                    item.profit_loss.total_more_year,
                                    item.order,
                                    item.profit_loss.monthly_january,
                                    item.profit_loss.monthly_february,
                                    item.profit_loss.monthly_march,
                                    item.profit_loss.monthly_april,
                                    item.profit_loss.monthly_may,
                                    item.profit_loss.monthly_june,
                                    item.profit_loss.monthly_july,
                                    item.profit_loss.monthly_august,
                                    item.profit_loss.monthly_september,
                                    item.profit_loss.monthly_october,
                                    item.profit_loss.monthly_november,
                                    item.profit_loss.monthly_december,
                                    item.profit_loss.monthly_last_year_january,
                                    item.profit_loss.monthly_last_year_february,
                                    item.profit_loss.monthly_last_year_march,
                                    item.profit_loss.monthly_last_year_april,
                                    item.profit_loss.monthly_last_year_may,
                                    item.profit_loss.monthly_last_year_june,
                                    item.profit_loss.monthly_last_year_july,
                                    item.profit_loss.monthly_last_year_august,
                                    item.profit_loss.monthly_last_year_september,
                                    item.profit_loss.monthly_last_year_october,
                                    item.profit_loss.monthly_last_year_november,
                                    item.profit_loss.monthly_last_year_december,
                                    item.profit_loss.notes
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
                        res.map((item, index) => {
idlanirined's avatar
idlanirined committed
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
                            dataTable.push([
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
                                item.profit_loss.total_actual_before === null ? "0" : item.profit_loss.total_actual_before === "" ? "0" : item.profit_loss.total_actual_before,
                                item.profit_loss.january,
                                item.profit_loss.february,
                                item.profit_loss.march,
                                item.profit_loss.april,
                                item.profit_loss.may,
                                item.profit_loss.june,
                                item.profit_loss.july,
                                item.profit_loss.august,
                                item.profit_loss.september,
                                item.profit_loss.october,
                                item.profit_loss.november,
                                item.profit_loss.december,
                                item.profit_loss.total_current_year,
                                item.profit_loss.total_next_year,
                                item.profit_loss.total_more_year,
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
                                item.order,
                                item.profit_loss.monthly_january,
                                item.profit_loss.monthly_february,
                                item.profit_loss.monthly_march,
                                item.profit_loss.monthly_april,
                                item.profit_loss.monthly_may,
                                item.profit_loss.monthly_june,
                                item.profit_loss.monthly_july,
                                item.profit_loss.monthly_august,
                                item.profit_loss.monthly_september,
                                item.profit_loss.monthly_october,
                                item.profit_loss.monthly_november,
                                item.profit_loss.monthly_december,
                                item.profit_loss.monthly_last_year_january,
                                item.profit_loss.monthly_last_year_february,
                                item.profit_loss.monthly_last_year_march,
                                item.profit_loss.monthly_last_year_april,
                                item.profit_loss.monthly_last_year_may,
                                item.profit_loss.monthly_last_year_june,
                                item.profit_loss.monthly_last_year_july,
                                item.profit_loss.monthly_last_year_august,
                                item.profit_loss.monthly_last_year_september,
                                item.profit_loss.monthly_last_year_october,
                                item.profit_loss.monthly_last_year_november,
539 540
                                item.profit_loss.monthly_last_year_december,
                                item.profit_loss.notes
idlanirined's avatar
idlanirined committed
541
                            ])
faisalhamdi's avatar
faisalhamdi committed
542 543 544 545 546 547
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
idlanirined's avatar
idlanirined committed
548
                            }
faisalhamdi's avatar
faisalhamdi committed
549 550 551 552
                        })
                        // console.log(dataTable)
                        // this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
553

faisalhamdi's avatar
faisalhamdi committed
554 555 556 557 558 559 560 561 562 563 564 565 566 567
                        // this.setState({ dataTable }, () => {
                        //     console.log(this.state.dataTable)
                        //     this.getPLDetailMR(payload)
                        // })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                            if (response.data.message.includes("Someone Logged In")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
idlanirined's avatar
idlanirined committed
568 569 570 571 572
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
            })
        } else if (this.state.report.value === 2) {
573
            api.create().getAllReportBS(payload).then(response => {
faisalhamdi's avatar
faisalhamdi committed
574 575
                console.log(payload);
                console.log(response);
idlanirined's avatar
idlanirined committed
576
                let dataTable = []
Deni Rinaldi's avatar
Deni Rinaldi committed
577
                if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
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 605 606 607 608 609 610 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 638 639 640 641 642 643
                    if (response.data.status === 'success') {
                        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,
                                    item.balance_sheet.total_actual_before === null ? "0.0" : item.balance_sheet.total_actual_before === "" ? "0.0" : item.balance_sheet.total_actual_before,
                                    Number(item.balance_sheet.january).toFixed(1),
                                    Number(item.balance_sheet.february).toFixed(1),
                                    Number(item.balance_sheet.march).toFixed(1),
                                    Number(item.balance_sheet.april).toFixed(1),
                                    Number(item.balance_sheet.may).toFixed(1),
                                    Number(item.balance_sheet.june).toFixed(1),
                                    Number(item.balance_sheet.july).toFixed(1),
                                    Number(item.balance_sheet.august).toFixed(1),
                                    Number(item.balance_sheet.september).toFixed(1),
                                    Number(item.balance_sheet.october).toFixed(1),
                                    Number(item.balance_sheet.november).toFixed(1),
                                    Number(item.balance_sheet.december).toFixed(1),
                                    Number(item.balance_sheet.total_current_year).toFixed(1),
                                    Number(item.balance_sheet.total_next_year).toFixed(1),
                                    Number(item.balance_sheet.total_more_year).toFixed(1),
                                    item.order,
                                    item.condition_it_should_be,
                                    item.condition_if_wrong,
                                    item.balance_sheet.monthly_january,
                                    item.balance_sheet.monthly_february,
                                    item.balance_sheet.monthly_march,
                                    item.balance_sheet.monthly_april,
                                    item.balance_sheet.monthly_may,
                                    item.balance_sheet.monthly_june,
                                    item.balance_sheet.monthly_july,
                                    item.balance_sheet.monthly_august,
                                    item.balance_sheet.monthly_september,
                                    item.balance_sheet.monthly_october,
                                    item.balance_sheet.monthly_november,
                                    item.balance_sheet.monthly_december,
                                    item.balance_sheet.monthly_last_year_january,
                                    item.balance_sheet.monthly_last_year_february,
                                    item.balance_sheet.monthly_last_year_march,
                                    item.balance_sheet.monthly_last_year_april,
                                    item.balance_sheet.monthly_last_year_may,
                                    item.balance_sheet.monthly_last_year_june,
                                    item.balance_sheet.monthly_last_year_july,
                                    item.balance_sheet.monthly_last_year_august,
                                    item.balance_sheet.monthly_last_year_september,
                                    item.balance_sheet.monthly_last_year_october,
                                    item.balance_sheet.monthly_last_year_november,
                                    item.balance_sheet.monthly_last_year_december
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
                        res.map((item, index) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
644 645 646 647 648 649 650 651
                            dataTable.push([
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
                                item.balance_sheet.total_actual_before === null ? "0.0" : item.balance_sheet.total_actual_before === "" ? "0.0" : item.balance_sheet.total_actual_before,
Deni Rinaldi's avatar
Deni Rinaldi committed
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
                                Number(item.balance_sheet.january).toFixed(1),
                                Number(item.balance_sheet.february).toFixed(1),
                                Number(item.balance_sheet.march).toFixed(1),
                                Number(item.balance_sheet.april).toFixed(1),
                                Number(item.balance_sheet.may).toFixed(1),
                                Number(item.balance_sheet.june).toFixed(1),
                                Number(item.balance_sheet.july).toFixed(1),
                                Number(item.balance_sheet.august).toFixed(1),
                                Number(item.balance_sheet.september).toFixed(1),
                                Number(item.balance_sheet.october).toFixed(1),
                                Number(item.balance_sheet.november).toFixed(1),
                                Number(item.balance_sheet.december).toFixed(1),
                                Number(item.balance_sheet.total_current_year).toFixed(1),
                                Number(item.balance_sheet.total_next_year).toFixed(1),
                                Number(item.balance_sheet.total_more_year).toFixed(1),
Deni Rinaldi's avatar
Deni Rinaldi committed
667 668
                                item.order,
                                item.condition_it_should_be,
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
                                item.condition_if_wrong,
                                item.balance_sheet.monthly_january,
                                item.balance_sheet.monthly_february,
                                item.balance_sheet.monthly_march,
                                item.balance_sheet.monthly_april,
                                item.balance_sheet.monthly_may,
                                item.balance_sheet.monthly_june,
                                item.balance_sheet.monthly_july,
                                item.balance_sheet.monthly_august,
                                item.balance_sheet.monthly_september,
                                item.balance_sheet.monthly_october,
                                item.balance_sheet.monthly_november,
                                item.balance_sheet.monthly_december,
                                item.balance_sheet.monthly_last_year_january,
                                item.balance_sheet.monthly_last_year_february,
                                item.balance_sheet.monthly_last_year_march,
                                item.balance_sheet.monthly_last_year_april,
                                item.balance_sheet.monthly_last_year_may,
                                item.balance_sheet.monthly_last_year_june,
                                item.balance_sheet.monthly_last_year_july,
                                item.balance_sheet.monthly_last_year_august,
                                item.balance_sheet.monthly_last_year_september,
                                item.balance_sheet.monthly_last_year_october,
                                item.balance_sheet.monthly_last_year_november,
                                item.balance_sheet.monthly_last_year_december
Deni Rinaldi's avatar
Deni Rinaldi committed
694
                            ])
faisalhamdi's avatar
faisalhamdi committed
695 696 697 698 699 700
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
701
                            }
faisalhamdi's avatar
faisalhamdi committed
702 703 704 705 706 707 708 709 710 711 712 713 714
                        })
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                        // this.setState({ dataTable }, () => {
                            // console.log(this.state.dataTable)
                        //     this.getBalanceSheetMR(payload)
                        // })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                            if (response.data.message.includes("Someone Logged In")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
Deni Rinaldi's avatar
Deni Rinaldi committed
715
                            }
faisalhamdi's avatar
faisalhamdi committed
716 717
                        })
                    }    
Deni Rinaldi's avatar
Deni Rinaldi committed
718
                } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
719
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
720
                }
idlanirined's avatar
idlanirined committed
721 722
            })
        } else if (this.state.report.value === 3) {
Riri Novita's avatar
Riri Novita committed
723 724 725 726 727
            let PLID = null
            let payloadID = {
                "periode": this.state.periode.periode,
                "company_id": this.state.company.company_id
            }
Riri Novita's avatar
Riri Novita committed
728
            // console.log(payloadID);
Riri Novita's avatar
Riri Novita committed
729
            api.create().getPLID(payloadID).then(response => {
Riri Novita's avatar
Riri Novita committed
730
                console.log(response);
Riri Novita's avatar
Riri Novita committed
731 732
                if (response) {
                    PLID = response.data.data == null ? null : response.data.data.profit_loss_id 
Riri Novita's avatar
Riri Novita committed
733
                    // PLID = response.data.data.profit_loss_id 
Riri Novita's avatar
Riri Novita committed
734 735 736 737
                } else {
                    PLID = null
                }
                this.setState({ PLID }, () => {
Riri Novita's avatar
Riri Novita committed
738
                    let payloads = {...payload, report_id: 28, submission_id: this.state.PLID, months: this.state.month.month_id, quarter: 0}
Riri Novita's avatar
Riri Novita committed
739 740 741 742
                    console.log(payloads);
                    api.create().getReportPL(payloads).then(response => {
                        console.log(response);
                        if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 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 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801
                            if (response.data.status === 'success') {
                                let dataTable = []
                                console.log(response)
                                let res = response.data.data
                                const handlePushChild = (item) => {
                                    dataTable.push([
                                        item.type_report_id,
                                        item.id,
                                        item.parent,
                                        item.formula,
                                        item.level,
                                        item.description,
                                        item.profit_loss.total_actual_before === null ? "0" : item.profit_loss.total_actual_before === "" ? "0" : item.profit_loss.total_actual_before,
                                        item.profit_loss.january,
                                        item.profit_loss.february,
                                        item.profit_loss.march,
                                        item.profit_loss.april,
                                        item.profit_loss.may,
                                        item.profit_loss.june,
                                        item.profit_loss.july,
                                        item.profit_loss.august,
                                        item.profit_loss.september,
                                        item.profit_loss.october,
                                        item.profit_loss.november,
                                        item.profit_loss.december,
                                        item.profit_loss.total_current_year,
                                        item.profit_loss.total_next_year,
                                        item.profit_loss.total_more_year,
                                        item.order,
                                        item.condition_it_should_be,
                                        item.condition_if_wrong,
                                        [],
                                        "",
                                        item.profit_loss.monthly_january,
                                        item.profit_loss.monthly_february,
                                        item.profit_loss.monthly_march,
                                        item.profit_loss.monthly_april,
                                        item.profit_loss.monthly_may,
                                        item.profit_loss.monthly_june,
                                        item.profit_loss.monthly_july,
                                        item.profit_loss.monthly_august,
                                        item.profit_loss.monthly_september,
                                        item.profit_loss.monthly_october,
                                        item.profit_loss.monthly_november,
                                        item.profit_loss.monthly_december,
                                        item.profit_loss.monthly_last_year_january,
                                        item.profit_loss.monthly_last_year_february,
                                        item.profit_loss.monthly_last_year_march,
                                        item.profit_loss.monthly_last_year_april,
                                        item.profit_loss.monthly_last_year_may,
                                        item.profit_loss.monthly_last_year_june,
                                        item.profit_loss.monthly_last_year_july,
                                        item.profit_loss.monthly_last_year_august,
                                        item.profit_loss.monthly_last_year_september,
                                        item.profit_loss.monthly_last_year_october,
                                        item.profit_loss.monthly_last_year_november,
                                        item.profit_loss.monthly_last_year_december,
                                        item.profit_loss.notes
                                    ])
idlanirined's avatar
idlanirined committed
802

faisalhamdi's avatar
faisalhamdi committed
803 804 805 806 807 808
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
Riri Novita's avatar
Riri Novita committed
809 810
                                    }
                                }
faisalhamdi's avatar
faisalhamdi committed
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871
                                res.map((item, index) => {
                                    dataTable.push([
                                        item.type_report_id,
                                        item.id,
                                        item.parent,
                                        item.formula,
                                        item.level,
                                        item.description,
                                        item.profit_loss.total_actual_before === null ? "0" : item.profit_loss.total_actual_before === "" ? "0" : item.profit_loss.total_actual_before,
                                        item.profit_loss.january,
                                        item.profit_loss.february,
                                        item.profit_loss.march,
                                        item.profit_loss.april,
                                        item.profit_loss.may,
                                        item.profit_loss.june,
                                        item.profit_loss.july,
                                        item.profit_loss.august,
                                        item.profit_loss.september,
                                        item.profit_loss.october,
                                        item.profit_loss.november,
                                        item.profit_loss.december,
                                        item.profit_loss.total_current_year,
                                        item.profit_loss.total_next_year,
                                        item.profit_loss.total_more_year,
                                        item.order,
                                        item.condition_it_should_be,
                                        item.condition_if_wrong,
                                        [],
                                        "",
                                        item.profit_loss.monthly_january,
                                        item.profit_loss.monthly_february,
                                        item.profit_loss.monthly_march,
                                        item.profit_loss.monthly_april,
                                        item.profit_loss.monthly_may,
                                        item.profit_loss.monthly_june,
                                        item.profit_loss.monthly_july,
                                        item.profit_loss.monthly_august,
                                        item.profit_loss.monthly_september,
                                        item.profit_loss.monthly_october,
                                        item.profit_loss.monthly_november,
                                        item.profit_loss.monthly_december,
                                        item.profit_loss.monthly_last_year_january,
                                        item.profit_loss.monthly_last_year_february,
                                        item.profit_loss.monthly_last_year_march,
                                        item.profit_loss.monthly_last_year_april,
                                        item.profit_loss.monthly_last_year_may,
                                        item.profit_loss.monthly_last_year_june,
                                        item.profit_loss.monthly_last_year_july,
                                        item.profit_loss.monthly_last_year_august,
                                        item.profit_loss.monthly_last_year_september,
                                        item.profit_loss.monthly_last_year_october,
                                        item.profit_loss.monthly_last_year_november,
                                        item.profit_loss.monthly_last_year_december,
                                        item.profit_loss.notes
                                    ])
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
Riri Novita's avatar
Riri Novita committed
872
                                    }
faisalhamdi's avatar
faisalhamdi committed
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
                                })
                                this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                                // this.setState({ dataTable , loading: false}, () => {
                                    console.log(this.state.dataTable)
                                    // this.getReportPLMR(payload)
                                // })
                            } else {
                                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                                    if (response.data.message.includes("Someone Logged In")) {
                                        setTimeout(() => {
                                            localStorage.removeItem(Constant.TOKEN)
                                            window.location.reload();
                                        }, 1000);
                                    }
                                })
                            }
Riri Novita's avatar
Riri Novita committed
889 890
                        } else {
                            this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
891 892
                        }
                    })
Riri Novita's avatar
Riri Novita committed
893
                })
idlanirined's avatar
idlanirined committed
894
            })
faisalhamdi's avatar
faisalhamdi committed
895
        } else if (this.state.report.value === 4) {
Riri Novita's avatar
Riri Novita committed
896 897 898 899 900 901
            let FRID = null
            let payloadFRID = {
                "periode": this.state.periode.periode,
                "company_id": this.state.company.company_id
            }
            api.create().getFRID(payloadFRID).then(response => {
Riri Novita's avatar
Riri Novita committed
902
                console.log(response);
Riri Novita's avatar
Riri Novita committed
903 904 905 906 907 908
                if (response) {
                    FRID = response.data.data == null ? null : response.data.data.ratio_id 
                } else {
                    FRID = null
                }
                this.setState({ FRID }, () => {
d.arizona's avatar
d.arizona committed
909
                    let payloads = {...payload, report_id: 29, submission_id: this.state.FRID, months: this.state.month.month_id, quarter: 0}
Riri Novita's avatar
Riri Novita committed
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928
                    api.create().getReportFR(payloads).then(response => {
                        console.log(payload);
                        console.log(response);
                        let dataTable = []
                        if (response.data) {
                            if (response.data.status === 'success') {
                                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,
                                            item.uom,
                                            item.ratio.total_actual_before === null ? "0.0" : item.ratio.total_actual_before === "" ? "0.0" : item.ratio.total_actual_before,
rifkaki's avatar
rifkaki committed
929 930 931 932 933 934 935 936 937 938 939 940 941 942
                                            item.ratio.january,
                                            item.ratio.february,
                                            item.ratio.march,
                                            item.ratio.april,
                                            item.ratio.may,
                                            item.ratio.june,
                                            item.ratio.july,
                                            item.ratio.august,
                                            item.ratio.september,
                                            item.ratio.october,
                                            item.ratio.november,
                                            item.ratio.december,
                                            item.ratio.total_next_year,
                                            item.ratio.total_more_year,
Riri Novita's avatar
Riri Novita committed
943 944 945 946 947 948 949 950 951 952 953 954
                                            item.ratio.monthly_january,
                                            item.ratio.monthly_february,
                                            item.ratio.monthly_march,
                                            item.ratio.monthly_april,
                                            item.ratio.monthly_may,
                                            item.ratio.monthly_june,
                                            item.ratio.monthly_july,
                                            item.ratio.monthly_august,
                                            item.ratio.monthly_september,
                                            item.ratio.monthly_october,
                                            item.ratio.monthly_november,
                                            item.ratio.monthly_december,
Riri Novita's avatar
Riri Novita committed
955 956 957 958 959 960 961 962 963 964 965 966
                                            item.ratio.monthly_last_year_january,
                                            item.ratio.monthly_last_year_february,
                                            item.ratio.monthly_last_year_march,
                                            item.ratio.monthly_last_year_april,
                                            item.ratio.monthly_last_year_may,
                                            item.ratio.monthly_last_year_june,
                                            item.ratio.monthly_last_year_july,
                                            item.ratio.monthly_last_year_august,
                                            item.ratio.monthly_last_year_september,
                                            item.ratio.monthly_last_year_october,
                                            item.ratio.monthly_last_year_november,
                                            item.ratio.monthly_last_year_december,
Riri Novita's avatar
Riri Novita committed
967
                                        ])
faisalhamdi's avatar
faisalhamdi committed
968
                                }
Riri Novita's avatar
Riri Novita committed
969 970 971 972 973 974 975
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
                                    }
faisalhamdi's avatar
faisalhamdi committed
976
                                }
Riri Novita's avatar
Riri Novita committed
977 978 979 980 981 982 983 984 985 986
                                res.map((item, index) => {
                                    dataTable.push([
                                        item.type_report_id,
                                        item.id,
                                        item.parent,
                                        item.formula,
                                        item.level,
                                        item.description,
                                        item.oum,
                                        item.ratio.total_actual_before === null ? "0.0" : item.ratio.total_actual_before === "" ? "0.0" : item.ratio.total_actual_before,
rifkaki's avatar
rifkaki committed
987 988 989 990 991 992 993 994 995 996 997 998 999 1000
                                        item.ratio.january,
                                        item.ratio.february,
                                        item.ratio.march,
                                        item.ratio.april,
                                        item.ratio.may,
                                        item.ratio.june,
                                        item.ratio.july,
                                        item.ratio.august,
                                        item.ratio.september,
                                        item.ratio.october,
                                        item.ratio.november,
                                        item.ratio.december,
                                        item.ratio.total_next_year,
                                        item.ratio.total_more_year,
Riri Novita's avatar
Riri Novita committed
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
                                        item.ratio.monthly_january,
                                        item.ratio.monthly_february,
                                        item.ratio.monthly_march,
                                        item.ratio.monthly_april,
                                        item.ratio.monthly_may,
                                        item.ratio.monthly_june,
                                        item.ratio.monthly_july,
                                        item.ratio.monthly_august,
                                        item.ratio.monthly_september,
                                        item.ratio.monthly_october,
                                        item.ratio.monthly_november,
                                        item.ratio.monthly_december,
Riri Novita's avatar
Riri Novita committed
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
                                        item.ratio.monthly_last_year_january,
                                        item.ratio.monthly_last_year_february,
                                        item.ratio.monthly_last_year_march,
                                        item.ratio.monthly_last_year_april,
                                        item.ratio.monthly_last_year_may,
                                        item.ratio.monthly_last_year_june,
                                        item.ratio.monthly_last_year_july,
                                        item.ratio.monthly_last_year_august,
                                        item.ratio.monthly_last_year_september,
                                        item.ratio.monthly_last_year_october,
                                        item.ratio.monthly_last_year_november,
                                        item.ratio.monthly_last_year_december,
Riri Novita's avatar
Riri Novita committed
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
                                    ])
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
                                    }
                                })
                                this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                                console.log(this.state.dataTable)
                                // this.setState({ dataTable }, () => {
                                //     console.log(this.state.dataTable)
                                //     this.getRatioMR(payload)
                                // })
                            } else {
                                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                                    if (response.data.message.includes("Someone Logged In")) {
                                        setTimeout(() => {
                                            localStorage.removeItem(Constant.TOKEN)
                                            window.location.reload();
                                        }, 1000);
                                    }
                                })
faisalhamdi's avatar
faisalhamdi committed
1049
                            }
Riri Novita's avatar
Riri Novita committed
1050 1051 1052 1053 1054
                        } else {
                            this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                        }
                    })
                })
faisalhamdi's avatar
faisalhamdi committed
1055
            })
d.arizona's avatar
d.arizona committed
1056
        } else if (this.state.report.value === 5) {
rifkaki's avatar
rifkaki committed
1057
            api.create().getReportTP(payload).then(response => {
rifkaki's avatar
rifkaki committed
1058
                console.log(payload);
d.arizona's avatar
d.arizona committed
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
                console.log(response);
                let dataTable = []
                if (response.data) {
                    if (response.data.status === 'success') {
                        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,
rifkaki's avatar
rifkaki committed
1069 1070 1071 1072 1073 1074
                                    // item.type_report_tax.value_tbc.type_report_id,
                                    // item.type_report_tax.value_fc.type_report_id,
                                    // item.type_report_tax.value_tbf.type_report_id,
                                    0,
                                    0,
                                    0,
d.arizona's avatar
d.arizona committed
1075 1076 1077 1078 1079
                                    item.id,
                                    item.parent,
                                    { tbc: item.formula_tax.value_tbc, fcp: item.formula_tax.value_fc, tbf: item.formula_tax.value_tbf },
                                    item.level,
                                    item.description,
rifkaki's avatar
rifkaki committed
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
                                    item.tax_planning_report.january,
                                    item.tax_planning_report.february,
                                    item.tax_planning_report.march,
                                    item.tax_planning_report.april,
                                    item.tax_planning_report.may,
                                    item.tax_planning_report.june,
                                    item.tax_planning_report.july,
                                    item.tax_planning_report.august,
                                    item.tax_planning_report.september,
                                    item.tax_planning_report.october,
                                    item.tax_planning_report.november,
                                    item.tax_planning_report.december,
d.arizona's avatar
d.arizona committed
1092
                                    item.order,
rifkaki's avatar
rifkaki committed
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
                                    item.tax_planning_report.monthly_january,
                                    item.tax_planning_report.monthly_february,
                                    item.tax_planning_report.monthly_march,
                                    item.tax_planning_report.monthly_april,
                                    item.tax_planning_report.monthly_may,
                                    item.tax_planning_report.monthly_june,
                                    item.tax_planning_report.monthly_july,
                                    item.tax_planning_report.monthly_august,
                                    item.tax_planning_report.monthly_september,
                                    item.tax_planning_report.monthly_october,
                                    item.tax_planning_report.monthly_november,
                                    item.tax_planning_report.monthly_december,
rifkaki's avatar
rifkaki committed
1105
                                    item.tax_planning_report.monthly_full_year,
d.arizona's avatar
d.arizona committed
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
                                ])
                            }
                            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,
rifkaki's avatar
rifkaki committed
1119 1120 1121 1122 1123 1124
                                // item.type_report_tax.value_tbc.type_report_id,
                                // item.type_report_tax.value_fc.type_report_id,
                                // item.type_report_tax.value_tbf.type_report_id,
                                0,
                                0,
                                0,
d.arizona's avatar
d.arizona committed
1125 1126 1127 1128 1129
                                item.id,
                                item.parent,
                                { tbc: item.formula_tax.value_tbc, fcp: item.formula_tax.value_fc, tbf: item.formula_tax.value_tbf },
                                item.level,
                                item.description,
rifkaki's avatar
rifkaki committed
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
                                item.tax_planning_report.january,
                                item.tax_planning_report.february,
                                item.tax_planning_report.march,
                                item.tax_planning_report.april,
                                item.tax_planning_report.may,
                                item.tax_planning_report.june,
                                item.tax_planning_report.july,
                                item.tax_planning_report.august,
                                item.tax_planning_report.september,
                                item.tax_planning_report.october,
                                item.tax_planning_report.november,
                                item.tax_planning_report.december,
d.arizona's avatar
d.arizona committed
1142
                                item.order,
rifkaki's avatar
rifkaki committed
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
                                item.tax_planning_report.monthly_january,
                                item.tax_planning_report.monthly_february,
                                item.tax_planning_report.monthly_march,
                                item.tax_planning_report.monthly_april,
                                item.tax_planning_report.monthly_may,
                                item.tax_planning_report.monthly_june,
                                item.tax_planning_report.monthly_july,
                                item.tax_planning_report.monthly_august,
                                item.tax_planning_report.monthly_september,
                                item.tax_planning_report.monthly_october,
                                item.tax_planning_report.monthly_november,
                                item.tax_planning_report.monthly_december,
rifkaki's avatar
rifkaki committed
1155
                                item.tax_planning_report.monthly_full_year,
d.arizona's avatar
d.arizona committed
1156 1157 1158 1159 1160 1161 1162 1163 1164
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
rifkaki's avatar
rifkaki committed
1165
                        console.log(dataTable)
rifkaki's avatar
rifkaki committed
1166 1167 1168 1169
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                        // this.setState({ dataTable }, () => {
                        //     this.getTaxPlanMR(payload)
                        // })
d.arizona's avatar
d.arizona committed
1170
                    } else {
d.arizona's avatar
d.arizona committed
1171 1172 1173 1174 1175 1176 1177 1178
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                            if (response.data.message.includes("Someone Logged In")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
d.arizona's avatar
d.arizona committed
1179
                    }
d.arizona's avatar
d.arizona committed
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                }
            })
        } else if (this.state.report.value === 21) {
            let OPID = null
            let payload = {
                "company_id": this.state.company.company_id,
                "periode": this.state.periode.periode
            }
            api.create().getOpetratingIndID(payload).then(response => {
                console.log(response);
                if (response) {
                    // console.log(response.data.data)
                    if (response.data.data) {
                        OPID = response.data.data.operating_indicator_id
                    } else {
d.arizona's avatar
d.arizona committed
1197
                        OPID = null
d.arizona's avatar
d.arizona committed
1198
                    }
d.arizona's avatar
d.arizona committed
1199
                    this.setState({ OPID }, () => {
d.arizona's avatar
d.arizona committed
1200 1201 1202 1203 1204 1205
                        let payloadOI = {
                            "company_id": this.state.company.company_id,
                            "operating_indicator_id": this.state.OPID,
                            "periode": this.state.periode.periode,
                            "report_id": 21
                        }
d.arizona's avatar
d.arizona committed
1206

1207
                        api.create().getAllReportOI(payloadOI).then(response => {
d.arizona's avatar
d.arizona committed
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239
                            // console.log(payload);
                            console.log(response);
                            let dataTable = []
                            if (response.data) {
                                if (response.data.status === 'success') {
                                    let res = response.data.data
                                    // // // console.log(res) 
                                    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,
                                                item.uom,
                                                item.master_budget.total_actual_before == "" ? item.master_budget.total_actual_before : String(item.master_budget.total_actual_before).indexOf(".") == -1 ? Number(item.master_budget.total_actual_before) : Number(item.master_budget.total_actual_before).toFixed(1),
                                                item.master_budget.january == "" ? item.master_budget.january : String(item.master_budget.january).indexOf(".") == -1 ? Number(item.master_budget.january) : Number(item.master_budget.january).toFixed(1),
                                                item.master_budget.february == "" ? item.master_budget.february : String(item.master_budget.february).indexOf(".") == -1 ? Number(item.master_budget.february) : Number(item.master_budget.february).toFixed(1),
                                                item.master_budget.march == "" ? item.master_budget.march : String(item.master_budget.march).indexOf(".") == -1 ? Number(item.master_budget.march) : Number(item.master_budget.march).toFixed(1),
                                                item.master_budget.april == "" ? item.master_budget.april : String(item.master_budget.april).indexOf(".") == -1 ? Number(item.master_budget.april) : Number(item.master_budget.april).toFixed(1),
                                                item.master_budget.may == "" ? item.master_budget.may : String(item.master_budget.may).indexOf(".") == -1 ? Number(item.master_budget.may) : Number(item.master_budget.may).toFixed(1),
                                                item.master_budget.june == "" ? item.master_budget.june : String(item.master_budget.june).indexOf(".") == -1 ? Number(item.master_budget.june) : Number(item.master_budget.june).toFixed(1),
                                                item.master_budget.july == "" ? item.master_budget.july : String(item.master_budget.july).indexOf(".") == -1 ? Number(item.master_budget.july) : Number(item.master_budget.july).toFixed(1),
                                                item.master_budget.august == "" ? item.master_budget.august : String(item.master_budget.august).indexOf(".") == -1 ? Number(item.master_budget.august) : Number(item.master_budget.august).toFixed(1),
                                                item.master_budget.september == "" ? item.master_budget.september : String(item.master_budget.september).indexOf(".") == -1 ? Number(item.master_budget.september) : Number(item.master_budget.september).toFixed(1),
                                                item.master_budget.october == "" ? item.master_budget.october : String(item.master_budget.october).indexOf(".") == -1 ? Number(item.master_budget.october) : Number(item.master_budget.october).toFixed(1),
                                                item.master_budget.november == "" ? item.master_budget.november : String(item.master_budget.november).indexOf(".") == -1 ? Number(item.master_budget.november) : Number(item.master_budget.november).toFixed(1),
                                                item.master_budget.december == "" ? item.master_budget.december : String(item.master_budget.december).indexOf(".") == -1 ? Number(item.master_budget.december) : Number(item.master_budget.december).toFixed(1),
                                                item.master_budget.total_current_year == "" ? item.master_budget.total_current_year : String(item.master_budget.total_current_year).indexOf(".") == -1 ? Number(item.master_budget.total_current_year) : Number(item.master_budget.total_current_year).toFixed(1),
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252
                                                item.order,
                                                item.master_budget.monthly_january == "" ? item.master_budget.monthly_january : String(item.master_budget.monthly_january).indexOf(".") == -1 ? Number(item.master_budget.monthly_january) : Number(item.master_budget.monthly_january).toFixed(1),
                                                item.master_budget.monthly_february == "" ? item.master_budget.monthly_february : String(item.master_budget.monthly_february).indexOf(".") == -1 ? Number(item.master_budget.monthly_february) : Number(item.master_budget.monthly_february).toFixed(1),
                                                item.master_budget.monthly_march == "" ? item.master_budget.monthly_march : String(item.master_budget.monthly_march).indexOf(".") == -1 ? Number(item.master_budget.monthly_march) : Number(item.master_budget.monthly_march).toFixed(1),
                                                item.master_budget.monthly_april == "" ? item.master_budget.monthly_april : String(item.master_budget.monthly_april).indexOf(".") == -1 ? Number(item.master_budget.monthly_april) : Number(item.master_budget.monthly_april).toFixed(1),
                                                item.master_budget.monthly_may == "" ? item.master_budget.monthly_may : String(item.master_budget.monthly_may).indexOf(".") == -1 ? Number(item.master_budget.monthly_may) : Number(item.master_budget.monthly_may).toFixed(1),
                                                item.master_budget.monthly_june == "" ? item.master_budget.monthly_june : String(item.master_budget.monthly_june).indexOf(".") == -1 ? Number(item.master_budget.monthly_june) : Number(item.master_budget.monthly_june).toFixed(1),
                                                item.master_budget.monthly_july == "" ? item.master_budget.monthly_july : String(item.master_budget.monthly_july).indexOf(".") == -1 ? Number(item.master_budget.monthly_july) : Number(item.master_budget.monthly_july).toFixed(1),
                                                item.master_budget.monthly_august == "" ? item.master_budget.monthly_august : String(item.master_budget.monthly_august).indexOf(".") == -1 ? Number(item.master_budget.monthly_august) : Number(item.master_budget.monthly_august).toFixed(1),
                                                item.master_budget.monthly_september == "" ? item.master_budget.monthly_september : String(item.master_budget.monthly_september).indexOf(".") == -1 ? Number(item.master_budget.monthly_september) : Number(item.master_budget.monthly_september).toFixed(1),
                                                item.master_budget.monthly_october == "" ? item.master_budget.monthly_october : String(item.master_budget.monthly_october).indexOf(".") == -1 ? Number(item.master_budget.monthly_october) : Number(item.master_budget.monthly_october).toFixed(1),
                                                item.master_budget.monthly_november == "" ? item.master_budget.monthly_november : String(item.master_budget.monthly_november).indexOf(".") == -1 ? Number(item.master_budget.monthly_november) : Number(item.master_budget.monthly_november).toFixed(1),
                                                item.master_budget.monthly_december == "" ? item.master_budget.monthly_december : String(item.master_budget.monthly_december).indexOf(".") == -1 ? Number(item.master_budget.monthly_december) : Number(item.master_budget.monthly_december).toFixed(1),
d.arizona's avatar
d.arizona committed
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
                                            ])
                                        }
                                        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,
                                            item.uom,
                                            item.master_budget.total_actual_before == "" ? item.master_budget.total_actual_before : String(item.master_budget.total_actual_before).indexOf(".") == -1 ? Number(item.master_budget.total_actual_before) : Number(item.master_budget.total_actual_before).toFixed(1),
                                            item.master_budget.january == "" ? item.master_budget.january : String(item.master_budget.january).indexOf(".") == -1 ? Number(item.master_budget.january) : Number(item.master_budget.january).toFixed(1),
                                            item.master_budget.february == "" ? item.master_budget.february : String(item.master_budget.february).indexOf(".") == -1 ? Number(item.master_budget.february) : Number(item.master_budget.february).toFixed(1),
                                            item.master_budget.march == "" ? item.master_budget.march : String(item.master_budget.march).indexOf(".") == -1 ? Number(item.master_budget.march) : Number(item.master_budget.march).toFixed(1),
                                            item.master_budget.april == "" ? item.master_budget.april : String(item.master_budget.april).indexOf(".") == -1 ? Number(item.master_budget.april) : Number(item.master_budget.april).toFixed(1),
                                            item.master_budget.may == "" ? item.master_budget.may : String(item.master_budget.may).indexOf(".") == -1 ? Number(item.master_budget.may) : Number(item.master_budget.may).toFixed(1),
                                            item.master_budget.june == "" ? item.master_budget.june : String(item.master_budget.june).indexOf(".") == -1 ? Number(item.master_budget.june) : Number(item.master_budget.june).toFixed(1),
                                            item.master_budget.july == "" ? item.master_budget.july : String(item.master_budget.july).indexOf(".") == -1 ? Number(item.master_budget.july) : Number(item.master_budget.july).toFixed(1),
                                            item.master_budget.august == "" ? item.master_budget.august : String(item.master_budget.august).indexOf(".") == -1 ? Number(item.master_budget.august) : Number(item.master_budget.august).toFixed(1),
                                            item.master_budget.september == "" ? item.master_budget.september : String(item.master_budget.september).indexOf(".") == -1 ? Number(item.master_budget.september) : Number(item.master_budget.september).toFixed(1),
                                            item.master_budget.october == "" ? item.master_budget.october : String(item.master_budget.october).indexOf(".") == -1 ? Number(item.master_budget.october) : Number(item.master_budget.october).toFixed(1),
                                            item.master_budget.november == "" ? item.master_budget.november : String(item.master_budget.november).indexOf(".") == -1 ? Number(item.master_budget.november) : Number(item.master_budget.november).toFixed(1),
                                            item.master_budget.december == "" ? item.master_budget.december : String(item.master_budget.december).indexOf(".") == -1 ? Number(item.master_budget.december) : Number(item.master_budget.december).toFixed(1),
                                            item.master_budget.total_current_year == "" ? item.master_budget.total_current_year : String(item.master_budget.total_current_year).indexOf(".") == -1 ? Number(item.master_budget.total_current_year) : Number(item.master_budget.total_current_year).toFixed(1),
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
                                            item.order,
                                            item.master_budget.monthly_january == "" ? item.master_budget.monthly_january : String(item.master_budget.monthly_january).indexOf(".") == -1 ? Number(item.master_budget.monthly_january) : Number(item.master_budget.monthly_january).toFixed(1),
                                            item.master_budget.monthly_february == "" ? item.master_budget.monthly_february : String(item.master_budget.monthly_february).indexOf(".") == -1 ? Number(item.master_budget.monthly_february) : Number(item.master_budget.monthly_february).toFixed(1),
                                            item.master_budget.monthly_march == "" ? item.master_budget.monthly_march : String(item.master_budget.monthly_march).indexOf(".") == -1 ? Number(item.master_budget.monthly_march) : Number(item.master_budget.monthly_march).toFixed(1),
                                            item.master_budget.monthly_april == "" ? item.master_budget.monthly_april : String(item.master_budget.monthly_april).indexOf(".") == -1 ? Number(item.master_budget.monthly_april) : Number(item.master_budget.monthly_april).toFixed(1),
                                            item.master_budget.monthly_may == "" ? item.master_budget.monthly_may : String(item.master_budget.monthly_may).indexOf(".") == -1 ? Number(item.master_budget.monthly_may) : Number(item.master_budget.monthly_may).toFixed(1),
                                            item.master_budget.monthly_june == "" ? item.master_budget.monthly_june : String(item.master_budget.monthly_june).indexOf(".") == -1 ? Number(item.master_budget.monthly_june) : Number(item.master_budget.monthly_june).toFixed(1),
                                            item.master_budget.monthly_july == "" ? item.master_budget.monthly_july : String(item.master_budget.monthly_july).indexOf(".") == -1 ? Number(item.master_budget.monthly_july) : Number(item.master_budget.monthly_july).toFixed(1),
                                            item.master_budget.monthly_august == "" ? item.master_budget.monthly_august : String(item.master_budget.monthly_august).indexOf(".") == -1 ? Number(item.master_budget.monthly_august) : Number(item.master_budget.monthly_august).toFixed(1),
                                            item.master_budget.monthly_september == "" ? item.master_budget.monthly_september : String(item.master_budget.monthly_september).indexOf(".") == -1 ? Number(item.master_budget.monthly_september) : Number(item.master_budget.monthly_september).toFixed(1),
                                            item.master_budget.monthly_october == "" ? item.master_budget.monthly_october : String(item.master_budget.monthly_october).indexOf(".") == -1 ? Number(item.master_budget.monthly_october) : Number(item.master_budget.monthly_october).toFixed(1),
                                            item.master_budget.monthly_november == "" ? item.master_budget.monthly_november : String(item.master_budget.monthly_november).indexOf(".") == -1 ? Number(item.master_budget.monthly_november) : Number(item.master_budget.monthly_november).toFixed(1),
                                            item.master_budget.monthly_december == "" ? item.master_budget.monthly_december : String(item.master_budget.monthly_december).indexOf(".") == -1 ? Number(item.master_budget.monthly_december) : Number(item.master_budget.monthly_december).toFixed(1),
d.arizona's avatar
d.arizona committed
1299 1300 1301 1302 1303 1304 1305 1306 1307
                                        ])
                                        if (item.children !== null) {
                                            if (item.children.length > 0) {
                                                item.children.map((items, indexs) => {
                                                    handlePushChild(items)
                                                })
                                            }
                                        }
                                    })
d.arizona's avatar
d.arizona committed
1308
                                    this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
1309 1310 1311 1312 1313

                                    // this.setState({ dataTable }, () => {
                                    //     console.log(this.state.dataTable)
                                    //     this.getOIMR(payloadOI)
                                    // })
d.arizona's avatar
d.arizona committed
1314
                                } else {
d.arizona's avatar
d.arizona committed
1315 1316 1317 1318 1319 1320 1321 1322
                                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                                        if (response.data.message.includes("Someone Logged In")) {
                                            setTimeout(() => {
                                                localStorage.removeItem(Constant.TOKEN)
                                                window.location.reload();
                                            }, 1000);
                                        }
                                    })
d.arizona's avatar
d.arizona committed
1323
                                }
d.arizona's avatar
d.arizona committed
1324 1325 1326 1327 1328
                            } else {
                                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                            }
                        })
                    })
d.arizona's avatar
d.arizona committed
1329 1330
                }
            })
d.arizona's avatar
d.arizona committed
1331
        } else if (this.state.report.value === 6) {
d.arizona's avatar
d.arizona committed
1332
            let dbSumaCF = []
d.arizona's avatar
d.arizona committed
1333
            let paylodCF = { ...payload, months: this.state.month.month_id }
d.arizona's avatar
d.arizona committed
1334
            api.create().getReportCFSuma(paylodCF).then(response => {
d.arizona's avatar
d.arizona committed
1335
                console.log(response)
d.arizona's avatar
d.arizona committed
1336 1337 1338
                if (response.data) {
                    if (response.data.status === 'success') {
                        let res = response.data.data
d.arizona's avatar
d.arizona committed
1339
                        console.log(res)
d.arizona's avatar
d.arizona committed
1340
                        const handlePushChild = (item) => {
rifkaki's avatar
rifkaki committed
1341
                            let indexIDzz = dbSumaCF.findIndex((val) => val[0] === item.id)
d.arizona's avatar
d.arizona committed
1342
                            if (indexIDzz === -1) {
rifkaki's avatar
rifkaki committed
1343 1344
                                let mtd_actual = item.cash_flow.mtd_actual == '' ? 0 : Number(item.cash_flow.mtd_actual)
                                let mtd = item.cash_flow.mtd == '' ? 0 : Number(item.cash_flow.mtd)
rifkaki's avatar
rifkaki committed
1345
                                console.log(mtd)
rifkaki's avatar
rifkaki committed
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373
                                // let persenMtd = Number(mtd_actual / mtd)
                                let persenMtd = 0
                                if (mtd < 0) {
                                    if (mtd_actual >= mtd) {
                                        persenMtd = ((mtd - mtd_actual) / mtd + 1 ) 
                                    }  else {
                                        persenMtd = ((mtd - mtd_actual) / mtd) 
                                    }
                                }
                                else {
                                    persenMtd = Number(mtd_actual / mtd) 
                                }

                                let ytd_actual = item.cash_flow.ytd_actual == '' ? 0 : Number(item.cash_flow.ytd_actual)
                                let ytd = item.cash_flow.ytd == '' ? 0 : Number(item.cash_flow.ytd)

                                // let persenYtd = Number(ytd_actual / ytd)
                                let persenYtd = 0
                                if (ytd  < 0) {
                                    if (ytd_actual >= ytd) {
                                        persenYtd = ((ytd - ytd_actual) / ytd + 1 ) 
                                    }  else {
                                        persenYtd = ((ytd - ytd_actual) / ytd) 
                                    }
                                }
                                else {
                                    persenYtd = Number(ytd_actual/ytd) 
                                }
d.arizona's avatar
d.arizona committed
1374

rifkaki's avatar
rifkaki committed
1375 1376
                                let quarter_actual = item.cash_flow.quarter_actual == '' ? 0 : Number(item.cash_flow.quarter_actual)
                                let quarter = item.cash_flow.quarter == '' ? 0 : Number(item.cash_flow.quarter)
rifkaki's avatar
rifkaki committed
1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
                                // let persenQuarter = Number(quarter_actual / quarter)
                                let persenQuarter = 0
                                if (quarter  < 0) {
                                    if (quarter_actual >= quarter) {
                                        persenQuarter = (quarter - quarter_actual) / quarter + 1  
                                    }  else {
                                        persenQuarter = (quarter - quarter_actual) / quarter 
                                    }
                                }
                                else {
                                    persenQuarter = quarter_actual / quarter
                                }
d.arizona's avatar
d.arizona committed
1389

rifkaki's avatar
rifkaki committed
1390 1391
                                let fy_actual = item.cash_flow.fy_actual == '' ? 0 : Number(item.cash_flow.fy_actual)
                                let fy = item.cash_flow.fy == '' ? 0 : Number(item.cash_flow.fy)
rifkaki's avatar
rifkaki committed
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403
                                // let persenFy = Number(fy_actual / fy)
                                let persenFy = 0
                                if (fy  < 0) {
                                    if (fy_actual >= fy) {
                                        persenFy = (fy - fy_actual) / fy + 1  
                                    }  else {
                                        persenFy = (fy - fy_actual) / fy 
                                    }
                                }
                                else {
                                    persenFy = fy_actual / fy
                                }
d.arizona's avatar
d.arizona committed
1404 1405

                                dbSumaCF.push([
d.arizona's avatar
d.arizona committed
1406
                                    item.id,
d.arizona's avatar
d.arizona committed
1407 1408
                                    item.cash_flow.mtd_actual,
                                    item.cash_flow.mtd,
d.arizona's avatar
d.arizona committed
1409
                                    isNaN(persenMtd) || persenMtd == 'Infinity' || persenMtd == '-Infinity' ? (item.cash_flow.mtd == '' || item.cash_flow.mtd == 0 ? -0 : 0) : (item.cash_flow.mtd == '' || item.cash_flow.mtd == 0 ? persenMtd * -100 : persenMtd * 100),
d.arizona's avatar
d.arizona committed
1410 1411 1412
                                    item.cash_flow.mtd_last_year,
                                    item.cash_flow.ytd_actual,
                                    item.cash_flow.ytd,
d.arizona's avatar
d.arizona committed
1413
                                    isNaN(persenYtd) || persenYtd == 'Infinity' || persenYtd == '-Infinity' ? (item.cash_flow.ytd == '' || item.cash_flow.ytd == 0 ? -0 : 0) : (item.cash_flow.ytd == '' || item.cash_flow.ytd == 0 ? persenYtd * -100 : persenYtd * 100),
d.arizona's avatar
d.arizona committed
1414
                                    // isNaN(persenYtd)? 0 : persenYtd * 100,
d.arizona's avatar
d.arizona committed
1415 1416 1417
                                    item.cash_flow.ytd_last_year,
                                    item.cash_flow.quarter_actual,
                                    item.cash_flow.quarter,
d.arizona's avatar
d.arizona committed
1418
                                    isNaN(persenQuarter) || persenQuarter == 'Infinity' || persenQuarter == '-Infinity' ? (item.cash_flow.quarter == '' || item.cash_flow.quarter == 0 ? -0 : 0) : (item.cash_flow.quarter == '' || item.cash_flow.quarter == 0 ? persenQuarter * -100 : persenQuarter * 100),
d.arizona's avatar
d.arizona committed
1419
                                    // isNaN(persenQuarter)? 0 : persenQuarter * 100,
d.arizona's avatar
d.arizona committed
1420 1421 1422
                                    item.cash_flow.quarter_last_year,
                                    item.cash_flow.fy_actual,
                                    item.cash_flow.fy,
d.arizona's avatar
d.arizona committed
1423
                                    isNaN(persenFy) || persenFy == 'Infinity' || persenFy == '-Infinity' ? (item.cash_flow.fy == '' || item.cash_flow.fy == 0 ? -0 : 0) : (item.cash_flow.fy == '' || item.cash_flow.fy == 0 ? persenFy * -100 : persenFy * 100),
d.arizona's avatar
d.arizona committed
1424
                                    // isNaN(persenFy)? 0 : persenFy * 100,
d.arizona's avatar
d.arizona committed
1425
                                    item.cash_flow.fy_last_year,
d.arizona's avatar
d.arizona committed
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
d.arizona's avatar
d.arizona committed
1436
                        res.map((item, index) => {
rifkaki's avatar
rifkaki committed
1437 1438 1439
                            let mtd_actual = item.cash_flow.mtd_actual == '' ? 0 : Number(item.cash_flow.mtd_actual)
                            let mtd = item.cash_flow.mtd == '' ? 0 : Number(item.cash_flow.mtd)
                            console.log(mtd)
rifkaki's avatar
rifkaki committed
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466
                            // let persenMtd = Number(mtd_actual / mtd)
                            let persenMtd = 0
                            if (mtd < 0) {
                                if (mtd_actual >= mtd) {
                                    persenMtd = ((mtd - mtd_actual) / mtd + 1 ) 
                                }  else {
                                    persenMtd = ((mtd - mtd_actual) / mtd) 
                                }
                            }
                            else {
                                persenMtd = Number(mtd_actual / mtd) 
                            }

                            let ytd_actual = item.cash_flow.ytd_actual == '' ? 0 : Number(item.cash_flow.ytd_actual)
                            let ytd = item.cash_flow.ytd == '' ? 0 : Number(item.cash_flow.ytd)
                            // let persenYtd = Number(ytd_actual / ytd)
                            let persenYtd = 0
                            if (ytd  < 0) {
                                if (ytd_actual >= ytd) {
                                    persenYtd = ((ytd - ytd_actual) / ytd + 1 ) 
                                }  else {
                                    persenYtd = ((ytd - ytd_actual) / ytd) 
                                }
                            }
                            else {
                                persenYtd = Number(ytd_actual/ytd) 
                            }
d.arizona's avatar
d.arizona committed
1467

rifkaki's avatar
rifkaki committed
1468 1469
                            let quarter_actual = item.cash_flow.quarter_actual == '' ? 0 : Number(item.cash_flow.quarter_actual)
                            let quarter = item.cash_flow.quarter == '' ? 0 : Number(item.cash_flow.quarter)
rifkaki's avatar
rifkaki committed
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
                            // let persenQuarter = Number(quarter_actual / quarter)
                            let persenQuarter = 0
                            if (quarter  < 0) {
                                if (quarter_actual >= quarter) {
                                    persenQuarter = (quarter - quarter_actual) / quarter + 1  
                                }  else {
                                    persenQuarter = (quarter - quarter_actual) / quarter 
                                }
                            }
                            else {
                                persenQuarter = quarter_actual / quarter
                            }
d.arizona's avatar
d.arizona committed
1482

rifkaki's avatar
rifkaki committed
1483 1484
                            let fy_actual = item.cash_flow.fy_actual == '' ? 0 : Number(item.cash_flow.fy_actual)
                            let fy = item.cash_flow.fy == '' ? 0 : Number(item.cash_flow.fy)
rifkaki's avatar
rifkaki committed
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496
                            // let persenFy = Number(fy_actual / fy)
                            let persenFy = 0
                            if (fy  < 0) {
                                if (fy_actual >= fy) {
                                    persenFy = (fy - fy_actual) / fy + 1  
                                }  else {
                                    persenFy = (fy - fy_actual) / fy 
                                }
                            }
                            else {
                                persenFy = fy_actual / fy
                            }
d.arizona's avatar
d.arizona committed
1497 1498

                            dbSumaCF.push([
d.arizona's avatar
d.arizona committed
1499
                                item.id,
d.arizona's avatar
d.arizona committed
1500 1501
                                item.cash_flow.mtd_actual,
                                item.cash_flow.mtd,
d.arizona's avatar
d.arizona committed
1502
                                isNaN(persenMtd) || persenMtd == 'Infinity' || persenMtd == '-Infinity' ? (item.cash_flow.mtd == '' || item.cash_flow.mtd == 0 ? -0 : 0) : (item.cash_flow.mtd == '' || item.cash_flow.mtd == 0 ? persenMtd * -100 : persenMtd * 100),
d.arizona's avatar
d.arizona committed
1503 1504 1505
                                item.cash_flow.mtd_last_year,
                                item.cash_flow.ytd_actual,
                                item.cash_flow.ytd,
d.arizona's avatar
d.arizona committed
1506
                                isNaN(persenYtd) || persenYtd == 'Infinity' || persenYtd == '-Infinity' ? (item.cash_flow.ytd == '' || item.cash_flow.ytd == 0 ? -0 : 0) : (item.cash_flow.ytd == '' || item.cash_flow.ytd == 0 ? persenYtd * -100 : persenYtd * 100),
d.arizona's avatar
d.arizona committed
1507
                                // isNaN(persenYtd)? 0 : persenYtd * 100,
d.arizona's avatar
d.arizona committed
1508 1509 1510
                                item.cash_flow.ytd_last_year,
                                item.cash_flow.quarter_actual,
                                item.cash_flow.quarter,
d.arizona's avatar
d.arizona committed
1511
                                isNaN(persenQuarter) || persenQuarter == 'Infinity' || persenQuarter == '-Infinity' ? (item.cash_flow.quarter == '' || item.cash_flow.quarter == 0 ? -0 : 0) : (item.cash_flow.quarter == '' || item.cash_flow.quarter == 0 ? persenQuarter * -100 : persenQuarter * 100),
d.arizona's avatar
d.arizona committed
1512
                                // isNaN(persenQuarter)? 0 : persenQuarter * 100,
d.arizona's avatar
d.arizona committed
1513 1514 1515
                                item.cash_flow.quarter_last_year,
                                item.cash_flow.fy_actual,
                                item.cash_flow.fy,
d.arizona's avatar
d.arizona committed
1516
                                isNaN(persenFy) || persenFy == 'Infinity' || persenFy == '-Infinity' ? (item.cash_flow.fy == '' || item.cash_flow.fy == 0 ? -0 : 0) : (item.cash_flow.fy == '' || item.cash_flow.fy == 0 ? persenFy * -100 : persenFy * 100),
d.arizona's avatar
d.arizona committed
1517
                                // isNaN(persenFy)? 0 : persenFy * 100,
d.arizona's avatar
d.arizona committed
1518
                                item.cash_flow.fy_last_year,
d.arizona's avatar
d.arizona committed
1519 1520 1521 1522 1523 1524 1525 1526 1527
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
d.arizona's avatar
d.arizona committed
1528
                        console.log(dbSumaCF)
d.arizona's avatar
d.arizona committed
1529
                        this.setState({ dbSumaCF }, () => {
d.arizona's avatar
d.arizona committed
1530 1531 1532 1533 1534 1535 1536
                            api.create().getReportCFSumaMB(payload).then(response => {
                                // console.log(payload);
                                console.log(response);
                                let dataTable = []
                                if (response.data) {
                                    if (response.data.status === 'success') {
                                        let res = response.data.data
d.arizona's avatar
d.arizona committed
1537
                                        console.log(res)
d.arizona's avatar
d.arizona committed
1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616
                                        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,
                                                    item.cash_flow.total_actual_before,
                                                    item.cash_flow.january,
                                                    item.cash_flow.february,
                                                    item.cash_flow.march,
                                                    item.cash_flow.april,
                                                    item.cash_flow.may,
                                                    item.cash_flow.june,
                                                    item.cash_flow.july,
                                                    item.cash_flow.august,
                                                    item.cash_flow.september,
                                                    item.cash_flow.october,
                                                    item.cash_flow.november,
                                                    item.cash_flow.december,
                                                    item.cash_flow.total_current_year,
                                                    item.cash_flow.total_next_year,
                                                    item.cash_flow.total_more_year,
                                                    item.order,
                                                    item.condition_it_should_be,
                                                    item.condition_if_wrong,
                                                    item.cash_flow.forecast_formula == null ? [] : item.cash_flow.forecast_formula
                                                ])
                                            }
                                            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,
                                                item.cash_flow.total_actual_before,
                                                item.cash_flow.january,
                                                item.cash_flow.february,
                                                item.cash_flow.march,
                                                item.cash_flow.april,
                                                item.cash_flow.may,
                                                item.cash_flow.june,
                                                item.cash_flow.july,
                                                item.cash_flow.august,
                                                item.cash_flow.september,
                                                item.cash_flow.october,
                                                item.cash_flow.november,
                                                item.cash_flow.december,
                                                item.cash_flow.total_current_year,
                                                item.cash_flow.total_next_year,
                                                item.cash_flow.total_more_year,
                                                item.order,
                                                item.condition_it_should_be,
                                                item.condition_if_wrong,
                                                item.cash_flow.forecast_formula == null ? [] : item.cash_flow.forecast_formula
                                            ])
                                            if (item.children !== null) {
                                                if (item.children.length > 0) {
                                                    item.children.map((items, indexs) => {
                                                        handlePushChild(items)
                                                    })
                                                }
                                            }
                                        })
                                        this.setState({ dataTable }, () => {
                                            console.log(this.state.dataTable)
d.arizona's avatar
d.arizona committed
1617
                                            this.getCFSumaMR(paylodCF, dbSumaCF)
d.arizona's avatar
d.arizona committed
1618
                                        })
d.arizona's avatar
d.arizona committed
1619
                                    } else {
d.arizona's avatar
d.arizona committed
1620 1621 1622 1623 1624 1625 1626 1627
                                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                                            if (response.data.message.includes("Someone Logged In")) {
                                                setTimeout(() => {
                                                    localStorage.removeItem(Constant.TOKEN)
                                                    window.location.reload();
                                                }, 1000);
                                            }
                                        })
d.arizona's avatar
d.arizona committed
1628
                                    }
d.arizona's avatar
d.arizona committed
1629 1630 1631 1632
                                } else {
                                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                                }
                            })
d.arizona's avatar
d.arizona committed
1633
                        })
d.arizona's avatar
d.arizona committed
1634
                    } else {
d.arizona's avatar
d.arizona committed
1635 1636 1637 1638 1639 1640 1641 1642
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                            if (response.data.message.includes("Someone Logged In")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
d.arizona's avatar
d.arizona committed
1643
                    }
d.arizona's avatar
d.arizona committed
1644 1645 1646 1647
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                }
            })
Riri Novita's avatar
Riri Novita committed
1648
        } else if (this.state.report.value === 7) {
faisalhamdi's avatar
faisalhamdi committed
1649 1650 1651 1652
            let dbSumaBS = []
            let payloadBS = {...payload, report_id: 2, months: this.state.month.month_id, quarter: 0}                
            api.create().getReportBSSuma(payloadBS).then(response => {
                // console.log(payloadBS);
Riri Novita's avatar
Riri Novita committed
1653
                console.log(response);
faisalhamdi's avatar
faisalhamdi committed
1654
                if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666
                    if (response.data.status === 'success') {
                        let res = response.data.data
                        const handlePushChild = (item) => {
                            let indexIDzz = dbSumaBS.findIndex((val) => val[1] === item.id)
                            if (indexIDzz === -1) {
                                let mtd_actual = item.balance_sheet.mtd_actual == '' ? 0 : item.balance_sheet.mtd_actual
                                let mtd_ol = item.balance_sheet.mtd_ol == '' ? 0 : item.balance_sheet.mtd_ol
                                let mtd_mb = item.balance_sheet.mtd_mb == '' ? 0 : item.balance_sheet.mtd_mb
                                let persenMtd = 0
                                let persenOL = 0

                                if (mtd_mb < 0) {
1667
                                    if (parseFloat(mtd_actual) < parseFloat(mtd_mb)) {
faisalhamdi's avatar
faisalhamdi committed
1668 1669 1670 1671 1672 1673 1674 1675 1676
                                        persenMtd = Number((mtd_mb - mtd_actual)/mtd_mb)
                                    } else {
                                        persenMtd = Number((mtd_mb - mtd_actual)/mtd_mb) + 1
                                    }
                                } else {
                                    persenMtd = Number(mtd_actual/mtd_mb)
                                }

                                if (mtd_ol < 0) {
1677
                                    if (parseFloat(mtd_actual) < parseFloat(mtd_ol)) {
faisalhamdi's avatar
faisalhamdi committed
1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720
                                        persenOL = Number((mtd_ol - mtd_actual)/mtd_ol)
                                    } else {
                                        persenOL = Number((mtd_ol - mtd_actual)/mtd_ol) + 1
                                    }
                                } else {
                                    persenOL = Number(mtd_actual/mtd_ol)
                                }

                                dbSumaBS.push([
                                    item.type_report_id,
                                    item.id,
                                    item.parent,
                                    item.formula,
                                    item.level,
                                    item.description,
                                    item.balance_sheet.mtd_last_month,
                                    item.balance_sheet.mtd_actual,
                                    item.balance_sheet.mtd_mb,
                                    isNaN(persenMtd) || persenMtd == 'Infinity' || persenMtd == '-Infinity' ? (item.balance_sheet.mtd_mb == '' || item.balance_sheet.mtd_mb == 0 ? -0 : 0) : (item.balance_sheet.mtd_mb == '' || item.balance_sheet.mtd_mb == 0 ? persenMtd * -100 : persenMtd * 100),
                                    item.balance_sheet.mtd_ol,
                                    isNaN(persenOL) || persenOL == 'Infinity' || persenOL == '-Infinity' ? (item.balance_sheet.mtd_ol == '' || item.balance_sheet.mtd_ol == 0 ? -0 : 0) : (item.balance_sheet.mtd_ol == '' || item.balance_sheet.mtd_ol == 0 ? persenOL * -100 : persenOL * 100),
                                    item.balance_sheet.mtd_last_year,
                                    item.balance_sheet.forecast_next_year,
                                    item.balance_sheet.forecast_more_year,
                                    item.order
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
                        res.map((item, index) => {
                            let mtd_actual = item.balance_sheet.mtd_actual == '' ? 0 : item.balance_sheet.mtd_actual
                            let mtd_ol = item.balance_sheet.mtd_ol == '' ? 0 : item.balance_sheet.mtd_ol
                            let mtd_mb = item.balance_sheet.mtd_mb == '' ? 0 : item.balance_sheet.mtd_mb
                            let persenMtd = 0
                            let persenOL = 0

                            if (mtd_mb < 0) {
1721
                                if (parseFloat(mtd_actual) < parseFloat(mtd_mb)) {
faisalhamdi's avatar
faisalhamdi committed
1722 1723 1724 1725 1726 1727 1728 1729 1730
                                    persenMtd = Number((mtd_mb - mtd_actual)/mtd_mb)
                                } else {
                                    persenMtd = Number((mtd_mb - mtd_actual)/mtd_mb) + 1
                                }
                            } else {
                                persenMtd = Number(mtd_actual/mtd_mb)
                            }

                            if (mtd_ol < 0) {
1731
                                if (parseFloat(mtd_actual) < parseFloat(mtd_ol)) {
faisalhamdi's avatar
faisalhamdi committed
1732 1733 1734 1735 1736 1737 1738 1739 1740
                                    persenOL = Number((mtd_ol - mtd_actual)/mtd_ol)
                                } else {
                                    persenOL = Number((mtd_ol - mtd_actual)/mtd_ol) + 1
                                }
                            } else {
                                persenOL = Number(mtd_actual/mtd_ol)
                            }

                            dbSumaBS.push([
faisalhamdi's avatar
faisalhamdi committed
1741 1742 1743 1744 1745 1746
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
faisalhamdi's avatar
faisalhamdi committed
1747
                                item.balance_sheet.mtd_last_month,
d.arizona's avatar
d.arizona committed
1748 1749
                                item.balance_sheet.mtd_actual,
                                item.balance_sheet.mtd_mb,
faisalhamdi's avatar
faisalhamdi committed
1750
                                isNaN(persenMtd) || persenMtd == 'Infinity' || persenMtd == '-Infinity' ? (item.balance_sheet.mtd_mb == '' || item.balance_sheet.mtd_mb == 0 ? -0 : 0) : (item.balance_sheet.mtd_mb == '' || item.balance_sheet.mtd_mb == 0 ? persenMtd * -100 : persenMtd * 100),
d.arizona's avatar
d.arizona committed
1751
                                item.balance_sheet.mtd_ol,
faisalhamdi's avatar
faisalhamdi committed
1752
                                isNaN(persenOL) || persenOL == 'Infinity' || persenOL == '-Infinity' ? (item.balance_sheet.mtd_ol == '' || item.balance_sheet.mtd_ol == 0 ? -0 : 0) : (item.balance_sheet.mtd_ol == '' || item.balance_sheet.mtd_ol == 0 ? persenOL * -100 : persenOL * 100),
faisalhamdi's avatar
faisalhamdi committed
1753
                                item.balance_sheet.mtd_last_year,
faisalhamdi's avatar
faisalhamdi committed
1754
                                item.balance_sheet.forecast_next_year,
d.arizona's avatar
d.arizona committed
1755
                                item.balance_sheet.forecast_more_year,
faisalhamdi's avatar
faisalhamdi committed
1756 1757
                                item.order
                            ])
faisalhamdi's avatar
faisalhamdi committed
1758 1759 1760 1761 1762 1763
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
faisalhamdi's avatar
faisalhamdi committed
1764
                            }
faisalhamdi's avatar
faisalhamdi committed
1765 1766
                        })
                        this.setState({ dataTable: dbSumaBS, previewTable: true, loading: false, previewDownload: true })
d.arizona's avatar
d.arizona committed
1767
                        console.log(this.state.dataTable)
faisalhamdi's avatar
faisalhamdi committed
1768 1769 1770 1771 1772 1773 1774 1775 1776 1777
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                            if (response.data.message.includes("Someone Logged In")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }                    
faisalhamdi's avatar
faisalhamdi committed
1778
                } else {
faisalhamdi's avatar
faisalhamdi committed
1779
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
faisalhamdi's avatar
faisalhamdi committed
1780
                }
Riri Novita's avatar
Riri Novita committed
1781 1782 1783
            })

        } else if (this.state.report.value === 8) {
Riri Novita's avatar
Riri Novita committed
1784
            let dbSumaPL = []
Riri Novita's avatar
Riri Novita committed
1785 1786
            let payloadPL = {...payload, report_id: 28, months: this.state.month.month_id, quarter: 0}
            api.create().getReportPLSummary(payloadPL).then(response => {
Riri Novita's avatar
Riri Novita committed
1787
                console.log(response);
Riri Novita's avatar
Riri Novita committed
1788 1789 1790 1791 1792 1793 1794
                if (response.data) {
                    if (response.data.status === 'success') {
                        let res = response.data.data
                        console.log(res) 
                        const handlePushChild = (item) => {
                            let indexIDzz = dbSumaPL.findIndex((val) => val[1] === item.id)
                            if (indexIDzz === -1) {
Riri Novita's avatar
Riri Novita committed
1795 1796 1797
                                let mtd_actual = item.profit_loss.mtd_actual == ''? 0 : Number(item.profit_loss.mtd_actual)
                                let mtd_mb = item.profit_loss.mtd_mb == ''? 0 : Number(item.profit_loss.mtd_mb)
                                let mtd_last_year = item.profit_loss.mtd_last_year == ''? 0 : Number(item.profit_loss.mtd_last_year)
Riri Novita's avatar
Riri Novita committed
1798 1799 1800
                                let persenMtd = 0
                                if (mtd_mb  < 0) {
                                    if (mtd_actual >= mtd_mb) {
Riri Novita's avatar
Riri Novita committed
1801
                                        persenMtd = (mtd_mb - mtd_actual) / mtd_mb + 1  
Riri Novita's avatar
Riri Novita committed
1802
                                    }  else {
Riri Novita's avatar
Riri Novita committed
1803
                                        persenMtd = (mtd_mb - mtd_actual) / mtd_mb 
Riri Novita's avatar
Riri Novita committed
1804 1805 1806
                                    }
                                }
                                else {
Riri Novita's avatar
Riri Novita committed
1807
                                    persenMtd = mtd_actual / mtd_mb
Riri Novita's avatar
Riri Novita committed
1808 1809
                                }

Riri Novita's avatar
Riri Novita committed
1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822
                                let persenMtdLY = 0
                                if (mtd_last_year  < 0) {
                                    if (mtd_actual >= mtd_last_year) {
                                        persenMtdLY = (mtd_last_year - mtd_actual) / mtd_last_year + 1 
                                    }  else {
                                        persenMtdLY = (mtd_last_year - mtd_actual) / mtd_last_year
                                    }
                                }
                                else {
                                    persenMtdLY = mtd_actual/mtd_last_year
                                }


Riri Novita's avatar
Riri Novita committed
1823 1824 1825 1826 1827 1828
                                let ytd_actual = item.profit_loss.ytd_actual == ''? 0 : Number(item.profit_loss.ytd_actual)
                                let ytd_mb = item.profit_loss.ytd_mb == ''? 0 : Number(item.profit_loss.ytd_mb)
                                let ytd_last_year = item.profit_loss.ytd_last_year == ''? 0 : Number(item.profit_loss.ytd_last_year)
                                let persenYtdMB = 0
                                if (ytd_mb  < 0) {
                                    if (ytd_actual >= ytd_mb) {
Riri Novita's avatar
Riri Novita committed
1829
                                        persenYtdMB = (ytd_mb - ytd_actual) / ytd_mb + 1  
Riri Novita's avatar
Riri Novita committed
1830
                                    }  else {
Riri Novita's avatar
Riri Novita committed
1831
                                        persenYtdMB = (ytd_mb - ytd_actual) / ytd_mb 
Riri Novita's avatar
Riri Novita committed
1832 1833 1834
                                    }
                                }
                                else {
Riri Novita's avatar
Riri Novita committed
1835
                                    persenYtdMB = ytd_actual / ytd_mb 
Riri Novita's avatar
Riri Novita committed
1836 1837 1838 1839 1840
                                }

                                let persenYtdLY = 0
                                if (ytd_last_year  < 0) {
                                    if (ytd_actual >= ytd_last_year) {
Riri Novita's avatar
Riri Novita committed
1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856
                                        persenYtdLY = (ytd_last_year - ytd_actual) / ytd_last_year + 1  
                                    }  else {
                                        persenYtdLY = (ytd_last_year - ytd_actual) / ytd_last_year 
                                    }
                                }
                                else {
                                    persenYtdLY = ytd_actual / ytd_last_year 
                                }

                                let q1_actual = item.profit_loss.q1_actual == ''? 0 : Number(item.profit_loss.q1_actual)
                                let q1_mb = item.profit_loss.q1_mb == ''? 0 : Number(item.profit_loss.q1_mb)
                                let q1_last_year = item.profit_loss.q1_last_year == ''? 0 : Number(item.profit_loss.q1_last_year)
                                let persenQuarterMB = 0
                                if (q1_mb  < 0) {
                                    if (q1_actual >= q1_mb) {
                                        persenQuarterMB = (q1_mb - q1_actual) / q1_mb + 1  
Riri Novita's avatar
Riri Novita committed
1857
                                    }  else {
Riri Novita's avatar
Riri Novita committed
1858
                                        persenQuarterMB = (q1_mb - q1_actual) / q1_mb 
Riri Novita's avatar
Riri Novita committed
1859 1860 1861
                                    }
                                }
                                else {
Riri Novita's avatar
Riri Novita committed
1862
                                    persenQuarterMB = q1_actual / q1_mb 
Riri Novita's avatar
Riri Novita committed
1863
                                }
Riri Novita's avatar
Riri Novita committed
1864

Riri Novita's avatar
Riri Novita committed
1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915
                                let persenQuarterLY = 0
                                if (q1_last_year  < 0) {
                                    if (q1_actual >= q1_last_year) {
                                        persenQuarterLY = (q1_last_year - q1_actual) / q1_last_year + 1  
                                    }  else {
                                        persenQuarterLY = (q1_last_year - q1_actual) / q1_last_year 
                                    }
                                }
                                else {
                                    persenQuarterLY = q1_actual / q1_last_year 
                                }

                                let fy_actual = item.profit_loss.fy_actual == ''? 0 : Number(item.profit_loss.fy_actual)
                                let fy_mb = item.profit_loss.fy_mb == ''? 0 : Number(item.profit_loss.fy_mb)
                                let fy_ol = item.profit_loss.fy_ol == ''? 0 : Number(item.profit_loss.fy_ol)
                                let fy_last_year = item.profit_loss.fy_last_year == ''? 0 : Number(item.profit_loss.fy_last_year)
                                let persenFyMB = 0
                                if (fy_mb  < 0) {
                                    if (fy_actual >= fy_mb) {
                                        persenFyMB = (fy_mb - fy_actual) / fy_mb + 1  
                                    }  else {
                                        persenFyMB = (fy_mb - fy_actual) / fy_mb 
                                    }
                                }
                                else {
                                    persenFyMB = fy_actual / fy_mb 
                                }

                                let persenFyOL = 0
                                if (fy_ol  < 0) {
                                    if (fy_actual >= fy_ol) {
                                        persenFyOL = (fy_ol - fy_actual) / fy_ol + 1  
                                    }  else {
                                        persenFyOL = (fy_ol - fy_actual) / fy_ol 
                                    }
                                }
                                else {
                                    persenFyOL = fy_actual / fy_ol 
                                }

                                let persenFyLY = 0
                                if (fy_last_year  < 0) {
                                    if (fy_actual >= fy_last_year) {
                                        persenFyLY = (fy_last_year - fy_actual) / fy_last_year + 1  
                                    }  else {
                                        persenFyLY = (fy_last_year - fy_actual) / fy_last_year 
                                    }
                                }
                                else {
                                    persenFyLY = fy_actual / fy_last_year 
                                }
Riri Novita's avatar
Riri Novita committed
1916

Riri Novita's avatar
Riri Novita committed
1917
                                let persenFyOLMB = Number(fy_ol/fy_mb)
Riri Novita's avatar
Riri Novita committed
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927
                                if (fy_mb  < 0) {
                                    if (fy_ol >= fy_mb) {
                                        persenFyLY = (fy_mb - fy_ol) / fy_mb + 1  
                                    }  else {
                                        persenFyLY = (fy_mb - fy_ol) / fy_mb 
                                    }
                                }
                                else {
                                    persenFyLY = fy_ol / fy_mb 
                                }
Riri Novita's avatar
Riri Novita committed
1928 1929

                                dbSumaPL.push([
Riri Novita's avatar
Riri Novita committed
1930
                                    item.type_report_id,
Riri Novita's avatar
Riri Novita committed
1931
                                    item.id,
Riri Novita's avatar
Riri Novita committed
1932 1933 1934 1935
                                    item.parent,
                                    item.formula,
                                    item.level,
                                    item.description,
Riri Novita's avatar
Riri Novita committed
1936
                                    item.profit_loss.mtd_actual,
Riri Novita's avatar
Riri Novita committed
1937 1938
                                    item.profit_loss.mtd_mb,
                                    isNaN(persenMtd) || persenMtd == 'Infinity' || persenMtd == '-Infinity'? (item.profit_loss.mtd_mb == '' || item.profit_loss.mtd_mb == 0? -0 : 0) : (item.profit_loss.mtd_mb == '' || item.profit_loss.mtd_mb == 0? persenMtd * -100 : persenMtd * 100),
Riri Novita's avatar
Riri Novita committed
1939
                                    item.profit_loss.mtd_last_year,
Riri Novita's avatar
Riri Novita committed
1940
                                    isNaN(persenMtdLY) || persenMtdLY == 'Infinity' || persenMtdLY == '-Infinity'? (item.profit_loss.mtd_last_year == '' || item.profit_loss.mtd_last_year == 0? -0 : 0) : (item.profit_loss.mtd_last_year == '' || item.profit_loss.mtd_last_year == 0? persenMtdLY * -100 : persenMtdLY * 100),
Riri Novita's avatar
Riri Novita committed
1941
                                    item.profit_loss.ytd_actual,
Riri Novita's avatar
Riri Novita committed
1942 1943
                                    item.profit_loss.ytd_mb,
                                    isNaN(persenYtdMB) || persenYtdMB == 'Infinity' || persenYtdMB == '-Infinity'? (item.profit_loss.ytd_mb == '' || item.profit_loss.ytd_mb == 0? -0 : 0) : (item.profit_loss.ytd_mb == '' || item.profit_loss.ytd_mb == 0? persenYtdMB * -100 : persenYtdMB * 100),
Riri Novita's avatar
Riri Novita committed
1944
                                    item.profit_loss.ytd_last_year,
Riri Novita's avatar
Riri Novita committed
1945 1946 1947 1948 1949 1950
                                    isNaN(persenYtdLY) || persenYtdLY == 'Infinity' || persenYtdLY == '-Infinity'? (item.profit_loss.ytd_last_year == '' || item.profit_loss.ytd_last_year == 0? -0 : 0) : (item.profit_loss.ytd_last_year == '' || item.profit_loss.ytd_last_year == 0? persenYtdLY * -100 : persenYtdLY * 100),
                                    item.profit_loss.q1_actual,
                                    item.profit_loss.q1_mb,
                                    isNaN(persenQuarterMB) || persenQuarterMB == 'Infinity' || persenQuarterMB == '-Infinity'? (item.profit_loss.q1_mb == '' || item.profit_loss.q1_mb == 0? -0 : 0) : (item.profit_loss.q1_mb == '' || item.profit_loss.q1_mb == 0? persenQuarterMB * -100 : persenQuarterMB * 100),
                                    item.profit_loss.q1_last_year,
                                    isNaN(persenQuarterLY) || persenQuarterLY == 'Infinity' || persenQuarterLY == '-Infinity'? (item.profit_loss.q1_last_year == '' || item.profit_loss.q1_last_year == 0? -0 : 0) : (item.profit_loss.q1_last_year == '' || item.profit_loss.q1_last_year == 0? persenQuarterLY * -100 : persenQuarterLY * 100),
Riri Novita's avatar
Riri Novita committed
1951
                                    item.profit_loss.fy_actual,
Riri Novita's avatar
Riri Novita committed
1952 1953 1954 1955
                                    item.profit_loss.fy_mb,
                                    isNaN(persenFyMB) || persenFyMB == 'Infinity' || persenFyMB == '-Infinity'? (item.profit_loss.fy_mb == '' || item.profit_loss.fy_mb == 0? -0 : 0) : (item.profit_loss.fy_mb == '' || item.profit_loss.fy_mb == 0? persenFyMB * -100 : persenFyMB * 100),
                                    item.profit_loss.fy_ol,
                                    isNaN(persenFyOL) || persenFyOL == 'Infinity' || persenFyOL == '-Infinity'? (item.profit_loss.fy_ol == '' || item.profit_loss.fy_ol == 0? -0 : 0) : (item.profit_loss.fy_ol == '' || item.profit_loss.fy_ol == 0? persenFyOL * -100 : persenFyOL * 100),
Riri Novita's avatar
Riri Novita committed
1956
                                    item.profit_loss.fy_last_year,
Riri Novita's avatar
Riri Novita committed
1957 1958 1959
                                    isNaN(persenFyLY) || persenFyLY == 'Infinity' || persenFyLY == '-Infinity'? (item.profit_loss.fy_last_year == '' || item.profit_loss.fy_last_year == 0? -0 : 0) : (item.profit_loss.fy_last_year == '' || item.profit_loss.fy_last_year == 0? persenFyLY * -100 : persenFyLY * 100),
                                    isNaN(persenFyOLMB) || persenFyOLMB == 'Infinity' || persenFyOLMB == '-Infinity'? (item.profit_loss.fy_percent_ach_ol_to_mb == '' || item.profit_loss.fy_percent_ach_ol_to_mb == 0? -0 : 0) : (item.profit_loss.fy_percent_ach_ol_to_mb == '' || item.profit_loss.fy_percent_ach_ol_to_mb == 0? persenFyOLMB * -100 : persenFyOLMB * 100),
                                    item.profit_loss.forecast_next_year,
Riri Novita's avatar
Riri Novita committed
1960 1961
                                    item.profit_loss.forecast_more_year,
                                    item.profit_loss.notes,
Riri Novita's avatar
Riri Novita committed
1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
                        res.map((item,index) => {
Riri Novita's avatar
Riri Novita committed
1973 1974
                            let mtd_actual = item.profit_loss.mtd_actual == ''? 0 : Number(item.profit_loss.mtd_actual)
                            let mtd_mb = item.profit_loss.mtd_mb == ''? 0 : Number(item.profit_loss.mtd_mb)
Riri Novita's avatar
Riri Novita committed
1975
                            let mtd_last_year = item.profit_loss.mtd_last_year == ''? 0 : Number(item.profit_loss.mtd_last_year)
Riri Novita's avatar
Riri Novita committed
1976 1977 1978
                            let persenMtd = 0
                            if (mtd_mb  < 0) {
                                if (mtd_actual >= mtd_mb) {
Riri Novita's avatar
Riri Novita committed
1979
                                    persenMtd = (mtd_mb - mtd_actual) / mtd_mb + 1  
Riri Novita's avatar
Riri Novita committed
1980
                                }  else {
Riri Novita's avatar
Riri Novita committed
1981
                                    persenMtd = (mtd_mb - mtd_actual) / mtd_mb 
Riri Novita's avatar
Riri Novita committed
1982 1983
                                }
                            }
Riri Novita's avatar
Riri Novita committed
1984 1985
                            else {
                                persenMtd = mtd_actual / mtd_mb
Riri Novita's avatar
Riri Novita committed
1986
                            }
Riri Novita's avatar
Riri Novita committed
1987

Riri Novita's avatar
Riri Novita committed
1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026
                            let persenMtdLY = 0
                            if (mtd_last_year  < 0) {
                                if (mtd_actual >= mtd_last_year) {
                                    persenMtdLY = (mtd_last_year - mtd_actual) / mtd_last_year + 1 
                                }  else {
                                    persenMtdLY = (mtd_last_year - mtd_actual) / mtd_last_year
                                }
                            }
                            else {
                                persenMtdLY = mtd_actual/mtd_last_year
                            }


                            let ytd_actual = item.profit_loss.ytd_actual == ''? 0 : Number(item.profit_loss.ytd_actual)
                            let ytd_mb = item.profit_loss.ytd_mb == ''? 0 : Number(item.profit_loss.ytd_mb)
                            let ytd_last_year = item.profit_loss.ytd_last_year == ''? 0 : Number(item.profit_loss.ytd_last_year)
                            let persenYtdMB = 0
                            if (ytd_mb  < 0) {
                                if (ytd_actual >= ytd_mb) {
                                    persenYtdMB = (ytd_mb - ytd_actual) / ytd_mb + 1  
                                }  else {
                                    persenYtdMB = (ytd_mb - ytd_actual) / ytd_mb 
                                }
                            }
                            else {
                                persenYtdMB = ytd_actual / ytd_mb 
                            }

                            let persenYtdLY = 0
                            if (ytd_last_year  < 0) {
                                if (ytd_actual >= ytd_last_year) {
                                    persenYtdLY = (ytd_last_year - ytd_actual) / ytd_last_year + 1  
                                }  else {
                                    persenYtdLY = (ytd_last_year - ytd_actual) / ytd_last_year 
                                }
                            }
                            else {
                                persenYtdLY = ytd_actual / ytd_last_year 
                            }
Riri Novita's avatar
Riri Novita committed
2027

Riri Novita's avatar
Riri Novita committed
2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093
                            let q1_actual = item.profit_loss.q1_actual == ''? 0 : Number(item.profit_loss.q1_actual)
                            let q1_mb = item.profit_loss.q1_mb == ''? 0 : Number(item.profit_loss.q1_mb)
                            let q1_last_year = item.profit_loss.q1_last_year == ''? 0 : Number(item.profit_loss.q1_last_year)
                            let persenQuarterMB = 0
                            if (q1_mb  < 0) {
                                if (q1_actual >= q1_mb) {
                                    persenQuarterMB = (q1_mb - q1_actual) / q1_mb + 1  
                                }  else {
                                    persenQuarterMB = (q1_mb - q1_actual) / q1_mb 
                                }
                            }
                            else {
                                persenQuarterMB = q1_actual / q1_mb 
                            }

                            let persenQuarterLY = 0
                            if (q1_last_year  < 0) {
                                if (q1_actual >= q1_last_year) {
                                    persenQuarterLY = (q1_last_year - q1_actual) / q1_last_year + 1  
                                }  else {
                                    persenQuarterLY = (q1_last_year - q1_actual) / q1_last_year 
                                }
                            }
                            else {
                                persenQuarterLY = q1_actual / q1_last_year 
                            }

                            let fy_actual = item.profit_loss.fy_actual == ''? 0 : Number(item.profit_loss.fy_actual)
                            let fy_mb = item.profit_loss.fy_mb == ''? 0 : Number(item.profit_loss.fy_mb)
                            let fy_ol = item.profit_loss.fy_ol == ''? 0 : Number(item.profit_loss.fy_ol)
                            let fy_last_year = item.profit_loss.fy_last_year == ''? 0 : Number(item.profit_loss.fy_last_year)
                            let persenFyMB = 0
                            if (fy_mb  < 0) {
                                if (fy_actual >= fy_mb) {
                                    persenFyMB = (fy_mb - fy_actual) / fy_mb + 1  
                                }  else {
                                    persenFyMB = (fy_mb - fy_actual) / fy_mb 
                                }
                            }
                            else {
                                persenFyMB = fy_actual / fy_mb 
                            }

                            let persenFyOL = 0
                            if (fy_ol  < 0) {
                                if (fy_actual >= fy_ol) {
                                    persenFyOL = (fy_ol - fy_actual) / fy_ol + 1  
                                }  else {
                                    persenFyOL = (fy_ol - fy_actual) / fy_ol 
                                }
                            }
                            else {
                                persenFyOL = fy_actual / fy_ol 
                            }

                            let persenFyLY = 0
                            if (fy_last_year  < 0) {
                                if (fy_actual >= fy_last_year) {
                                    persenFyLY = (fy_last_year - fy_actual) / fy_last_year + 1  
                                }  else {
                                    persenFyLY = (fy_last_year - fy_actual) / fy_last_year 
                                }
                            }
                            else {
                                persenFyLY = fy_actual / fy_last_year 
                            }
Riri Novita's avatar
Riri Novita committed
2094

Riri Novita's avatar
Riri Novita committed
2095
                            let persenFyOLMB = Number(fy_ol/fy_mb)
Riri Novita's avatar
Riri Novita committed
2096 2097 2098 2099 2100 2101 2102 2103 2104 2105
                            if (fy_mb  < 0) {
                                if (fy_ol >= fy_mb) {
                                    persenFyLY = (fy_mb - fy_ol) / fy_mb + 1  
                                }  else {
                                    persenFyLY = (fy_mb - fy_ol) / fy_mb 
                                }
                            }
                            else {
                                persenFyLY = fy_ol / fy_mb 
                            }
Riri Novita's avatar
Riri Novita committed
2106 2107

                            dbSumaPL.push([
Riri Novita's avatar
Riri Novita committed
2108
                                item.type_report_id,
Riri Novita's avatar
Riri Novita committed
2109
                                item.id,
Riri Novita's avatar
Riri Novita committed
2110 2111 2112 2113
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
Riri Novita's avatar
Riri Novita committed
2114
                                item.profit_loss.mtd_actual,
Riri Novita's avatar
Riri Novita committed
2115
                                item.profit_loss.mtd_mb,
Riri Novita's avatar
Riri Novita committed
2116
                                isNaN(persenMtd) || persenMtd == 'Infinity' || persenMtd == '-Infinity'? (item.profit_loss.mtd_mb == '' || item.profit_loss.mtd_mb == 0? -0 : 0) : (item.profit_loss.mtd_mb == '' || item.profit_loss.mtd_mb == 0? persenMtd * -100 : persenMtd * 100),
Riri Novita's avatar
Riri Novita committed
2117
                                item.profit_loss.mtd_last_year,
Riri Novita's avatar
Riri Novita committed
2118
                                isNaN(persenMtdLY) || persenMtdLY == 'Infinity' || persenMtdLY == '-Infinity'? (item.profit_loss.mtd_last_year == '' || item.profit_loss.mtd_last_year == 0? -0 : 0) : (item.profit_loss.mtd_last_year == '' || item.profit_loss.mtd_last_year == 0? persenMtdLY * -100 : persenMtdLY * 100),
Riri Novita's avatar
Riri Novita committed
2119
                                item.profit_loss.ytd_actual,
Riri Novita's avatar
Riri Novita committed
2120 2121
                                item.profit_loss.ytd_mb,
                                isNaN(persenYtdMB) || persenYtdMB == 'Infinity' || persenYtdMB == '-Infinity'? (item.profit_loss.ytd_mb == '' || item.profit_loss.ytd_mb == 0? -0 : 0) : (item.profit_loss.ytd_mb == '' || item.profit_loss.ytd_mb == 0? persenYtdMB * -100 : persenYtdMB * 100),
Riri Novita's avatar
Riri Novita committed
2122
                                item.profit_loss.ytd_last_year,
Riri Novita's avatar
Riri Novita committed
2123 2124 2125 2126 2127 2128
                                isNaN(persenYtdLY) || persenYtdLY == 'Infinity' || persenYtdLY == '-Infinity'? (item.profit_loss.ytd_last_year == '' || item.profit_loss.ytd_last_year == 0? -0 : 0) : (item.profit_loss.ytd_last_year == '' || item.profit_loss.ytd_last_year == 0? persenYtdLY * -100 : persenYtdLY * 100),
                                item.profit_loss.q1_actual,
                                item.profit_loss.q1_mb,
                                isNaN(persenQuarterMB) || persenQuarterMB == 'Infinity' || persenQuarterMB == '-Infinity'? (item.profit_loss.q1_mb == '' || item.profit_loss.q1_mb == 0? -0 : 0) : (item.profit_loss.q1_mb == '' || item.profit_loss.q1_mb == 0? persenQuarterMB * -100 : persenQuarterMB * 100),
                                item.profit_loss.q1_last_year,
                                isNaN(persenQuarterLY) || persenQuarterLY == 'Infinity' || persenQuarterLY == '-Infinity'? (item.profit_loss.q1_last_year == '' || item.profit_loss.q1_last_year == 0? -0 : 0) : (item.profit_loss.q1_last_year == '' || item.profit_loss.q1_last_year == 0? persenQuarterLY * -100 : persenQuarterLY * 100),
Riri Novita's avatar
Riri Novita committed
2129
                                item.profit_loss.fy_actual,
Riri Novita's avatar
Riri Novita committed
2130 2131 2132 2133
                                item.profit_loss.fy_mb,
                                isNaN(persenFyMB) || persenFyMB == 'Infinity' || persenFyMB == '-Infinity'? (item.profit_loss.fy_mb == '' || item.profit_loss.fy_mb == 0? -0 : 0) : (item.profit_loss.fy_mb == '' || item.profit_loss.fy_mb == 0? persenFyMB * -100 : persenFyMB * 100),
                                item.profit_loss.fy_ol,
                                isNaN(persenFyOL) || persenFyOL == 'Infinity' || persenFyOL == '-Infinity'? (item.profit_loss.fy_ol == '' || item.profit_loss.fy_ol == 0? -0 : 0) : (item.profit_loss.fy_ol == '' || item.profit_loss.fy_ol == 0? persenFyOL * -100 : persenFyOL * 100),
Riri Novita's avatar
Riri Novita committed
2134
                                item.profit_loss.fy_last_year,
Riri Novita's avatar
Riri Novita committed
2135 2136
                                isNaN(persenFyLY) || persenFyLY == 'Infinity' || persenFyLY == '-Infinity'? (item.profit_loss.fy_last_year == '' || item.profit_loss.fy_last_year == 0? -0 : 0) : (item.profit_loss.fy_last_year == '' || item.profit_loss.fy_last_year == 0? persenFyLY * -100 : persenFyLY * 100),
                                isNaN(persenFyOLMB) || persenFyOLMB == 'Infinity' || persenFyOLMB == '-Infinity'? (item.profit_loss.fy_percent_ach_ol_to_mb == '' || item.profit_loss.fy_percent_ach_ol_to_mb == 0? -0 : 0) : (item.profit_loss.fy_percent_ach_ol_to_mb == '' || item.profit_loss.fy_percent_ach_ol_to_mb == 0? persenFyOLMB * -100 : persenFyOLMB * 100),
Riri Novita's avatar
Riri Novita committed
2137 2138 2139
                                item.profit_loss.forecast_next_year,
                                item.profit_loss.forecast_more_year,
                                item.profit_loss.notes,
Riri Novita's avatar
Riri Novita committed
2140 2141 2142 2143 2144 2145 2146
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
Riri Novita's avatar
Riri Novita committed
2147
                            } 
Riri Novita's avatar
Riri Novita committed
2148
                        })
Riri Novita's avatar
Riri Novita committed
2149
                        this.setState({ dataTable: dbSumaPL, loading: false, previewTable: true, previewDownload: true })
Riri Novita's avatar
Riri Novita committed
2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162
                    } else {                            
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                            if (response.data.message.includes("Someone Logged In")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }   
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                }
Riri Novita's avatar
Riri Novita committed
2163 2164
            })
        } else if (this.state.report.value === 9) {
rifkaki's avatar
rifkaki committed
2165 2166 2167 2168 2169 2170
            let FRID = null
            let payloadFRID = {
                "periode": this.state.periode.periode,
                "company_id": this.state.company.company_id
            }
            api.create().getFRID(payloadFRID).then(response => {
rifkaki's avatar
rifkaki committed
2171
                console.log(response);
rifkaki's avatar
rifkaki committed
2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385
                if (response) {
                    FRID = response.data.data == null ? null : response.data.data.ratio_id 
                } else {
                    FRID = null
                }
                this.setState({ FRID }, () => {
                    let paylodFR = { ...payload, report_id: 29, submission_id: this.state.FRID, months: this.state.month.month_id, quarter: 0 }
                    api.create().getReportFRSuma(paylodFR).then(response => {
                        console.log(paylodFR);
                        console.log(response);
                        // console.log(JSON.stringify(response));
                        let dataTable = []
                        if (response.data) {
                            if (response.data.status === 'success') {
                                let res = response.data.data
                                const handlePushChild = (item) => {
                                    let indexIDzz = dataTable.findIndex((val) => val[1] === item.id)
                                    if (indexIDzz === -1) {
                                        let mtd_actual = item.ratio.mtd_actual == '' ? 0 : Number(item.ratio.mtd_actual)
                                        let mtd_mb = item.ratio.mtd_mb == '' ? 0 : Number(item.ratio.mtd_mb)
                                        let mtdPersenMB = 0
                                        if (mtd_mb < 0) {
                                            if (mtd_actual >= mtd_mb) {
                                                mtdPersenMB = ((mtd_mb - mtd_actual) / mtd_mb + 1 ) 
                                            }  else {
                                                mtdPersenMB = ((mtd_mb - mtd_actual) / mtd_mb) 
                                            }
                                        }
                                        else {
                                            mtdPersenMB = Number(mtd_actual / mtd_mb) 
                                        }

                                        let fy_actual = item.ratio.fy_actual == '' ? 0 : Number(item.ratio.fy_actual)
                                        let fy_mb = item.ratio.fy_mb == '' ? 0 : Number(item.ratio.fy_mb)
                                        let fyPersenMB = 0
                                        if (fy_mb < 0) {
                                            if (fy_actual >= fy_mb) {
                                                fyPersenMB = ((fy_mb - fy_actual) / fy_mb + 1 ) 
                                            }  else {
                                                fyPersenMB = ((fy_mb - fy_actual) / fy_mb) 
                                            }
                                        }
                                        else {
                                            fyPersenMB = Number(fy_actual / fy_mb) 
                                        }

                                        // let fy_actual = item.ratio.fy_actual == '' ? 0 : Number(item.ratio.fy_actual)
                                        let fy_ol = item.ratio.fy_ol == '' ? 0 : Number(item.ratio.fy_ol)
                                        let fyPersenOL = 0
                                        if (fy_ol < 0) {
                                            if (fy_actual >= fy_ol) {
                                                fyPersenOL = ((fy_ol - fy_actual) / fy_ol + 1 ) 
                                            }  else {
                                                fyPersenOL = ((fy_ol - fy_actual) / fy_ol) 
                                            }
                                        }
                                        else {
                                            fyPersenOL = Number(fy_actual / fy_ol) 
                                        }

                                        // let fy_actual = item.ratio.fy_actual == '' ? 0 : Number(item.ratio.fy_actual)
                                        let fy_last_year = item.ratio.fy_last_year == '' ? 0 : Number(item.ratio.fy_last_year)
                                        let fyPersenLY = 0
                                        if (fy_last_year < 0) {
                                            if (fy_actual >= fy_last_year) {
                                                fyPersenLY = ((fy_last_year - fy_actual) / fy_last_year + 1 ) 
                                            }  else {
                                                fyPersenLY = ((fy_last_year - fy_actual) / fy_last_year) 
                                            }
                                        }
                                        else {
                                            fyPersenLY = Number(fy_actual / fy_last_year) 
                                        }

                                        dataTable.push([
                                            item.type_report_id,
                                            item.id,
                                            item.parent,
                                            item.formula,
                                            item.level,
                                            item.description,
                                            item.uom,
                                            item.ratio.mtd_actual,
                                            item.ratio.mtd_mb,
                                            isNaN(mtdPersenMB) || mtdPersenMB == 'Infinity' || mtdPersenMB == '-Infinity' ? (item.ratio.mtd_mb == '' || item.ratio.mtd_mb == 0 ? -0 : 0) : (item.ratio.mtd_mb == '' || item.ratio.mtd_mb == 0 ? mtdPersenMB * -100 : mtdPersenMB * 100),
                                            item.ratio.mtd_last_year,
                                            item.ratio.fy_actual,
                                            item.ratio.fy_mb,
                                            isNaN(fyPersenMB) || fyPersenMB == 'Infinity' || fyPersenMB == '-Infinity' ? (item.ratio.fy_mb == '' || item.ratio.fy_mb == 0 ? -0 : 0) : (item.ratio.fy_mb == '' || item.ratio.fy_mb == 0 ? fyPersenMB * -100 : fyPersenMB * 100),
                                            item.ratio.fy_ol,
                                            isNaN(fyPersenOL) || fyPersenOL == 'Infinity' || fyPersenOL == '-Infinity' ? (item.ratio.fy_ol == '' || item.ratio.fy_ol == 0 ? -0 : 0) : (item.ratio.fy_ol == '' || item.ratio.fy_ol == 0 ? fyPersenOL * -100 : fyPersenOL * 100),
                                            item.ratio.fy_last_year,
                                            isNaN(fyPersenLY) || fyPersenLY == 'Infinity' || fyPersenLY == '-Infinity' ? (item.ratio.fy_last_year == '' || item.ratio.fy_last_year == 0 ? -0 : 0) : (item.ratio.fy_last_year == '' || item.ratio.fy_last_year == 0 ? fyPersenLY * -100 : fyPersenLY * 100),
                                            item.ratio.forecast_next_year,
                                            item.ratio.forecast_more_year
                                        ])
                                    }
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
                                    }
                                }
                                res.map((item, index) => {
                                    let mtd_actual = item.ratio.mtd_actual == '' ? 0 : Number(item.ratio.mtd_actual)
                                    let mtd_mb = item.ratio.mtd_mb == '' ? 0 : Number(item.ratio.mtd_mb)
                                    let mtdPersenMB = 0
                                    if (mtd_mb < 0) {
                                        if (mtd_actual >= mtd_mb) {
                                            mtdPersenMB = ((mtd_mb - mtd_actual) / mtd_mb + 1 ) 
                                        }  else {
                                            mtdPersenMB = ((mtd_mb - mtd_actual) / mtd_mb) 
                                        }
                                    }
                                    else {
                                        mtdPersenMB = Number(mtd_actual / mtd_mb) 
                                    }

                                    let fy_actual = item.ratio.fy_actual == '' ? 0 : Number(item.ratio.fy_actual)
                                    let fy_mb = item.ratio.fy_mb == '' ? 0 : Number(item.ratio.fy_mb)
                                    let fyPersenMB = 0
                                    if (fy_mb < 0) {
                                        if (fy_actual >= fy_mb) {
                                            fyPersenMB = ((fy_mb - fy_actual) / fy_mb + 1 ) 
                                        }  else {
                                            fyPersenMB = ((fy_mb - fy_actual) / fy_mb) 
                                        }
                                    }
                                    else {
                                        fyPersenMB = Number(fy_actual / fy_mb) 
                                    }

                                    // let fy_actual = item.ratio.fy_actual == '' ? 0 : Number(item.ratio.fy_actual)
                                    let fy_ol = item.ratio.fy_ol == '' ? 0 : Number(item.ratio.fy_ol)
                                    let fyPersenOL = 0
                                    if (fy_ol < 0) {
                                        if (fy_actual >= fy_ol) {
                                            fyPersenOL = ((fy_ol - fy_actual) / fy_ol + 1 ) 
                                        }  else {
                                            fyPersenOL = ((fy_ol - fy_actual) / fy_ol) 
                                        }
                                    }
                                    else {
                                        fyPersenOL = Number(fy_actual / fy_ol) 
                                    }

                                    // let fy_actual = item.ratio.fy_actual == '' ? 0 : Number(item.ratio.fy_actual)
                                    let fy_last_year = item.ratio.fy_last_year == '' ? 0 : Number(item.ratio.fy_last_year)
                                    let fyPersenLY = 0
                                    if (fy_last_year < 0) {
                                        if (fy_actual >= fy_last_year) {
                                            fyPersenLY = ((fy_last_year - fy_actual) / fy_last_year + 1 ) 
                                        }  else {
                                            fyPersenLY = ((fy_last_year - fy_actual) / fy_last_year) 
                                        }
                                    }
                                    else {
                                        fyPersenLY = Number(fy_actual / fy_last_year) 
                                    }

                                    dataTable.push([
                                        item.type_report_id,
                                        item.id,
                                        item.parent,
                                        item.formula,
                                        item.level,
                                        item.description,
                                        item.uom,
                                        item.ratio.mtd_actual,
                                        item.ratio.mtd_mb,
                                        isNaN(mtdPersenMB) || mtdPersenMB == 'Infinity' || mtdPersenMB == '-Infinity' ? (item.ratio.mtd_mb == '' || item.ratio.mtd_mb == 0 ? -0 : 0) : (item.ratio.mtd_mb == '' || item.ratio.mtd_mb == 0 ? mtdPersenMB * -100 : mtdPersenMB * 100),
                                        item.ratio.mtd_last_year,
                                        item.ratio.fy_actual,
                                        item.ratio.fy_mb,
                                        isNaN(fyPersenMB) || fyPersenMB == 'Infinity' || fyPersenMB == '-Infinity' ? (item.ratio.fy_mb == '' || item.ratio.fy_mb == 0 ? -0 : 0) : (item.ratio.fy_mb == '' || item.ratio.fy_mb == 0 ? fyPersenMB * -100 : fyPersenMB * 100),
                                        item.ratio.fy_ol,
                                        isNaN(fyPersenOL) || fyPersenOL == 'Infinity' || fyPersenOL == '-Infinity' ? (item.ratio.fy_ol == '' || item.ratio.fy_ol == 0 ? -0 : 0) : (item.ratio.fy_ol == '' || item.ratio.fy_ol == 0 ? fyPersenOL * -100 : fyPersenOL * 100),
                                        item.ratio.fy_last_year,
                                        isNaN(fyPersenLY) || fyPersenLY == 'Infinity' || fyPersenLY == '-Infinity' ? (item.ratio.fy_last_year == '' || item.ratio.fy_last_year == 0 ? -0 : 0) : (item.ratio.fy_last_year == '' || item.ratio.fy_last_year == 0 ? fyPersenLY * -100 : fyPersenLY * 100),
                                        item.ratio.forecast_next_year,
                                        item.ratio.forecast_more_year
                                    ])
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
                                    }
                                })
                                this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                                console.log(this.state.dataTable)
                                // this.setState({ dataTable }, () => {
                                //     console.log(this.state.dataTable)
                                //     this.getRatioMR(payload)
                                // })
                            } else {
                                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                                    if (response.data.message.includes("Someone Logged In")) {
                                        setTimeout(() => {
                                            localStorage.removeItem(Constant.TOKEN)
                                            window.location.reload();
                                        }, 1000);
                                    }
                                })
                            }
                        } else {
                            this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                        }
                        // this.setState({ previewTable: true, loading: false, previewDownload: true })
                    })
                })
Riri Novita's avatar
Riri Novita committed
2386
            })
faisalhamdi's avatar
faisalhamdi committed
2387 2388 2389 2390 2391 2392 2393 2394 2395 2396
        } else if (this.state.report.value === 10) {
            let dbCatPQ = [
                ["ABCD", "%", "Rp Bio", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"]
            ]
            this.setState({ dataTable: dbCatPQ, previewTable: true, loading: false, previewDownload: true })
        } else if (this.state.report.value === 11) {
            let dbCatPA = [
                ["ABCD", "%", "Rp Bio", "HIG", "Unlimited", "SUM", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"]
            ]
            this.setState({ dataTable: dbCatPA, previewTable: true, loading: false, previewDownload: true })
d.arizona's avatar
d.arizona committed
2397
        }
Riri Novita's avatar
Riri Novita committed
2398

d.arizona's avatar
d.arizona committed
2399 2400
    }

d.arizona's avatar
d.arizona committed
2401
    getCFSumaMR(payload, dbSumaCF) {
d.arizona's avatar
d.arizona committed
2402
        let payloadLast = { ...payload, "periode": Number(this.state.periode.periode) - 1 }
d.arizona's avatar
d.arizona committed
2403 2404 2405 2406 2407 2408 2409 2410
        // let payloadLast = {
        //     "report_id": this.state.report.value,
        //     "revision": this.state.revisionType,
        //     "periode": Number(this.state.periode.periode) -1,
        //     "months" : this.state.
        //     "company_id": this.state.company.company_id,
        //     "submission_id": this.state.submissionID
        // }
d.arizona's avatar
d.arizona committed
2411 2412 2413 2414 2415 2416 2417
        api.create().getReportCFSumaMR(payload).then(response => {
            console.log(payload);
            console.log(response);
            let dataTable = this.state.dataTable
            let dataTable2 = []
            if (response.data) {
                let res = response.data.data
d.arizona's avatar
d.arizona committed
2418
                res.map((item, index) => {
d.arizona's avatar
d.arizona committed
2419 2420 2421 2422 2423 2424 2425
                    let indexID = dataTable.findIndex((val) => val[1] == item.id)
                    if (indexID != -1) {
                        const handlePushChild = (items) => {
                            let indexIDzz = dataTable.findIndex((val) => val[1] === items.id)
                            // console.log(indexIDzz)
                            if (indexIDzz != -1) {
                                dataTable2.push([...dataTable[indexIDzz],
d.arizona's avatar
d.arizona committed
2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437
                                items.cash_flow.january,
                                items.cash_flow.february,
                                items.cash_flow.march,
                                items.cash_flow.april,
                                items.cash_flow.may,
                                items.cash_flow.june,
                                items.cash_flow.july,
                                items.cash_flow.august,
                                items.cash_flow.september,
                                items.cash_flow.october,
                                items.cash_flow.november,
                                items.cash_flow.december,
d.arizona's avatar
d.arizona committed
2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449
                                ])
                            }
                            if (items.children !== null) {
                                if (items.children.length > 0) {
                                    items.children.map((itemss, indexss) => {
                                        handlePushChild(itemss)
                                    })
                                }
                            }
                        }

                        dataTable2.push([...dataTable[indexID],
d.arizona's avatar
d.arizona committed
2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461
                        item.cash_flow.january,
                        item.cash_flow.february,
                        item.cash_flow.march,
                        item.cash_flow.april,
                        item.cash_flow.may,
                        item.cash_flow.june,
                        item.cash_flow.july,
                        item.cash_flow.august,
                        item.cash_flow.september,
                        item.cash_flow.october,
                        item.cash_flow.november,
                        item.cash_flow.december,
d.arizona's avatar
d.arizona committed
2462 2463 2464 2465 2466 2467 2468 2469 2470
                        ])

                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
d.arizona's avatar
d.arizona committed
2471

d.arizona's avatar
d.arizona committed
2472
                    }
d.arizona's avatar
d.arizona committed
2473

d.arizona's avatar
d.arizona committed
2474 2475 2476
                })
                this.setState({ dataTable2 }, () => {
                    // console.log(this.state.dataTable2)
d.arizona's avatar
d.arizona committed
2477
                    this.getCFSumaLastMR(payloadLast, dbSumaCF)
d.arizona's avatar
d.arizona committed
2478 2479 2480 2481 2482 2483 2484 2485 2486
                })
                console.log(dataTable2)
                // this.setState({ dataTable: dataTable2, previewTable: true, loading: false, previewDownload: false })
            } else {
                this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
            }
        })
    }

d.arizona's avatar
d.arizona committed
2487
    getCFSumaLastMR(payload, dbSumaCF) {
rifkaki's avatar
rifkaki committed
2488 2489
        console.log(dbSumaCF)
        console.log(this.state.dbSumaCF)
d.arizona's avatar
d.arizona committed
2490 2491 2492 2493 2494 2495 2496
        api.create().getReportCFSumaMR(payload).then(response => {
            console.log(payload);
            console.log(response);
            let dataTable2 = this.state.dataTable2
            let dataTable3 = []
            if (response.data) {
                let res = response.data.data
d.arizona's avatar
d.arizona committed
2497
                res.map((item, index) => {
d.arizona's avatar
d.arizona committed
2498
                    let indexID = dataTable2.findIndex((val) => val[1] == item.id)
d.arizona's avatar
d.arizona committed
2499
                    let indexIDSuma = dbSumaCF.findIndex((val) => val[0] == item.id)
d.arizona's avatar
d.arizona committed
2500 2501 2502
                    if (indexID != -1) {
                        const handlePushChild = (items) => {
                            let indexIDzz = dataTable2.findIndex((val) => val[1] === items.id)
rifkaki's avatar
rifkaki committed
2503
                            let indexIDSumaChild = dbSumaCF.findIndex((val) => val[0] == items.id)
d.arizona's avatar
d.arizona committed
2504 2505 2506
                            // console.log(indexIDzz)
                            if (indexIDzz != -1) {
                                dataTable3.push([...dataTable2[indexIDzz],
d.arizona's avatar
d.arizona committed
2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518
                                items.cash_flow.january,
                                items.cash_flow.february,
                                items.cash_flow.march,
                                items.cash_flow.april,
                                items.cash_flow.may,
                                items.cash_flow.june,
                                items.cash_flow.july,
                                items.cash_flow.august,
                                items.cash_flow.september,
                                items.cash_flow.october,
                                items.cash_flow.november,
                                items.cash_flow.december,
rifkaki's avatar
rifkaki committed
2519
                                ...dbSumaCF[indexIDSumaChild]
d.arizona's avatar
d.arizona committed
2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531
                                ])
                            }
                            if (items.children !== null) {
                                if (items.children.length > 0) {
                                    items.children.map((itemss, indexss) => {
                                        handlePushChild(itemss)
                                    })
                                }
                            }
                        }

                        dataTable3.push([...dataTable2[indexID],
d.arizona's avatar
d.arizona committed
2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544
                        item.cash_flow.january,
                        item.cash_flow.february,
                        item.cash_flow.march,
                        item.cash_flow.april,
                        item.cash_flow.may,
                        item.cash_flow.june,
                        item.cash_flow.july,
                        item.cash_flow.august,
                        item.cash_flow.september,
                        item.cash_flow.october,
                        item.cash_flow.november,
                        item.cash_flow.december,
                        ...dbSumaCF[indexIDSuma]
d.arizona's avatar
d.arizona committed
2545 2546 2547 2548 2549 2550 2551 2552 2553
                        ])

                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
d.arizona's avatar
d.arizona committed
2554

d.arizona's avatar
d.arizona committed
2555
                    }
d.arizona's avatar
d.arizona committed
2556

d.arizona's avatar
d.arizona committed
2557
                })
rifkaki's avatar
rifkaki committed
2558
                console.log(dbSumaCF)
d.arizona's avatar
d.arizona committed
2559 2560 2561 2562 2563 2564 2565 2566
                console.log(dataTable3)
                this.setState({ dataTable: dataTable3, previewTable: true, loading: false, previewDownload: true })
            } else {
                this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
            }
        })
    }

Riri Novita's avatar
Riri Novita committed
2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581
    getReportPLMR(payload) {
        let payloadLast = {
            "report_id": this.state.report.value,
            "revision": this.state.revisionType,
            "periode": Number(this.state.periode.periode) - 1,
            "company_id": this.state.company.company_id,
            "submission_id": this.state.submissionID
        }
        api.create().getReportPLMR(payload).then(response => {
            console.log(payload);
            console.log(response);
            let dataTable = this.state.dataTable
            let dataTable2 = []
            if (response.data) {
                let res = response.data.data
d.arizona's avatar
d.arizona committed
2582
                res.map((item, index) => {
Riri Novita's avatar
Riri Novita committed
2583 2584 2585 2586 2587 2588 2589
                    let indexID = dataTable.findIndex((val) => val[1] == item.id)
                    if (indexID != -1) {
                        const handlePushChild = (items) => {
                            let indexIDzz = dataTable.findIndex((val) => val[1] === items.id)
                            // console.log(indexIDzz)
                            if (indexIDzz != -1) {
                                dataTable2.push([...dataTable[indexIDzz],
d.arizona's avatar
d.arizona committed
2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602
                                items.formula,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.january, formula: items.profit_detail.january_formula } : items.profit_detail.january,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.february, formula: items.profit_detail.february_formula } : items.profit_detail.february,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.march, formula: items.profit_detail.march_formula } : items.profit_detail.march,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.april, formula: items.profit_detail.april_formula } : items.profit_detail.april,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.may, formula: items.profit_detail.may_formula } : items.profit_detail.may,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.june, formula: items.profit_detail.june_formula } : items.profit_detail.june,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.july, formula: items.profit_detail.july_formula } : items.profit_detail.july,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.august, formula: items.profit_detail.august_formula } : items.profit_detail.august,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.september, formula: items.profit_detail.september_formula } : items.profit_detail.september,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.october, formula: items.profit_detail.october_formula } : items.profit_detail.october,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.november, formula: items.profit_detail.november_formula } : items.profit_detail.november,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.december, formula: items.profit_detail.december_formula } : items.profit_detail.december,
Riri Novita's avatar
Riri Novita committed
2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614
                                ])
                            }
                            if (items.children !== null) {
                                if (items.children.length > 0) {
                                    items.children.map((itemss, indexss) => {
                                        handlePushChild(itemss)
                                    })
                                }
                            }
                        }

                        dataTable2.push([...dataTable[indexID],
d.arizona's avatar
d.arizona committed
2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627
                        item.formula,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.january, formula: item.profit_detail.january_formula } : item.profit_detail.january,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.february, formula: item.profit_detail.february_formula } : item.profit_detail.february,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.march, formula: item.profit_detail.march_formula } : item.profit_detail.march,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.april, formula: item.profit_detail.april_formula } : item.profit_detail.april,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.may, formula: item.profit_detail.may_formula } : item.profit_detail.may,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.june, formula: item.profit_detail.june_formula } : item.profit_detail.june,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.july, formula: item.profit_detail.july_formula } : item.profit_detail.july,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.august, formula: item.profit_detail.august_formula } : item.profit_detail.august,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.september, formula: item.profit_detail.september_formula } : item.profit_detail.september,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.october, formula: item.profit_detail.october_formula } : item.profit_detail.october,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.november, formula: item.profit_detail.november_formula } : item.profit_detail.november,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.december, formula: item.profit_detail.december_formula } : item.profit_detail.december,
Riri Novita's avatar
Riri Novita committed
2628 2629 2630 2631 2632 2633 2634 2635 2636
                        ])

                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
d.arizona's avatar
d.arizona committed
2637

Riri Novita's avatar
Riri Novita committed
2638
                    }
d.arizona's avatar
d.arizona committed
2639

Riri Novita's avatar
Riri Novita committed
2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660
                })
                console.log(dataTable2)
                // this.setState({ dataTable: dataTable2, previewTable: true, loading: false, previewDownload: true })
                this.setState({ dataTable2 }, () => {
                    // console.log(this.state.dataTable2)
                    this.getProfitLossLastMR(payloadLast)
                })
            } else {
                this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
            }
        })
    }

    getProfitLossLastMR(payload) {
        api.create().getReportPLMR(payload).then(response => {
            console.log(payload);
            console.log(response);
            let dataTable2 = this.state.dataTable2
            let dataTable3 = []
            if (response.data) {
                let res = response.data.data
d.arizona's avatar
d.arizona committed
2661
                res.map((item, index) => {
Riri Novita's avatar
Riri Novita committed
2662 2663 2664 2665 2666 2667 2668
                    let indexID = dataTable2.findIndex((val) => val[1] == item.id)
                    if (indexID != -1) {
                        const handlePushChild = (items) => {
                            let indexIDzz = dataTable2.findIndex((val) => val[1] === items.id)
                            // console.log(indexIDzz)
                            if (indexIDzz != -1) {
                                dataTable3.push([...dataTable2[indexIDzz],
d.arizona's avatar
d.arizona committed
2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.january, formula: items.profit_detail.january_formula } : items.profit_detail.january,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.february, formula: items.profit_detail.february_formula } : items.profit_detail.february,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.march, formula: items.profit_detail.march_formula } : items.profit_detail.march,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.april, formula: items.profit_detail.april_formula } : items.profit_detail.april,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.may, formula: items.profit_detail.may_formula } : items.profit_detail.may,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.june, formula: items.profit_detail.june_formula } : items.profit_detail.june,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.july, formula: items.profit_detail.july_formula } : items.profit_detail.july,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.august, formula: items.profit_detail.august_formula } : items.profit_detail.august,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.september, formula: items.profit_detail.september_formula } : items.profit_detail.september,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.october, formula: items.profit_detail.october_formula } : items.profit_detail.october,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.november, formula: items.profit_detail.november_formula } : items.profit_detail.november,
                                items.type_report_id == 5 || items.type_report_id == 6 || items.type_report_id == 7 ? { value: items.profit_detail.december, formula: items.profit_detail.december_formula } : items.profit_detail.december,
Riri Novita's avatar
Riri Novita committed
2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692
                                ])
                            }
                            if (items.children !== null) {
                                if (items.children.length > 0) {
                                    items.children.map((itemss, indexss) => {
                                        handlePushChild(itemss)
                                    })
                                }
                            }
                        }

                        dataTable3.push([...dataTable2[indexID],
d.arizona's avatar
d.arizona committed
2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.january, formula: item.profit_detail.january_formula } : item.profit_detail.january,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.february, formula: item.profit_detail.february_formula } : item.profit_detail.february,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.march, formula: item.profit_detail.march_formula } : item.profit_detail.march,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.april, formula: item.profit_detail.april_formula } : item.profit_detail.april,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.may, formula: item.profit_detail.may_formula } : item.profit_detail.may,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.june, formula: item.profit_detail.june_formula } : item.profit_detail.june,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.july, formula: item.profit_detail.july_formula } : item.profit_detail.july,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.august, formula: item.profit_detail.august_formula } : item.profit_detail.august,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.september, formula: item.profit_detail.september_formula } : item.profit_detail.september,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.october, formula: item.profit_detail.october_formula } : item.profit_detail.october,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.november, formula: item.profit_detail.november_formula } : item.profit_detail.november,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.december, formula: item.profit_detail.december_formula } : item.profit_detail.december,
Riri Novita's avatar
Riri Novita committed
2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716
                        ])

                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }

                    }

d.arizona's avatar
d.arizona committed
2717 2718 2719 2720 2721 2722 2723 2724 2725
                })
                console.log(dataTable3)
                this.setState({ dataTable: dataTable3, previewTable: true, loading: false, previewDownload: true })
            } else {
                this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
            }
        })
    }

d.arizona's avatar
d.arizona committed
2726
    getRatioMR(payload) {
rifkaki's avatar
rifkaki committed
2727 2728 2729 2730 2731 2732 2733
        let payloadLast = {
            "report_id": this.state.report.value,
            "revision": this.state.revisionType,
            "periode": Number(this.state.periode.periode) - 1,
            "company_id": this.state.company.company_id,
            "submission_id": this.state.submissionID
        }
d.arizona's avatar
d.arizona committed
2734 2735 2736 2737 2738 2739 2740 2741
        api.create().getReportHierarkiFRMR(payload).then(response => {
            // console.log(payload);
            console.log(response);
            let dataTable = this.state.dataTable
            let dataTable2 = []
            if (response.data) {
                if (response.data.status === 'success') {
                    let res = response.data.data
d.arizona's avatar
d.arizona committed
2742
                    res.map((item, index) => {
d.arizona's avatar
d.arizona committed
2743 2744 2745 2746 2747 2748 2749
                        let indexID = dataTable.findIndex((val) => val[1] == item.id)
                        if (indexID != -1) {
                            const handlePushChild = (items) => {
                                let indexIDzz = dataTable.findIndex((val) => val[1] === items.id)
                                // console.log(indexIDzz)
                                if (indexIDzz != -1) {
                                    dataTable2.push([...dataTable[indexIDzz],
rifkaki's avatar
rifkaki committed
2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773
                                    // String(items.ratio.monthly_january) == "" ? "" : Number(items.ratio.monthly_january).toFixed(2),
                                    // String(items.ratio.monthly_february) == "" ? "" : Number(items.ratio.monthly_february).toFixed(2),
                                    // String(items.ratio.monthly_march) == "" ? "" : Number(items.ratio.monthly_march).toFixed(2),
                                    // String(items.ratio.monthly_april) == "" ? "" : Number(items.ratio.monthly_april).toFixed(2),
                                    // String(items.ratio.monthly_may) == "" ? "" : Number(items.ratio.monthly_may).toFixed(2),
                                    // String(items.ratio.monthly_june) == "" ? "" : Number(items.ratio.monthly_june).toFixed(2),
                                    // String(items.ratio.monthly_july) == "" ? "" : Number(items.ratio.monthly_july).toFixed(2),
                                    // String(items.ratio.monthly_august) == "" ? "" : Number(items.ratio.monthly_august).toFixed(2),
                                    // String(items.ratio.monthly_september) == "" ? "" : Number(items.ratio.monthly_september).toFixed(2),
                                    // String(items.ratio.monthly_october) == "" ? "" : Number(items.ratio.monthly_october).toFixed(2),
                                    // String(items.ratio.monthly_november) == "" ? "" : Number(items.ratio.monthly_november).toFixed(2),
                                    // String(items.ratio.monthly_december) == "" ? "" : Number(items.ratio.monthly_december).toFixed(2),
                                    items.ratio.monthly_january,
                                    items.ratio.monthly_february,
                                    items.ratio.monthly_march,
                                    items.ratio.monthly_april,
                                    items.ratio.monthly_may,
                                    items.ratio.monthly_june,
                                    items.ratio.monthly_july,
                                    items.ratio.monthly_august,
                                    items.ratio.monthly_september,
                                    items.ratio.monthly_october,
                                    items.ratio.monthly_november,
                                    items.ratio.monthly_december
d.arizona's avatar
d.arizona committed
2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785
                                    ])
                                }
                                if (items.children !== null) {
                                    if (items.children.length > 0) {
                                        items.children.map((itemss, indexss) => {
                                            handlePushChild(itemss)
                                        })
                                    }
                                }
                            }

                            dataTable2.push([...dataTable[indexID],
rifkaki's avatar
rifkaki committed
2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809
                            // String(item.ratio.monthly_january) == "" ? "" : Number(item.ratio.monthly_january).toFixed(2),
                            // String(item.ratio.monthly_february) == "" ? "" : Number(item.ratio.monthly_february).toFixed(2),
                            // String(item.ratio.monthly_march) == "" ? "" : Number(item.ratio.monthly_march).toFixed(2),
                            // String(item.ratio.monthly_april) == "" ? "" : Number(item.ratio.monthly_april).toFixed(2),
                            // String(item.ratio.monthly_may) == "" ? "" : Number(item.ratio.monthly_may).toFixed(2),
                            // String(item.ratio.monthly_june) == "" ? "" : Number(item.ratio.monthly_june).toFixed(2),
                            // String(item.ratio.monthly_july) == "" ? "" : Number(item.ratio.monthly_july).toFixed(2),
                            // String(item.ratio.monthly_august) == "" ? "" : Number(item.ratio.monthly_august).toFixed(2),
                            // String(item.ratio.monthly_september) == "" ? "" : Number(item.ratio.monthly_september).toFixed(2),
                            // String(item.ratio.monthly_october) == "" ? "" : Number(item.ratio.monthly_october).toFixed(2),
                            // String(item.ratio.monthly_november) == "" ? "" : Number(item.ratio.monthly_november).toFixed(2),
                            // String(item.ratio.monthly_december) == "" ? "" : Number(item.ratio.monthly_december).toFixed(2),
                            item.ratio.monthly_january,
                            item.ratio.monthly_february,
                            item.ratio.monthly_march,
                            item.ratio.monthly_april,
                            item.ratio.monthly_may,
                            item.ratio.monthly_june,
                            item.ratio.monthly_july,
                            item.ratio.monthly_august,
                            item.ratio.monthly_september,
                            item.ratio.monthly_october,
                            item.ratio.monthly_november,
                            item.ratio.monthly_december
d.arizona's avatar
d.arizona committed
2810 2811 2812 2813 2814 2815 2816 2817 2818
                            ])

                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
d.arizona's avatar
d.arizona committed
2819

d.arizona's avatar
d.arizona committed
2820
                        }
d.arizona's avatar
d.arizona committed
2821

d.arizona's avatar
d.arizona committed
2822 2823
                    })
                    console.log(dataTable2)
rifkaki's avatar
rifkaki committed
2824 2825 2826 2827 2828
                    // this.setState({ dataTable: dataTable2, previewTable: true, loading: false, previewDownload: true })
                    this.setState({ dataTable2 }, () => {
                        console.log(this.state.dataTable2)
                        this.getRatioLastMR(payloadLast)
                    })
d.arizona's avatar
d.arizona committed
2829
                } else {
rifkaki's avatar
rifkaki committed
2830 2831 2832 2833 2834 2835 2836 2837
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                        if (response.data.message.includes("Someone Logged In")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
d.arizona's avatar
d.arizona committed
2838
                }
rifkaki's avatar
rifkaki committed
2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
            }
        })
    }

    getRatioLastMR(payloadLast) {
        api.create().getReportHierarkiFRMR(payloadLast).then(response => {
            console.log(payloadLast);
            console.log(response);
            let dataTable2 = this.state.dataTable2
            let dataTable3 = []
            if (response.data) {
                if (response.data.status === 'success') {
                    let res = response.data.data
d.arizona's avatar
d.arizona committed
2854
                    res.map((item, index) => {
rifkaki's avatar
rifkaki committed
2855 2856 2857 2858 2859 2860 2861
                        let indexID = dataTable2.findIndex((val) => val[1] == item.id)
                        if (indexID != -1) {
                            const handlePushChild = (items) => {
                                let indexIDzz = dataTable2.findIndex((val) => val[1] === items.id)
                                // console.log(indexIDzz)
                                if (indexIDzz != -1) {
                                    dataTable3.push([...dataTable2[indexIDzz],
rifkaki's avatar
rifkaki committed
2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885
                                    // Number(items.ratio.monthly_january).toFixed(2),
                                    // Number(items.ratio.monthly_february).toFixed(2),
                                    // Number(items.ratio.monthly_march).toFixed(2),
                                    // Number(items.ratio.monthly_april).toFixed(2),
                                    // Number(items.ratio.monthly_may).toFixed(2),
                                    // Number(items.ratio.monthly_june).toFixed(2),
                                    // Number(items.ratio.monthly_july).toFixed(2),
                                    // Number(items.ratio.monthly_august).toFixed(2),
                                    // Number(items.ratio.monthly_september).toFixed(2),
                                    // Number(items.ratio.monthly_october).toFixed(2),
                                    // Number(items.ratio.monthly_november).toFixed(2),
                                    // Number(items.ratio.monthly_december).toFixed(2),
                                    items.ratio.monthly_january_last_year,
                                    items.ratio.monthly_february_last_year,
                                    items.ratio.monthly_march_last_year,
                                    items.ratio.monthly_april_last_year,
                                    items.ratio.monthly_may_last_year,
                                    items.ratio.monthly_june_last_year,
                                    items.ratio.monthly_july_last_year,
                                    items.ratio.monthly_august_last_year,
                                    items.ratio.monthly_september_last_year,
                                    items.ratio.monthly_october_last_year,
                                    items.ratio.monthly_november_last_year,
                                    items.ratio.monthly_december_last_year,
rifkaki's avatar
rifkaki committed
2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897
                                    ])
                                }
                                if (items.children !== null) {
                                    if (items.children.length > 0) {
                                        items.children.map((itemss, indexss) => {
                                            handlePushChild(itemss)
                                        })
                                    }
                                }
                            }

                            dataTable3.push([...dataTable2[indexID],
rifkaki's avatar
rifkaki committed
2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921
                            // Number(item.ratio.monthly_january).toFixed(2),
                            // Number(item.ratio.monthly_february).toFixed(2),
                            // Number(item.ratio.monthly_march).toFixed(2),
                            // Number(item.ratio.monthly_april).toFixed(2),
                            // Number(item.ratio.monthly_may).toFixed(2),
                            // Number(item.ratio.monthly_june).toFixed(2),
                            // Number(item.ratio.monthly_july).toFixed(2),
                            // Number(item.ratio.monthly_august).toFixed(2),
                            // Number(item.ratio.monthly_september).toFixed(2),
                            // Number(item.ratio.monthly_october).toFixed(2),
                            // Number(item.ratio.monthly_november).toFixed(2),
                            // Number(item.ratio.monthly_december).toFixed(2),
                            item.ratio.monthly_january_last_year,
                            item.ratio.monthly_february_last_year,
                            item.ratio.monthly_march_last_year,
                            item.ratio.monthly_april_last_year,
                            item.ratio.monthly_may_last_year,
                            item.ratio.monthly_june_last_year,
                            item.ratio.monthly_july_last_year,
                            item.ratio.monthly_august_last_year,
                            item.ratio.monthly_september_last_year,
                            item.ratio.monthly_october_last_year,
                            item.ratio.monthly_november_last_year,
                            item.ratio.monthly_december_last_year,
rifkaki's avatar
rifkaki committed
2922 2923 2924 2925 2926 2927 2928 2929 2930
                            ])

                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
d.arizona's avatar
d.arizona committed
2931

rifkaki's avatar
rifkaki committed
2932
                        }
d.arizona's avatar
d.arizona committed
2933

rifkaki's avatar
rifkaki committed
2934 2935 2936
                    })
                    console.log(dataTable3)
                    this.setState({ dataTable: dataTable3, previewTable: true, loading: false, previewDownload: true })
d.arizona's avatar
d.arizona committed
2937
                } else {
d.arizona's avatar
d.arizona committed
2938 2939 2940 2941 2942 2943 2944 2945
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                        if (response.data.message.includes("Someone Logged In")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
d.arizona's avatar
d.arizona committed
2946
                }
d.arizona's avatar
d.arizona committed
2947 2948 2949 2950 2951 2952
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
2953
    async downloadAllData() {
faisalhamdi's avatar
faisalhamdi committed
2954
        if (this.state.report.value === 1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2955
            let res = await fetch(
d.arizona's avatar
d.arizona committed
2956
                `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/db_profit_loss_detail/export_report?submission_id=${this.state.submissionID === null ? "" : this.state.submissionID}&&report_id=${this.state.report.value}&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.revisionType}`
Deni Rinaldi's avatar
Deni Rinaldi committed
2957 2958 2959 2960 2961 2962 2963
            )
            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;
Deni Rinaldi's avatar
Deni Rinaldi committed
2964
                a.download = 'Report DB Profit & Loss Detail.xlsx';
Deni Rinaldi's avatar
Deni Rinaldi committed
2965 2966
                a.click();
            }
faisalhamdi's avatar
faisalhamdi committed
2967
        } else if (this.state.report.value === 2) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2968
            let res = await fetch(
d.arizona's avatar
d.arizona committed
2969
                `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/db_balance_sheet/export_report?submission_id=${this.state.submissionID === null ? "" : this.state.submissionID}&&report_id=${this.state.report.value}&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.revisionType}`
Deni Rinaldi's avatar
Deni Rinaldi committed
2970 2971 2972 2973 2974 2975 2976
            )
            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;
Deni Rinaldi's avatar
Deni Rinaldi committed
2977
                a.download = 'Report DB Balance Sheet.xlsx';
Deni Rinaldi's avatar
Deni Rinaldi committed
2978 2979 2980 2981
                a.click();
            }
        } else if (this.state.report.value === 3) {
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
2982
                `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/db_profit_loss/export_report?submission_id=${this.state.PLID === null ? "" : this.state.PLID}&&report_id=28&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.revisionType}`
Deni Rinaldi's avatar
Deni Rinaldi committed
2983 2984 2985 2986 2987 2988 2989
            )
            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;
Deni Rinaldi's avatar
Deni Rinaldi committed
2990
                a.download = 'Report DB Profit & Loss.xlsx';
Deni Rinaldi's avatar
Deni Rinaldi committed
2991 2992
                a.click();
            }
faisalhamdi's avatar
faisalhamdi committed
2993
        } else if (this.state.report.value === 4) {
Riri Novita's avatar
Riri Novita committed
2994
            let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/db_ratio/export_report?submission_id=${this.state.FRID === null ? "" : this.state.FRID}&&report_id=29&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.revisionType}`
Deni Rinaldi's avatar
Deni Rinaldi committed
2995
            console.log(url);
faisalhamdi's avatar
faisalhamdi committed
2996
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
2997
                `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/db_ratio/export_report?submission_id=${this.state.FRID === null ? "" : this.state.FRID}&&report_id=29&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.revisionType}`
faisalhamdi's avatar
faisalhamdi committed
2998 2999 3000 3001 3002 3003 3004 3005 3006 3007
            )
            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 = 'Report DB Financial Ratio.xlsx';
                a.click();
            }
rifkaki's avatar
rifkaki committed
3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020
        } else if (this.state.report.value === 5) {
            let res = await fetch(
                `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/db_tax_planning/export_report?submission_id=${this.state.submissionID === null ? "" : this.state.submissionID}&&report_id=${this.state.report.value}&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.revisionType}`
            )
            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 = 'Report DB Tax Planning.xlsx';
                a.click();
            }
d.arizona's avatar
d.arizona committed
3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033
        } else if (this.state.report.value === 21) {
            let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/db_operating_indicator/export_report?operating_indicator_id=${this.state.OPID === null ? "" : this.state.OPID}&&report_id=${this.state.report.value}&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}`
            console.log(url);
            let res = await fetch(
                `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/db_operating_indicator/export_report?operating_indicator_id=${this.state.OPID === null ? "" : this.state.OPID}&&report_id=${this.state.report.value}&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}`
            )
            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 = 'Report DB Operating Indicator.xlsx';
d.arizona's avatar
d.arizona committed
3034 3035 3036
                a.click();
            }
        } else if (this.state.report.value === 6) {
rifkaki's avatar
rifkaki committed
3037 3038
            let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_cash_flow/export_report?submission_id=${this.state.submissionID === null ? "" : this.state.submissionID}&&report_id=6&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.revisionType}&&months=${this.state.month.month_id}&&quarter=1`
            console.log(url);
d.arizona's avatar
d.arizona committed
3039
            let res = await fetch(
Arfin Syadziy's avatar
Arfin Syadziy committed
3040
                `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_cash_flow/export_report?submission_id=${this.state.submissionID === null ? "" : this.state.submissionID}&&report_id=6&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.revisionType}&&months=${this.state.month.month_id}&&quarter=1`
d.arizona's avatar
d.arizona committed
3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052
            )
            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 = 'Report Cash Flow - Summary.xlsx';
                a.click();
            }
        } else if (this.state.report.value === 7) {
            let res = await fetch(
Arfin Syadziy's avatar
Arfin Syadziy committed
3053
                `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_balance_sheet/export_report?submission_id=${this.state.submissionID === null ? "" : this.state.submissionID}&&report_id=2&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.revisionType}&&months=${this.state.month.month_id}&&quarter=1`
d.arizona's avatar
d.arizona committed
3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064
            )
            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 = 'Report Balance Sheet - Summary.xlsx';
                a.click();
            }
        } else if (this.state.report.value === 8) {
d.arizona's avatar
d.arizona committed
3065
            let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_profit_loss/export_report_summary?submission_id=${this.state.submissionID === null ? "" : this.state.submissionID}&&report_id=28&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.revisionType}&&months=${this.state.month.month_id}&&quarter=1`
Riri Novita's avatar
Riri Novita committed
3066
            console.log(url);
d.arizona's avatar
d.arizona committed
3067
            let res = await fetch(
d.arizona's avatar
d.arizona committed
3068
                `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_profit_loss/export_report_summary?submission_id=${this.state.submissionID === null ? "" : this.state.submissionID}&&report_id=28&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.revisionType}&&months=${this.state.month.month_id}&&quarter=1`
d.arizona's avatar
d.arizona committed
3069 3070 3071 3072 3073 3074 3075 3076
            )
            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 = 'Report Profit & Loss - Summary.xlsx';
d.arizona's avatar
d.arizona committed
3077 3078
                a.click();
            }
rifkaki's avatar
rifkaki committed
3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092
        } else if (this.state.report.value === 9) {
            let res = await fetch(
                `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_ratio/export_report?submission_id=${this.state.submissionID === null ? "" : this.state.submissionID}&&report_id=1&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.revisionType}&&months=${this.state.month.month_id}&&quarter=1`
            )
            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 = 'Report Financial Ratio - Summary.xlsx';
                a.click();
            }
        }else {
Deni Rinaldi's avatar
Deni Rinaldi committed
3093 3094 3095
            setTimeout(() => {
                this.setState({ loading: false })
            }, 1000);
Deni Rinaldi's avatar
Deni Rinaldi committed
3096 3097 3098
        }
    }

faisalhamdi's avatar
faisalhamdi committed
3099 3100 3101 3102
    closeAlert() {
        this.setState({ alert: false })
    }

faisalhamdi's avatar
faisalhamdi committed
3103
    render() {
Deni Rinaldi's avatar
Deni Rinaldi committed
3104
        const loadingComponent = (
Deni Rinaldi's avatar
Deni Rinaldi committed
3105
            <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)' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3106 3107 3108 3109 3110 3111 3112 3113
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
            </div>
        );
faisalhamdi's avatar
faisalhamdi committed
3114 3115 3116 3117 3118 3119
        return (
            <div style={{ flex: 1, backgroundColor: '#f8f8f8' }} ref={this.myRef}>
                <div>
                    <div className={"main-color"} style={{ height: 78, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
                        <Typography style={{ fontSize: '16px', color: 'white' }}>Sub Holding Report</Typography>
                    </div>
faisalhamdi's avatar
faisalhamdi committed
3120 3121 3122 3123 3124
                    <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
3125 3126 3127 3128 3129
                    <div style={{ padding: 20, width: '100%' }}>
                        <Paper style={{ paddingTop: 10 }}>
                            <div style={{ borderBottom: 'solid 1px #c4c4c4' }} >
                                <Typography style={{ fontSize: '12px', color: '#4b4b4b', margin: 10 }}>Sub Holding</Typography>
                            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3130
                            <div style={{ minWidth: 'max-content', padding: '20px 20px 0px 20px' }}>
d.arizona's avatar
d.arizona committed
3131
                                <div style={{ marginTop: 15, display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3132 3133
                                    <Autocomplete
                                        options={this.state.reportType}
Deni Rinaldi's avatar
Deni Rinaldi committed
3134
                                        getOptionLabel={(option) => titleCase(option.label)}
Deni Rinaldi's avatar
Deni Rinaldi committed
3135
                                        id="typereport"
idlanirined's avatar
idlanirined committed
3136
                                        onChange={(event, newInputValue) => this.setState({ report: newInputValue, loading: true, previewTable: false }, () => {
d.arizona's avatar
d.arizona committed
3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155
                                            console.log('sini deh')
                                            let data = this.state.listPeriode.options
                                            let currentYear = new Date().getFullYear()
                                            let periode = (this.state.lastPeriod == "" ? String(Number(currentYear) + 1) : this.state.lastPeriod)
                                            let dateNow = new Date()
                                            dateNow.setMonth(dateNow.getMonth() - 1);
                                            let yearNow = dateNow.getFullYear()
                                            // console.log(data)
                                            // console.log(yearNow)
                                            // console.log(periode)
                                            if (String(this.state.report.label).toLocaleLowerCase().includes('summary')) {
                                                let index = data.sort((a, b) => a - b).findIndex((val) => val.periode == yearNow)
                                                // console.log(index)
                                                this.setState({periode: data[index]}, () => {
                                                    this.getReportType()
                                                })
                                            } else {
                                                this.getReportType()
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
3156
                                        })}
Deni Rinaldi's avatar
Deni Rinaldi committed
3157
                                        disableClearable
faisalhamdi's avatar
faisalhamdi committed
3158
                                        style={{ width: 250 }}
Deni Rinaldi's avatar
Deni Rinaldi committed
3159 3160 3161
                                        renderInput={(params) => <TextField {...params} label="Report Type" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.report}
                                    />
faisalhamdi's avatar
faisalhamdi committed
3162
                                </div>
d.arizona's avatar
d.arizona committed
3163
                                <div style={{ marginTop: 15, display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3164 3165 3166 3167
                                    <Autocomplete
                                        {...this.state.listCompany}
                                        id="company"
                                        disabled={this.state.intent === 'Home' ? true : false}
idlanirined's avatar
idlanirined committed
3168
                                        onChange={(event, newInputValue) => this.setState({ company: newInputValue, loading: true, previewTable: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
3169
                                            this.getReportType()
Deni Rinaldi's avatar
Deni Rinaldi committed
3170
                                        })}
Deni Rinaldi's avatar
Deni Rinaldi committed
3171 3172 3173 3174 3175
                                        disableClearable
                                        style={{ width: 250 }}
                                        renderInput={(params) => <TextField {...params} label="Company" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.company}
                                    />
d.arizona's avatar
d.arizona committed
3176
                                    {/* {this.state.report != null ? String(this.state.report.label).toLocaleLowerCase().includes('summary') ? <Autocomplete
d.arizona's avatar
d.arizona committed
3177
                                        {...this.state.listUom}
d.arizona's avatar
d.arizona committed
3178
                                        // getOptionLabel={(option) => titleCase(option.label)}
d.arizona's avatar
d.arizona committed
3179 3180
                                        id="uom"
                                        onChange={(event, newInputValue) => this.setState({ uom: newInputValue, loading: true, previewTable: false }, () => {
d.arizona's avatar
d.arizona committed
3181 3182 3183 3184
                                            this.getReportType()
                                        })}
                                        disableClearable
                                        style={{ width: 250, marginLeft: 10 }}
d.arizona's avatar
d.arizona committed
3185 3186
                                        renderInput={(params) => <TextField {...params} label="Uom" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.uom}
d.arizona's avatar
d.arizona committed
3187
                                    /> : null : null} */}
faisalhamdi's avatar
faisalhamdi committed
3188
                                </div>
d.arizona's avatar
d.arizona committed
3189
                                <div style={{ marginTop: 15, display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3190 3191
                                    <Autocomplete
                                        {...this.state.listPeriode}
faisalhamdi's avatar
faisalhamdi committed
3192
                                        id="periode"
idlanirined's avatar
idlanirined committed
3193
                                        onChange={(event, newInputValue) => this.setState({ periode: newInputValue, loading: true, previewTable: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
3194
                                            this.getReportType()
Deni Rinaldi's avatar
Deni Rinaldi committed
3195 3196 3197 3198 3199 3200 3201
                                        })}
                                        disabled={this.state.intent === 'Home' ? true : false}
                                        disableClearable
                                        style={{ width: 250 }}
                                        renderInput={(params) =>
                                            <TextField {...params} label="Period" margin="normal" style={{ marginTop: 7 }}
                                            />}
faisalhamdi's avatar
faisalhamdi committed
3202
                                        value={this.state.periode}
Deni Rinaldi's avatar
Deni Rinaldi committed
3203
                                    />
rifkaki's avatar
rifkaki committed
3204 3205 3206
                                </div>
                                {this.state.report != null ? String(this.state.report.label).toLocaleLowerCase().includes('quarterly') ? <div style={{ marginTop: 15, display: 'flex' }}>
                                    <Autocomplete
d.arizona's avatar
d.arizona committed
3207 3208 3209 3210 3211 3212 3213
                                        {...this.state.listQuarter}
                                        // getOptionLabel={(option) => titleCase(option.label)}
                                        id="quarter"
                                        onChange={(event, newInputValue) => this.setState({ quarter: newInputValue, loading: true, previewTable: false }, () => {
                                            this.getReportType()
                                        })}
                                        disableClearable
rifkaki's avatar
rifkaki committed
3214
                                        style={{ width: 250 }}
d.arizona's avatar
d.arizona committed
3215 3216
                                        renderInput={(params) => <TextField {...params} label="Quarter" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.quarter}
rifkaki's avatar
rifkaki committed
3217 3218
                                    /> 
                                </div> : null : null}
d.arizona's avatar
d.arizona committed
3219 3220 3221 3222 3223 3224 3225 3226 3227
                                {this.state.report != null ? String(this.state.report.label).toLocaleLowerCase().includes('summary') ? <div style={{ marginTop: 15, display: 'flex' }}>
                                    <Autocomplete
                                        {...this.state.listMonths}
                                        // getOptionLabel={(option) => titleCase(option.label)}
                                        id="months"
                                        onChange={(event, newInputValue) => this.setState({ month: newInputValue, loading: true, previewTable: false }, () => {
                                            this.getReportType()
                                        })}
                                        disableClearable
d.arizona's avatar
d.arizona committed
3228
                                        style={{ width: 250 }}
d.arizona's avatar
d.arizona committed
3229 3230 3231 3232
                                        renderInput={(params) => <TextField {...params} label="Months" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.month}
                                    />
                                </div> : null : null}
Deni Rinaldi's avatar
Deni Rinaldi committed
3233
                            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3234
                            <div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3235
                                <div style={{ display: 'flex', justifyContent: 'space-between', padding: '0px 20px 10px 20px' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260
                                    <div></div>
                                    {this.state.previewDownload && (
                                        <div style={{ width: '50%', justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
                                            <a data-tip={'Download'} data-for="download">
                                                <button
                                                    style={{
                                                        backgroundColor: 'transparent',
                                                        cursor: 'pointer',
                                                        borderColor: 'transparent',
                                                        margin: 5,
                                                        outline: 'none'
                                                    }}
                                                    onClick={() => this.setState({ loading: true }, () => {
                                                        setTimeout(() => {
                                                            this.downloadAllData()
                                                        }, 100);
                                                    })}
                                                >
                                                    <img src={Images.download} />
                                                </button>
                                            </a>
                                            <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
                                        </div>
                                    )}
                                </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3261
                                {this.state.loading && loadingComponent}
Deni Rinaldi's avatar
Deni Rinaldi committed
3262
                                {this.state.previewTable && (
Deni Rinaldi's avatar
Deni Rinaldi committed
3263 3264 3265 3266
                                    <TableSubHolding
                                        width={this.props.width}
                                        height={this.props.height}
                                        open={this.props.open}
Riri Novita's avatar
Riri Novita committed
3267
                                        month={this.state.month.month_value}
Riri Novita's avatar
Riri Novita committed
3268 3269
                                        approvedMB={this.state.approveMB}
                                        approveMonthly={this.state.approveMonthly}
Deni Rinaldi's avatar
Deni Rinaldi committed
3270
                                        type={this.state.report ? this.state.report.value : 1}
Deni Rinaldi's avatar
Deni Rinaldi committed
3271 3272 3273 3274
                                        dataTable={this.state.dataTable}
                                        periode={this.state.periode ? this.state.periode.periode : null}
                                    />
                                )}
faisalhamdi's avatar
faisalhamdi committed
3275 3276 3277 3278 3279 3280 3281 3282
                            </div>
                        </Paper>
                    </div>
                </div>
            </div>
        )
    }
}