SubHolding.js 233 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);
Riri Novita's avatar
Riri Novita committed
425
                console.log(payload);
idlanirined's avatar
idlanirined committed
426 427
                let dataTable = []
                if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
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
                    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,
Riri Novita's avatar
Riri Novita committed
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
                                    item.profit_loss.notes,
                                    item.profit_loss.ro_full_year_january,
                                    item.profit_loss.ro_full_year_february,
                                    item.profit_loss.ro_full_year_march,
                                    item.profit_loss.ro_full_year_april,
                                    item.profit_loss.ro_full_year_may,
                                    item.profit_loss.ro_full_year_june,
                                    item.profit_loss.ro_full_year_july,
                                    item.profit_loss.ro_full_year_august,
                                    item.profit_loss.ro_full_year_september,
                                    item.profit_loss.ro_full_year_october,
                                    item.profit_loss.ro_full_year_november,
                                    item.profit_loss.ro_full_year_december,
                                    item.profit_loss.ol_q1_january,
                                    item.profit_loss.ol_q1_february,
                                    item.profit_loss.ol_q1_march,
                                    item.profit_loss.ol_q1_april,
                                    item.profit_loss.ol_q1_may,
                                    item.profit_loss.ol_q1_june,
                                    item.profit_loss.ol_q1_july,
                                    item.profit_loss.ol_q1_august,
                                    item.profit_loss.ol_q1_september,
                                    item.profit_loss.ol_q1_october,
                                    item.profit_loss.ol_q1_november,
                                    item.profit_loss.ol_q1_december,
                                    item.profit_loss.ol_q2_january,
                                    item.profit_loss.ol_q2_february,
                                    item.profit_loss.ol_q2_march,
                                    item.profit_loss.ol_q2_april,
                                    item.profit_loss.ol_q2_may,
                                    item.profit_loss.ol_q2_june,
                                    item.profit_loss.ol_q2_july,
                                    item.profit_loss.ol_q2_august,
                                    item.profit_loss.ol_q2_september,
                                    item.profit_loss.ol_q2_october,
                                    item.profit_loss.ol_q2_november,
                                    item.profit_loss.ol_q2_december,
                                    item.profit_loss.ol_q3_january,
                                    item.profit_loss.ol_q3_february,
                                    item.profit_loss.ol_q3_march,
                                    item.profit_loss.ol_q3_april,
                                    item.profit_loss.ol_q3_may,
                                    item.profit_loss.ol_q3_june,
                                    item.profit_loss.ol_q3_july,
                                    item.profit_loss.ol_q3_august,
                                    item.profit_loss.ol_q3_september,
                                    item.profit_loss.ol_q3_october,
                                    item.profit_loss.ol_q3_november,
                                    item.profit_loss.ol_q3_december,

faisalhamdi's avatar
faisalhamdi committed
531 532 533 534 535 536 537 538 539 540 541
                                ])
                            }
                            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
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
                            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,
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
                                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,
589
                                item.profit_loss.monthly_last_year_december,
Riri Novita's avatar
Riri Novita committed
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
                                item.profit_loss.notes,
                                item.profit_loss.ro_full_year_january,
                                item.profit_loss.ro_full_year_february,
                                item.profit_loss.ro_full_year_march,
                                item.profit_loss.ro_full_year_april,
                                item.profit_loss.ro_full_year_may,
                                item.profit_loss.ro_full_year_june,
                                item.profit_loss.ro_full_year_july,
                                item.profit_loss.ro_full_year_august,
                                item.profit_loss.ro_full_year_september,
                                item.profit_loss.ro_full_year_october,
                                item.profit_loss.ro_full_year_november,
                                item.profit_loss.ro_full_year_december,
                                item.profit_loss.ol_q1_january,
                                item.profit_loss.ol_q1_february,
                                item.profit_loss.ol_q1_march,
                                item.profit_loss.ol_q1_april,
                                item.profit_loss.ol_q1_may,
                                item.profit_loss.ol_q1_june,
                                item.profit_loss.ol_q1_july,
                                item.profit_loss.ol_q1_august,
                                item.profit_loss.ol_q1_september,
                                item.profit_loss.ol_q1_october,
                                item.profit_loss.ol_q1_november,
                                item.profit_loss.ol_q1_december,
                                item.profit_loss.ol_q2_january,
                                item.profit_loss.ol_q2_february,
                                item.profit_loss.ol_q2_march,
                                item.profit_loss.ol_q2_april,
                                item.profit_loss.ol_q2_may,
                                item.profit_loss.ol_q2_june,
                                item.profit_loss.ol_q2_july,
                                item.profit_loss.ol_q2_august,
                                item.profit_loss.ol_q2_september,
                                item.profit_loss.ol_q2_october,
                                item.profit_loss.ol_q2_november,
                                item.profit_loss.ol_q2_december,
                                item.profit_loss.ol_q3_january,
                                item.profit_loss.ol_q3_february,
                                item.profit_loss.ol_q3_march,
                                item.profit_loss.ol_q3_april,
                                item.profit_loss.ol_q3_may,
                                item.profit_loss.ol_q3_june,
                                item.profit_loss.ol_q3_july,
                                item.profit_loss.ol_q3_august,
                                item.profit_loss.ol_q3_september,
                                item.profit_loss.ol_q3_october,
                                item.profit_loss.ol_q3_november,
                                item.profit_loss.ol_q3_december,
idlanirined's avatar
idlanirined committed
639
                            ])
faisalhamdi's avatar
faisalhamdi committed
640 641 642 643 644 645
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
idlanirined's avatar
idlanirined committed
646
                            }
faisalhamdi's avatar
faisalhamdi committed
647
                        })
Riri Novita's avatar
Riri Novita committed
648
                        console.log(dataTable)
faisalhamdi's avatar
faisalhamdi committed
649 650
                        // this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
651

faisalhamdi's avatar
faisalhamdi committed
652 653 654 655 656 657 658 659 660 661 662 663 664 665
                        // 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
666 667 668 669 670
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
            })
        } else if (this.state.report.value === 2) {
671
            api.create().getAllReportBS(payload).then(response => {
faisalhamdi's avatar
faisalhamdi committed
672 673
                console.log(payload);
                console.log(response);
idlanirined's avatar
idlanirined committed
674
                let dataTable = []
Deni Rinaldi's avatar
Deni Rinaldi committed
675
                if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
                    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,
Riri Novita's avatar
Riri Novita committed
730 731 732 733 734 735 736 737 738 739 740 741 742 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
                                    item.balance_sheet.monthly_last_year_december,
                                    item.balance_sheet.ro_january,
                                    item.balance_sheet.ro_february,
                                    item.balance_sheet.ro_march,
                                    item.balance_sheet.ro_april,
                                    item.balance_sheet.ro_may,
                                    item.balance_sheet.ro_june,
                                    item.balance_sheet.ro_july,
                                    item.balance_sheet.ro_august,
                                    item.balance_sheet.ro_september,
                                    item.balance_sheet.ro_october,
                                    item.balance_sheet.ro_november,
                                    item.balance_sheet.ro_december,
                                    item.balance_sheet.ro_q1_january,
                                    item.balance_sheet.ro_q1_february,
                                    item.balance_sheet.ro_q1_march,
                                    item.balance_sheet.ro_q1_april,
                                    item.balance_sheet.ro_q1_may,
                                    item.balance_sheet.ro_q1_june,
                                    item.balance_sheet.ro_q1_july,
                                    item.balance_sheet.ro_q1_august,
                                    item.balance_sheet.ro_q1_september,
                                    item.balance_sheet.ro_q1_october,
                                    item.balance_sheet.ro_q1_november,
                                    item.balance_sheet.ro_q1_december,
                                    item.balance_sheet.ro_q2_january,
                                    item.balance_sheet.ro_q2_february,
                                    item.balance_sheet.ro_q2_march,
                                    item.balance_sheet.ro_q2_april,
                                    item.balance_sheet.ro_q2_may,
                                    item.balance_sheet.ro_q2_june,
                                    item.balance_sheet.ro_q2_july,
                                    item.balance_sheet.ro_q2_august,
                                    item.balance_sheet.ro_q2_september,
                                    item.balance_sheet.ro_q2_october,
                                    item.balance_sheet.ro_q2_november,
                                    item.balance_sheet.ro_q2_december,
                                    item.balance_sheet.ro_q3_january,
                                    item.balance_sheet.ro_q3_february,
                                    item.balance_sheet.ro_q3_march,
                                    item.balance_sheet.ro_q3_april,
                                    item.balance_sheet.ro_q3_may,
                                    item.balance_sheet.ro_q3_june,
                                    item.balance_sheet.ro_q3_july,
                                    item.balance_sheet.ro_q3_august,
                                    item.balance_sheet.ro_q3_september,
                                    item.balance_sheet.ro_q3_october,
                                    item.balance_sheet.ro_q3_november,
                                    item.balance_sheet.ro_q3_december,
faisalhamdi's avatar
faisalhamdi committed
779 780 781 782 783 784 785 786 787 788 789
                                ])
                            }
                            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
790 791 792 793 794 795 796 797
                            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
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
                                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
813 814
                                item.order,
                                item.condition_it_should_be,
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838
                                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,
Riri Novita's avatar
Riri Novita committed
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887
                                item.balance_sheet.monthly_last_year_december,
                                item.balance_sheet.ro_january,
                                item.balance_sheet.ro_february,
                                item.balance_sheet.ro_march,
                                item.balance_sheet.ro_april,
                                item.balance_sheet.ro_may,
                                item.balance_sheet.ro_june,
                                item.balance_sheet.ro_july,
                                item.balance_sheet.ro_august,
                                item.balance_sheet.ro_september,
                                item.balance_sheet.ro_october,
                                item.balance_sheet.ro_november,
                                item.balance_sheet.ro_december,
                                item.balance_sheet.ro_q1_january,
                                item.balance_sheet.ro_q1_february,
                                item.balance_sheet.ro_q1_march,
                                item.balance_sheet.ro_q1_april,
                                item.balance_sheet.ro_q1_may,
                                item.balance_sheet.ro_q1_june,
                                item.balance_sheet.ro_q1_july,
                                item.balance_sheet.ro_q1_august,
                                item.balance_sheet.ro_q1_september,
                                item.balance_sheet.ro_q1_october,
                                item.balance_sheet.ro_q1_november,
                                item.balance_sheet.ro_q1_december,
                                item.balance_sheet.ro_q2_january,
                                item.balance_sheet.ro_q2_february,
                                item.balance_sheet.ro_q2_march,
                                item.balance_sheet.ro_q2_april,
                                item.balance_sheet.ro_q2_may,
                                item.balance_sheet.ro_q2_june,
                                item.balance_sheet.ro_q2_july,
                                item.balance_sheet.ro_q2_august,
                                item.balance_sheet.ro_q2_september,
                                item.balance_sheet.ro_q2_october,
                                item.balance_sheet.ro_q2_november,
                                item.balance_sheet.ro_q2_december,
                                item.balance_sheet.ro_q3_january,
                                item.balance_sheet.ro_q3_february,
                                item.balance_sheet.ro_q3_march,
                                item.balance_sheet.ro_q3_april,
                                item.balance_sheet.ro_q3_may,
                                item.balance_sheet.ro_q3_june,
                                item.balance_sheet.ro_q3_july,
                                item.balance_sheet.ro_q3_august,
                                item.balance_sheet.ro_q3_september,
                                item.balance_sheet.ro_q3_october,
                                item.balance_sheet.ro_q3_november,
                                item.balance_sheet.ro_q3_december,
Deni Rinaldi's avatar
Deni Rinaldi committed
888
                            ])
faisalhamdi's avatar
faisalhamdi committed
889 890 891 892 893 894
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
895
                            }
faisalhamdi's avatar
faisalhamdi committed
896 897 898 899 900 901 902 903 904 905 906 907 908
                        })
                        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
909
                            }
faisalhamdi's avatar
faisalhamdi committed
910 911
                        })
                    }    
Riri Novita's avatar
Riri Novita committed
912
                    
Deni Rinaldi's avatar
Deni Rinaldi committed
913
                } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
914
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
915
                }
Riri Novita's avatar
Riri Novita committed
916
                console.log(dataTable);
idlanirined's avatar
idlanirined committed
917 918
            })
        } else if (this.state.report.value === 3) {
Riri Novita's avatar
Riri Novita committed
919 920 921 922 923
            let PLID = null
            let payloadID = {
                "periode": this.state.periode.periode,
                "company_id": this.state.company.company_id
            }
Riri Novita's avatar
Riri Novita committed
924
            // console.log(payloadID);
Riri Novita's avatar
Riri Novita committed
925
            api.create().getPLID(payloadID).then(response => {
Riri Novita's avatar
Riri Novita committed
926
                console.log(response);
Riri Novita's avatar
Riri Novita committed
927 928
                if (response) {
                    PLID = response.data.data == null ? null : response.data.data.profit_loss_id 
Riri Novita's avatar
Riri Novita committed
929
                    // PLID = response.data.data.profit_loss_id 
Riri Novita's avatar
Riri Novita committed
930 931 932 933
                } else {
                    PLID = null
                }
                this.setState({ PLID }, () => {
Riri Novita's avatar
Riri Novita committed
934
                    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
935 936 937 938
                    console.log(payloads);
                    api.create().getReportPL(payloads).then(response => {
                        console.log(response);
                        if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
                            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
998

faisalhamdi's avatar
faisalhamdi committed
999 1000 1001 1002 1003 1004
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
Riri Novita's avatar
Riri Novita committed
1005 1006
                                    }
                                }
faisalhamdi's avatar
faisalhamdi committed
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
                                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
1068
                                    }
faisalhamdi's avatar
faisalhamdi committed
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
                                })
                                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
1085 1086
                        } else {
                            this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
1087 1088
                        }
                    })
Riri Novita's avatar
Riri Novita committed
1089
                })
idlanirined's avatar
idlanirined committed
1090
            })
faisalhamdi's avatar
faisalhamdi committed
1091
        } else if (this.state.report.value === 4) {
Riri Novita's avatar
Riri Novita committed
1092 1093 1094 1095 1096 1097
            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
1098
                console.log(response);
Riri Novita's avatar
Riri Novita committed
1099 1100 1101 1102 1103 1104
                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
1105
                    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
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
                    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
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
                                            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
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
                                            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
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
                                            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
1163
                                        ])
faisalhamdi's avatar
faisalhamdi committed
1164
                                }
Riri Novita's avatar
Riri Novita committed
1165 1166 1167 1168 1169 1170 1171
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
                                    }
faisalhamdi's avatar
faisalhamdi committed
1172
                                }
Riri Novita's avatar
Riri Novita committed
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
                                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
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
                                        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
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
                                        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
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
                                        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
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
                                    ])
                                    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
1245
                            }
Riri Novita's avatar
Riri Novita committed
1246 1247 1248 1249 1250
                        } else {
                            this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                        }
                    })
                })
faisalhamdi's avatar
faisalhamdi committed
1251
            })
d.arizona's avatar
d.arizona committed
1252
        } else if (this.state.report.value === 5) {
rifkaki's avatar
rifkaki committed
1253
            api.create().getReportTP(payload).then(response => {
rifkaki's avatar
rifkaki committed
1254
                console.log(payload);
d.arizona's avatar
d.arizona committed
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
                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
1265 1266 1267 1268 1269 1270
                                    // 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
1271 1272 1273 1274 1275
                                    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
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
                                    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
1288
                                    item.order,
rifkaki's avatar
rifkaki committed
1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300
                                    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
1301
                                    item.tax_planning_report.monthly_full_year,
d.arizona's avatar
d.arizona committed
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
                                ])
                            }
                            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
1315 1316 1317 1318 1319 1320
                                // 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
1321 1322 1323 1324 1325
                                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
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337
                                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
1338
                                item.order,
rifkaki's avatar
rifkaki committed
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
                                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
1351
                                item.tax_planning_report.monthly_full_year,
d.arizona's avatar
d.arizona committed
1352 1353 1354 1355 1356 1357 1358 1359 1360
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
rifkaki's avatar
rifkaki committed
1361
                        console.log(dataTable)
rifkaki's avatar
rifkaki committed
1362 1363 1364 1365
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                        // this.setState({ dataTable }, () => {
                        //     this.getTaxPlanMR(payload)
                        // })
d.arizona's avatar
d.arizona committed
1366
                    } else {
d.arizona's avatar
d.arizona committed
1367 1368 1369 1370 1371 1372 1373 1374
                        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
1375
                    }
d.arizona's avatar
d.arizona committed
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392
                } 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
1393
                        OPID = null
d.arizona's avatar
d.arizona committed
1394
                    }
d.arizona's avatar
d.arizona committed
1395
                    this.setState({ OPID }, () => {
d.arizona's avatar
d.arizona committed
1396 1397 1398 1399 1400 1401
                        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
1402

1403
                        api.create().getAllReportOI(payloadOI).then(response => {
d.arizona's avatar
d.arizona committed
1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
                            // 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),
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448
                                                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
1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
                                            ])
                                        }
                                        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),
1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494
                                            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
1495 1496 1497 1498 1499 1500 1501 1502 1503
                                        ])
                                        if (item.children !== null) {
                                            if (item.children.length > 0) {
                                                item.children.map((items, indexs) => {
                                                    handlePushChild(items)
                                                })
                                            }
                                        }
                                    })
d.arizona's avatar
d.arizona committed
1504
                                    this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
1505 1506 1507 1508 1509

                                    // this.setState({ dataTable }, () => {
                                    //     console.log(this.state.dataTable)
                                    //     this.getOIMR(payloadOI)
                                    // })
d.arizona's avatar
d.arizona committed
1510
                                } else {
d.arizona's avatar
d.arizona committed
1511 1512 1513 1514 1515 1516 1517 1518
                                    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
1519
                                }
d.arizona's avatar
d.arizona committed
1520 1521 1522 1523 1524
                            } else {
                                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                            }
                        })
                    })
d.arizona's avatar
d.arizona committed
1525 1526
                }
            })
d.arizona's avatar
d.arizona committed
1527
        } else if (this.state.report.value === 6) {
d.arizona's avatar
d.arizona committed
1528
            let dbSumaCF = []
d.arizona's avatar
d.arizona committed
1529
            let paylodCF = { ...payload, months: this.state.month.month_id }
d.arizona's avatar
d.arizona committed
1530
            api.create().getReportCFSuma(paylodCF).then(response => {
d.arizona's avatar
d.arizona committed
1531
                console.log(response)
d.arizona's avatar
d.arizona committed
1532 1533 1534
                if (response.data) {
                    if (response.data.status === 'success') {
                        let res = response.data.data
d.arizona's avatar
d.arizona committed
1535
                        console.log(res)
d.arizona's avatar
d.arizona committed
1536
                        const handlePushChild = (item) => {
rifkaki's avatar
rifkaki committed
1537
                            let indexIDzz = dbSumaCF.findIndex((val) => val[0] === item.id)
d.arizona's avatar
d.arizona committed
1538
                            if (indexIDzz === -1) {
rifkaki's avatar
rifkaki committed
1539 1540
                                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
1541
                                console.log(mtd)
rifkaki's avatar
rifkaki committed
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
                                // 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
1570

rifkaki's avatar
rifkaki committed
1571 1572
                                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
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584
                                // 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
1585

rifkaki's avatar
rifkaki committed
1586 1587
                                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
1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599
                                // 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
1600 1601

                                dbSumaCF.push([
d.arizona's avatar
d.arizona committed
1602
                                    item.id,
d.arizona's avatar
d.arizona committed
1603 1604
                                    item.cash_flow.mtd_actual,
                                    item.cash_flow.mtd,
d.arizona's avatar
d.arizona committed
1605
                                    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
1606 1607 1608
                                    item.cash_flow.mtd_last_year,
                                    item.cash_flow.ytd_actual,
                                    item.cash_flow.ytd,
d.arizona's avatar
d.arizona committed
1609
                                    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
1610
                                    // isNaN(persenYtd)? 0 : persenYtd * 100,
d.arizona's avatar
d.arizona committed
1611 1612 1613
                                    item.cash_flow.ytd_last_year,
                                    item.cash_flow.quarter_actual,
                                    item.cash_flow.quarter,
d.arizona's avatar
d.arizona committed
1614
                                    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
1615
                                    // isNaN(persenQuarter)? 0 : persenQuarter * 100,
d.arizona's avatar
d.arizona committed
1616 1617 1618
                                    item.cash_flow.quarter_last_year,
                                    item.cash_flow.fy_actual,
                                    item.cash_flow.fy,
d.arizona's avatar
d.arizona committed
1619
                                    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
1620
                                    // isNaN(persenFy)? 0 : persenFy * 100,
d.arizona's avatar
d.arizona committed
1621
                                    item.cash_flow.fy_last_year,
d.arizona's avatar
d.arizona committed
1622 1623 1624 1625 1626 1627 1628 1629 1630 1631
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
d.arizona's avatar
d.arizona committed
1632
                        res.map((item, index) => {
rifkaki's avatar
rifkaki committed
1633 1634 1635
                            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
1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662
                            // 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
1663

rifkaki's avatar
rifkaki committed
1664 1665
                            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
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677
                            // 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
1678

rifkaki's avatar
rifkaki committed
1679 1680
                            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
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692
                            // 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
1693 1694

                            dbSumaCF.push([
d.arizona's avatar
d.arizona committed
1695
                                item.id,
d.arizona's avatar
d.arizona committed
1696 1697
                                item.cash_flow.mtd_actual,
                                item.cash_flow.mtd,
d.arizona's avatar
d.arizona committed
1698
                                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
1699 1700 1701
                                item.cash_flow.mtd_last_year,
                                item.cash_flow.ytd_actual,
                                item.cash_flow.ytd,
d.arizona's avatar
d.arizona committed
1702
                                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
1703
                                // isNaN(persenYtd)? 0 : persenYtd * 100,
d.arizona's avatar
d.arizona committed
1704 1705 1706
                                item.cash_flow.ytd_last_year,
                                item.cash_flow.quarter_actual,
                                item.cash_flow.quarter,
d.arizona's avatar
d.arizona committed
1707
                                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
1708
                                // isNaN(persenQuarter)? 0 : persenQuarter * 100,
d.arizona's avatar
d.arizona committed
1709 1710 1711
                                item.cash_flow.quarter_last_year,
                                item.cash_flow.fy_actual,
                                item.cash_flow.fy,
d.arizona's avatar
d.arizona committed
1712
                                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
1713
                                // isNaN(persenFy)? 0 : persenFy * 100,
d.arizona's avatar
d.arizona committed
1714
                                item.cash_flow.fy_last_year,
d.arizona's avatar
d.arizona committed
1715 1716 1717 1718 1719 1720 1721 1722 1723
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
d.arizona's avatar
d.arizona committed
1724
                        console.log(dbSumaCF)
d.arizona's avatar
d.arizona committed
1725
                        this.setState({ dbSumaCF }, () => {
d.arizona's avatar
d.arizona committed
1726 1727 1728 1729 1730 1731 1732
                            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
1733
                                        console.log(res)
d.arizona's avatar
d.arizona committed
1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762
                                        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,
Riri Novita's avatar
Riri Novita committed
1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775
                                                    item.cash_flow.forecast_formula == null ? [] : item.cash_flow.forecast_formula,
                                                    item.cash_flow.olpa_january,
                                                    item.cash_flow.olpa_february,
                                                    item.cash_flow.olpa_march,
                                                    item.cash_flow.olpa_april,
                                                    item.cash_flow.olpa_may,
                                                    item.cash_flow.olpa_june,
                                                    item.cash_flow.olpa_july,
                                                    item.cash_flow.olpa_august,
                                                    item.cash_flow.olpa_september,
                                                    item.cash_flow.olpa_october,
                                                    item.cash_flow.olpa_november,
                                                    item.cash_flow.olpa_december,
d.arizona's avatar
d.arizona committed
1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812
                                                ])
                                            }
                                            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,
Riri Novita's avatar
Riri Novita committed
1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825
                                                item.cash_flow.forecast_formula == null ? [] : item.cash_flow.forecast_formula,
                                                item.cash_flow.olpa_january,
                                                item.cash_flow.olpa_february,
                                                item.cash_flow.olpa_march,
                                                item.cash_flow.olpa_april,
                                                item.cash_flow.olpa_may,
                                                item.cash_flow.olpa_june,
                                                item.cash_flow.olpa_july,
                                                item.cash_flow.olpa_august,
                                                item.cash_flow.olpa_september,
                                                item.cash_flow.olpa_october,
                                                item.cash_flow.olpa_november,
                                                item.cash_flow.olpa_december,
d.arizona's avatar
d.arizona committed
1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836
                                            ])
                                            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
1837
                                            this.getCFSumaMR(paylodCF, dbSumaCF)
d.arizona's avatar
d.arizona committed
1838
                                        })
d.arizona's avatar
d.arizona committed
1839
                                    } else {
d.arizona's avatar
d.arizona committed
1840 1841 1842 1843 1844 1845 1846 1847
                                        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
1848
                                    }
d.arizona's avatar
d.arizona committed
1849 1850 1851
                                } else {
                                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                                }
Riri Novita's avatar
Riri Novita committed
1852
                                console.log(dataTable);
d.arizona's avatar
d.arizona committed
1853
                            })
d.arizona's avatar
d.arizona committed
1854
                        })
d.arizona's avatar
d.arizona committed
1855
                    } else {
d.arizona's avatar
d.arizona committed
1856 1857 1858 1859 1860 1861 1862 1863
                        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
1864
                    }
d.arizona's avatar
d.arizona committed
1865 1866 1867 1868
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                }
            })
Riri Novita's avatar
Riri Novita committed
1869
        } else if (this.state.report.value === 7) {
faisalhamdi's avatar
faisalhamdi committed
1870 1871 1872 1873
            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
1874
                console.log(response);
faisalhamdi's avatar
faisalhamdi committed
1875
                if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887
                    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) {
1888
                                    if (parseFloat(mtd_actual) < parseFloat(mtd_mb)) {
faisalhamdi's avatar
faisalhamdi committed
1889 1890 1891 1892 1893 1894 1895 1896 1897
                                        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) {
1898
                                    if (parseFloat(mtd_actual) < parseFloat(mtd_ol)) {
faisalhamdi's avatar
faisalhamdi committed
1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941
                                        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) {
1942
                                if (parseFloat(mtd_actual) < parseFloat(mtd_mb)) {
faisalhamdi's avatar
faisalhamdi committed
1943 1944 1945 1946 1947 1948 1949 1950 1951
                                    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) {
1952
                                if (parseFloat(mtd_actual) < parseFloat(mtd_ol)) {
faisalhamdi's avatar
faisalhamdi committed
1953 1954 1955 1956 1957 1958 1959 1960 1961
                                    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
1962 1963 1964 1965 1966 1967
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
faisalhamdi's avatar
faisalhamdi committed
1968
                                item.balance_sheet.mtd_last_month,
d.arizona's avatar
d.arizona committed
1969 1970
                                item.balance_sheet.mtd_actual,
                                item.balance_sheet.mtd_mb,
faisalhamdi's avatar
faisalhamdi committed
1971
                                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
1972
                                item.balance_sheet.mtd_ol,
faisalhamdi's avatar
faisalhamdi committed
1973
                                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
1974
                                item.balance_sheet.mtd_last_year,
faisalhamdi's avatar
faisalhamdi committed
1975
                                item.balance_sheet.forecast_next_year,
d.arizona's avatar
d.arizona committed
1976
                                item.balance_sheet.forecast_more_year,
faisalhamdi's avatar
faisalhamdi committed
1977 1978
                                item.order
                            ])
faisalhamdi's avatar
faisalhamdi committed
1979 1980 1981 1982 1983 1984
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
faisalhamdi's avatar
faisalhamdi committed
1985
                            }
faisalhamdi's avatar
faisalhamdi committed
1986 1987
                        })
                        this.setState({ dataTable: dbSumaBS, previewTable: true, loading: false, previewDownload: true })
d.arizona's avatar
d.arizona committed
1988
                        console.log(this.state.dataTable)
faisalhamdi's avatar
faisalhamdi committed
1989 1990 1991 1992 1993 1994 1995 1996 1997 1998
                    } 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
1999
                } else {
faisalhamdi's avatar
faisalhamdi committed
2000
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
faisalhamdi's avatar
faisalhamdi committed
2001
                }
Riri Novita's avatar
Riri Novita committed
2002 2003 2004
            })

        } else if (this.state.report.value === 8) {
Riri Novita's avatar
Riri Novita committed
2005
            let dbSumaPL = []
Riri Novita's avatar
Riri Novita committed
2006 2007
            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
2008
                console.log(response);
Riri Novita's avatar
Riri Novita committed
2009 2010 2011 2012 2013 2014 2015
                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
2016 2017 2018
                                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
2019 2020 2021
                                let persenMtd = 0
                                if (mtd_mb  < 0) {
                                    if (mtd_actual >= mtd_mb) {
Riri Novita's avatar
Riri Novita committed
2022
                                        persenMtd = (mtd_mb - mtd_actual) / mtd_mb + 1  
Riri Novita's avatar
Riri Novita committed
2023
                                    }  else {
Riri Novita's avatar
Riri Novita committed
2024
                                        persenMtd = (mtd_mb - mtd_actual) / mtd_mb 
Riri Novita's avatar
Riri Novita committed
2025 2026 2027
                                    }
                                }
                                else {
Riri Novita's avatar
Riri Novita committed
2028
                                    persenMtd = mtd_actual / mtd_mb
Riri Novita's avatar
Riri Novita committed
2029 2030
                                }

Riri Novita's avatar
Riri Novita committed
2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043
                                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
2044 2045 2046 2047 2048 2049
                                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
2050
                                        persenYtdMB = (ytd_mb - ytd_actual) / ytd_mb + 1  
Riri Novita's avatar
Riri Novita committed
2051
                                    }  else {
Riri Novita's avatar
Riri Novita committed
2052
                                        persenYtdMB = (ytd_mb - ytd_actual) / ytd_mb 
Riri Novita's avatar
Riri Novita committed
2053 2054 2055
                                    }
                                }
                                else {
Riri Novita's avatar
Riri Novita committed
2056
                                    persenYtdMB = ytd_actual / ytd_mb 
Riri Novita's avatar
Riri Novita committed
2057 2058 2059 2060 2061
                                }

                                let persenYtdLY = 0
                                if (ytd_last_year  < 0) {
                                    if (ytd_actual >= ytd_last_year) {
Riri Novita's avatar
Riri Novita committed
2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077
                                        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
2078
                                    }  else {
Riri Novita's avatar
Riri Novita committed
2079
                                        persenQuarterMB = (q1_mb - q1_actual) / q1_mb 
Riri Novita's avatar
Riri Novita committed
2080 2081 2082
                                    }
                                }
                                else {
Riri Novita's avatar
Riri Novita committed
2083
                                    persenQuarterMB = q1_actual / q1_mb 
Riri Novita's avatar
Riri Novita committed
2084
                                }
Riri Novita's avatar
Riri Novita committed
2085

Riri Novita's avatar
Riri Novita committed
2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136
                                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
2137

Riri Novita's avatar
Riri Novita committed
2138
                                let persenFyOLMB = Number(fy_ol/fy_mb)
Riri Novita's avatar
Riri Novita committed
2139 2140 2141 2142 2143 2144 2145 2146 2147 2148
                                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
2149 2150

                                dbSumaPL.push([
Riri Novita's avatar
Riri Novita committed
2151
                                    item.type_report_id,
Riri Novita's avatar
Riri Novita committed
2152
                                    item.id,
Riri Novita's avatar
Riri Novita committed
2153 2154 2155 2156
                                    item.parent,
                                    item.formula,
                                    item.level,
                                    item.description,
Riri Novita's avatar
Riri Novita committed
2157
                                    item.profit_loss.mtd_actual,
Riri Novita's avatar
Riri Novita committed
2158 2159
                                    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
2160
                                    item.profit_loss.mtd_last_year,
Riri Novita's avatar
Riri Novita committed
2161
                                    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
2162
                                    item.profit_loss.ytd_actual,
Riri Novita's avatar
Riri Novita committed
2163 2164
                                    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
2165
                                    item.profit_loss.ytd_last_year,
Riri Novita's avatar
Riri Novita committed
2166 2167 2168 2169 2170 2171
                                    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
2172
                                    item.profit_loss.fy_actual,
Riri Novita's avatar
Riri Novita committed
2173 2174 2175 2176
                                    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
2177
                                    item.profit_loss.fy_last_year,
Riri Novita's avatar
Riri Novita committed
2178 2179 2180
                                    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
2181 2182
                                    item.profit_loss.forecast_more_year,
                                    item.profit_loss.notes,
Riri Novita's avatar
Riri Novita committed
2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193
                                ])
                            }
                            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
2194 2195
                            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
2196
                            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
2197 2198 2199
                            let persenMtd = 0
                            if (mtd_mb  < 0) {
                                if (mtd_actual >= mtd_mb) {
Riri Novita's avatar
Riri Novita committed
2200
                                    persenMtd = (mtd_mb - mtd_actual) / mtd_mb + 1  
Riri Novita's avatar
Riri Novita committed
2201
                                }  else {
Riri Novita's avatar
Riri Novita committed
2202
                                    persenMtd = (mtd_mb - mtd_actual) / mtd_mb 
Riri Novita's avatar
Riri Novita committed
2203 2204
                                }
                            }
Riri Novita's avatar
Riri Novita committed
2205 2206
                            else {
                                persenMtd = mtd_actual / mtd_mb
Riri Novita's avatar
Riri Novita committed
2207
                            }
Riri Novita's avatar
Riri Novita committed
2208

Riri Novita's avatar
Riri Novita committed
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
                            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
2248

Riri Novita's avatar
Riri Novita committed
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
                            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
2315

Riri Novita's avatar
Riri Novita committed
2316
                            let persenFyOLMB = Number(fy_ol/fy_mb)
Riri Novita's avatar
Riri Novita committed
2317 2318 2319 2320 2321 2322 2323 2324 2325 2326
                            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
2327 2328

                            dbSumaPL.push([
Riri Novita's avatar
Riri Novita committed
2329
                                item.type_report_id,
Riri Novita's avatar
Riri Novita committed
2330
                                item.id,
Riri Novita's avatar
Riri Novita committed
2331 2332 2333 2334
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
Riri Novita's avatar
Riri Novita committed
2335
                                item.profit_loss.mtd_actual,
Riri Novita's avatar
Riri Novita committed
2336
                                item.profit_loss.mtd_mb,
Riri Novita's avatar
Riri Novita committed
2337
                                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
2338
                                item.profit_loss.mtd_last_year,
Riri Novita's avatar
Riri Novita committed
2339
                                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
2340
                                item.profit_loss.ytd_actual,
Riri Novita's avatar
Riri Novita committed
2341 2342
                                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
2343
                                item.profit_loss.ytd_last_year,
Riri Novita's avatar
Riri Novita committed
2344 2345 2346 2347 2348 2349
                                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
2350
                                item.profit_loss.fy_actual,
Riri Novita's avatar
Riri Novita committed
2351 2352 2353 2354
                                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
2355
                                item.profit_loss.fy_last_year,
Riri Novita's avatar
Riri Novita committed
2356 2357
                                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
2358 2359 2360
                                item.profit_loss.forecast_next_year,
                                item.profit_loss.forecast_more_year,
                                item.profit_loss.notes,
Riri Novita's avatar
Riri Novita committed
2361 2362 2363 2364 2365 2366 2367
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
Riri Novita's avatar
Riri Novita committed
2368
                            } 
Riri Novita's avatar
Riri Novita committed
2369
                        })
Riri Novita's avatar
Riri Novita committed
2370
                        this.setState({ dataTable: dbSumaPL, loading: false, previewTable: true, previewDownload: true })
Riri Novita's avatar
Riri Novita committed
2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383
                    } 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
2384 2385
            })
        } else if (this.state.report.value === 9) {
rifkaki's avatar
rifkaki committed
2386 2387 2388 2389 2390 2391
            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
2392
                console.log(response);
rifkaki's avatar
rifkaki committed
2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606
                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
2607
            })
faisalhamdi's avatar
faisalhamdi committed
2608 2609 2610 2611 2612 2613 2614 2615 2616 2617
        } 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
2618
        }
Riri Novita's avatar
Riri Novita committed
2619

d.arizona's avatar
d.arizona committed
2620 2621
    }

d.arizona's avatar
d.arizona committed
2622
    getCFSumaMR(payload, dbSumaCF) {
d.arizona's avatar
d.arizona committed
2623
        let payloadLast = { ...payload, "periode": Number(this.state.periode.periode) - 1 }
d.arizona's avatar
d.arizona committed
2624 2625 2626 2627 2628 2629 2630 2631
        // 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
2632 2633 2634 2635 2636 2637 2638
        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
2639
                res.map((item, index) => {
d.arizona's avatar
d.arizona committed
2640 2641 2642 2643 2644 2645 2646
                    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
2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658
                                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,
Riri Novita's avatar
Riri Novita committed
2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695
                                items.cash_flow.q1_january,
                                items.cash_flow.q1_february,
                                items.cash_flow.q1_march,
                                items.cash_flow.q1_april,
                                items.cash_flow.q1_may,
                                items.cash_flow.q1_june,
                                items.cash_flow.q1_july,
                                items.cash_flow.q1_august,
                                items.cash_flow.q1_september,
                                items.cash_flow.q1_october,
                                items.cash_flow.q1_november,
                                items.cash_flow.q1_december,
                                items.cash_flow.q2_january,
                                items.cash_flow.q2_february,
                                items.cash_flow.q2_march,
                                items.cash_flow.q2_april,
                                items.cash_flow.q2_may,
                                items.cash_flow.q2_june,
                                items.cash_flow.q2_july,
                                items.cash_flow.q2_august,
                                items.cash_flow.q2_september,
                                items.cash_flow.q2_october,
                                items.cash_flow.q2_november,
                                items.cash_flow.q2_december,
                                items.cash_flow.q3_january,
                                items.cash_flow.q3_february,
                                items.cash_flow.q3_march,
                                items.cash_flow.q3_april,
                                items.cash_flow.q3_may,
                                items.cash_flow.q3_june,
                                items.cash_flow.q3_july,
                                items.cash_flow.q3_august,
                                items.cash_flow.q3_september,
                                items.cash_flow.q3_october,
                                items.cash_flow.q3_november,
                                items.cash_flow.q3_december,

d.arizona's avatar
d.arizona committed
2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707
                                ])
                            }
                            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
2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719
                        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,
Riri Novita's avatar
Riri Novita committed
2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755
                        item.cash_flow.q1_january,
                        item.cash_flow.q1_february,
                        item.cash_flow.q1_march,
                        item.cash_flow.q1_april,
                        item.cash_flow.q1_may,
                        item.cash_flow.q1_june,
                        item.cash_flow.q1_july,
                        item.cash_flow.q1_august,
                        item.cash_flow.q1_september,
                        item.cash_flow.q1_october,
                        item.cash_flow.q1_november,
                        item.cash_flow.q1_december,
                        item.cash_flow.q2_january,
                        item.cash_flow.q2_february,
                        item.cash_flow.q2_march,
                        item.cash_flow.q2_april,
                        item.cash_flow.q2_may,
                        item.cash_flow.q2_june,
                        item.cash_flow.q2_july,
                        item.cash_flow.q2_august,
                        item.cash_flow.q2_september,
                        item.cash_flow.q2_october,
                        item.cash_flow.q2_november,
                        item.cash_flow.q2_december,
                        item.cash_flow.q3_january,
                        item.cash_flow.q3_february,
                        item.cash_flow.q3_march,
                        item.cash_flow.q3_april,
                        item.cash_flow.q3_may,
                        item.cash_flow.q3_june,
                        item.cash_flow.q3_july,
                        item.cash_flow.q3_august,
                        item.cash_flow.q3_september,
                        item.cash_flow.q3_october,
                        item.cash_flow.q3_november,
                        item.cash_flow.q3_december,
d.arizona's avatar
d.arizona committed
2756 2757 2758 2759 2760 2761 2762 2763 2764
                        ])

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

d.arizona's avatar
d.arizona committed
2766
                    }
d.arizona's avatar
d.arizona committed
2767

d.arizona's avatar
d.arizona committed
2768 2769 2770
                })
                this.setState({ dataTable2 }, () => {
                    // console.log(this.state.dataTable2)
d.arizona's avatar
d.arizona committed
2771
                    this.getCFSumaLastMR(payloadLast, dbSumaCF)
d.arizona's avatar
d.arizona committed
2772 2773 2774 2775 2776 2777 2778 2779 2780
                })
                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
2781
    getCFSumaLastMR(payload, dbSumaCF) {
rifkaki's avatar
rifkaki committed
2782 2783
        console.log(dbSumaCF)
        console.log(this.state.dbSumaCF)
d.arizona's avatar
d.arizona committed
2784 2785 2786 2787 2788 2789 2790
        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
2791
                res.map((item, index) => {
d.arizona's avatar
d.arizona committed
2792
                    let indexID = dataTable2.findIndex((val) => val[1] == item.id)
d.arizona's avatar
d.arizona committed
2793
                    let indexIDSuma = dbSumaCF.findIndex((val) => val[0] == item.id)
d.arizona's avatar
d.arizona committed
2794 2795 2796
                    if (indexID != -1) {
                        const handlePushChild = (items) => {
                            let indexIDzz = dataTable2.findIndex((val) => val[1] === items.id)
rifkaki's avatar
rifkaki committed
2797
                            let indexIDSumaChild = dbSumaCF.findIndex((val) => val[0] == items.id)
d.arizona's avatar
d.arizona committed
2798 2799 2800
                            // console.log(indexIDzz)
                            if (indexIDzz != -1) {
                                dataTable3.push([...dataTable2[indexIDzz],
d.arizona's avatar
d.arizona committed
2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812
                                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
2813
                                ...dbSumaCF[indexIDSumaChild]
d.arizona's avatar
d.arizona committed
2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825
                                ])
                            }
                            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
2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838
                        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
2839 2840 2841 2842 2843 2844 2845 2846 2847
                        ])

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

d.arizona's avatar
d.arizona committed
2849
                    }
d.arizona's avatar
d.arizona committed
2850

d.arizona's avatar
d.arizona committed
2851
                })
rifkaki's avatar
rifkaki committed
2852
                console.log(dbSumaCF)
d.arizona's avatar
d.arizona committed
2853 2854 2855 2856 2857 2858 2859 2860
                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
2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875
    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
2876
                res.map((item, index) => {
Riri Novita's avatar
Riri Novita committed
2877 2878 2879 2880 2881 2882 2883
                    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
2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896
                                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
2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908
                                ])
                            }
                            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
2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921
                        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
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

Riri Novita's avatar
Riri Novita committed
2932
                    }
d.arizona's avatar
d.arizona committed
2933

Riri Novita's avatar
Riri Novita committed
2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954
                })
                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
2955
                res.map((item, index) => {
Riri Novita's avatar
Riri Novita committed
2956 2957 2958 2959 2960 2961 2962
                    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
2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974
                                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
2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986
                                ])
                            }
                            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
2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998
                        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
2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010
                        ])

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

                    }

d.arizona's avatar
d.arizona committed
3011 3012 3013 3014 3015 3016 3017 3018 3019
                })
                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
3020
    getRatioMR(payload) {
rifkaki's avatar
rifkaki committed
3021 3022 3023 3024 3025 3026 3027
        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
3028 3029 3030 3031 3032 3033 3034 3035
        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
3036
                    res.map((item, index) => {
d.arizona's avatar
d.arizona committed
3037 3038 3039 3040 3041 3042 3043
                        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
3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067
                                    // 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
3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079
                                    ])
                                }
                                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
3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103
                            // 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
3104 3105 3106 3107 3108 3109 3110 3111 3112
                            ])

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

d.arizona's avatar
d.arizona committed
3114
                        }
d.arizona's avatar
d.arizona committed
3115

d.arizona's avatar
d.arizona committed
3116 3117
                    })
                    console.log(dataTable2)
rifkaki's avatar
rifkaki committed
3118 3119 3120 3121 3122
                    // 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
3123
                } else {
rifkaki's avatar
rifkaki committed
3124 3125 3126 3127 3128 3129 3130 3131
                    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
3132
                }
rifkaki's avatar
rifkaki committed
3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147
            } 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
3148
                    res.map((item, index) => {
rifkaki's avatar
rifkaki committed
3149 3150 3151 3152 3153 3154 3155
                        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
3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179
                                    // 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
3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191
                                    ])
                                }
                                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
3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215
                            // 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
3216 3217 3218 3219 3220 3221 3222 3223 3224
                            ])

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

rifkaki's avatar
rifkaki committed
3226
                        }
d.arizona's avatar
d.arizona committed
3227

rifkaki's avatar
rifkaki committed
3228 3229 3230
                    })
                    console.log(dataTable3)
                    this.setState({ dataTable: dataTable3, previewTable: true, loading: false, previewDownload: true })
d.arizona's avatar
d.arizona committed
3231
                } else {
d.arizona's avatar
d.arizona committed
3232 3233 3234 3235 3236 3237 3238 3239
                    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
3240
                }
d.arizona's avatar
d.arizona committed
3241 3242 3243 3244 3245 3246
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
3247
    async downloadAllData() {
faisalhamdi's avatar
faisalhamdi committed
3248
        if (this.state.report.value === 1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
3249
            let res = await fetch(
d.arizona's avatar
d.arizona committed
3250
                `${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
3251 3252 3253 3254 3255 3256 3257
            )
            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
3258
                a.download = 'Report DB Profit & Loss Detail.xlsx';
Deni Rinaldi's avatar
Deni Rinaldi committed
3259 3260
                a.click();
            }
faisalhamdi's avatar
faisalhamdi committed
3261
        } else if (this.state.report.value === 2) {
Deni Rinaldi's avatar
Deni Rinaldi committed
3262
            let res = await fetch(
d.arizona's avatar
d.arizona committed
3263
                `${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
3264 3265 3266 3267 3268 3269 3270
            )
            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
3271
                a.download = 'Report DB Balance Sheet.xlsx';
Deni Rinaldi's avatar
Deni Rinaldi committed
3272 3273 3274 3275
                a.click();
            }
        } else if (this.state.report.value === 3) {
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
3276
                `${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
3277 3278 3279 3280 3281 3282 3283
            )
            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
3284
                a.download = 'Report DB Profit & Loss.xlsx';
Deni Rinaldi's avatar
Deni Rinaldi committed
3285 3286
                a.click();
            }
faisalhamdi's avatar
faisalhamdi committed
3287
        } else if (this.state.report.value === 4) {
Riri Novita's avatar
Riri Novita committed
3288
            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
3289
            console.log(url);
faisalhamdi's avatar
faisalhamdi committed
3290
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
3291
                `${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
3292 3293 3294 3295 3296 3297 3298 3299 3300 3301
            )
            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
3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314
        } 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
3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327
        } 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
3328 3329 3330
                a.click();
            }
        } else if (this.state.report.value === 6) {
rifkaki's avatar
rifkaki committed
3331 3332
            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
3333
            let res = await fetch(
Arfin Syadziy's avatar
Arfin Syadziy committed
3334
                `${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
3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346
            )
            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
3347
                `${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
3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358
            )
            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
3359
            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
3360
            console.log(url);
d.arizona's avatar
d.arizona committed
3361
            let res = await fetch(
d.arizona's avatar
d.arizona committed
3362
                `${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
3363 3364 3365 3366 3367 3368 3369 3370
            )
            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
3371 3372
                a.click();
            }
rifkaki's avatar
rifkaki committed
3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386
        } 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
3387 3388 3389
            setTimeout(() => {
                this.setState({ loading: false })
            }, 1000);
Deni Rinaldi's avatar
Deni Rinaldi committed
3390 3391 3392
        }
    }

faisalhamdi's avatar
faisalhamdi committed
3393 3394 3395 3396
    closeAlert() {
        this.setState({ alert: false })
    }

faisalhamdi's avatar
faisalhamdi committed
3397
    render() {
Deni Rinaldi's avatar
Deni Rinaldi committed
3398
        const loadingComponent = (
Deni Rinaldi's avatar
Deni Rinaldi committed
3399
            <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
3400 3401 3402 3403 3404 3405 3406 3407
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
            </div>
        );
faisalhamdi's avatar
faisalhamdi committed
3408 3409 3410 3411 3412 3413
        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
3414 3415 3416 3417 3418
                    <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
3419 3420 3421 3422 3423
                    <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
3424
                            <div style={{ minWidth: 'max-content', padding: '20px 20px 0px 20px' }}>
d.arizona's avatar
d.arizona committed
3425
                                <div style={{ marginTop: 15, display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3426 3427
                                    <Autocomplete
                                        options={this.state.reportType}
Deni Rinaldi's avatar
Deni Rinaldi committed
3428
                                        getOptionLabel={(option) => titleCase(option.label)}
Deni Rinaldi's avatar
Deni Rinaldi committed
3429
                                        id="typereport"
idlanirined's avatar
idlanirined committed
3430
                                        onChange={(event, newInputValue) => this.setState({ report: newInputValue, loading: true, previewTable: false }, () => {
d.arizona's avatar
d.arizona committed
3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449
                                            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
3450
                                        })}
Deni Rinaldi's avatar
Deni Rinaldi committed
3451
                                        disableClearable
faisalhamdi's avatar
faisalhamdi committed
3452
                                        style={{ width: 250 }}
Deni Rinaldi's avatar
Deni Rinaldi committed
3453 3454 3455
                                        renderInput={(params) => <TextField {...params} label="Report Type" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.report}
                                    />
d.arizona's avatar
d.arizona committed
3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469
                                    <Autocomplete
                                        {...this.state.listPeriode}
                                        id="periode"
                                        onChange={(event, newInputValue) => this.setState({ periode: newInputValue, loading: true, previewTable: false }, () => {
                                            this.getReportType()
                                        })}
                                        disabled={this.state.intent === 'Home' ? true : false}
                                        disableClearable
                                        style={{ width: 250, marginLeft: 20}}
                                        renderInput={(params) =>
                                            <TextField {...params} label="Period" margin="normal" style={{ marginTop: 7 }}
                                            />}
                                        value={this.state.periode}
                                    />
faisalhamdi's avatar
faisalhamdi committed
3470
                                </div>
d.arizona's avatar
d.arizona committed
3471
                                <div style={{ marginTop: 15, display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3472 3473 3474 3475
                                    <Autocomplete
                                        {...this.state.listCompany}
                                        id="company"
                                        disabled={this.state.intent === 'Home' ? true : false}
idlanirined's avatar
idlanirined committed
3476
                                        onChange={(event, newInputValue) => this.setState({ company: newInputValue, loading: true, previewTable: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
3477
                                            this.getReportType()
Deni Rinaldi's avatar
Deni Rinaldi committed
3478
                                        })}
Deni Rinaldi's avatar
Deni Rinaldi committed
3479 3480 3481 3482 3483
                                        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
3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496
                                    {this.state.report != null ? String(this.state.report.label).toLocaleLowerCase().includes('summary') ? 
                                        <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
                                            style={{ width: 250, marginLeft: 20}}
                                            renderInput={(params) => <TextField {...params} label="Months" margin="normal" style={{ marginTop: 7 }} />}
                                            value={this.state.month}
                                        /> : null : null}
d.arizona's avatar
d.arizona committed
3497
                                    {/* {this.state.report != null ? String(this.state.report.label).toLocaleLowerCase().includes('summary') ? <Autocomplete
d.arizona's avatar
d.arizona committed
3498
                                        {...this.state.listUom}
d.arizona's avatar
d.arizona committed
3499
                                        // getOptionLabel={(option) => titleCase(option.label)}
d.arizona's avatar
d.arizona committed
3500 3501
                                        id="uom"
                                        onChange={(event, newInputValue) => this.setState({ uom: newInputValue, loading: true, previewTable: false }, () => {
d.arizona's avatar
d.arizona committed
3502 3503 3504 3505
                                            this.getReportType()
                                        })}
                                        disableClearable
                                        style={{ width: 250, marginLeft: 10 }}
d.arizona's avatar
d.arizona committed
3506 3507
                                        renderInput={(params) => <TextField {...params} label="Uom" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.uom}
d.arizona's avatar
d.arizona committed
3508
                                    /> : null : null} */}
faisalhamdi's avatar
faisalhamdi committed
3509
                                </div>
d.arizona's avatar
d.arizona committed
3510
                                {/* <div style={{ marginTop: 15, display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3511 3512
                                    <Autocomplete
                                        {...this.state.listPeriode}
faisalhamdi's avatar
faisalhamdi committed
3513
                                        id="periode"
idlanirined's avatar
idlanirined committed
3514
                                        onChange={(event, newInputValue) => this.setState({ periode: newInputValue, loading: true, previewTable: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
3515
                                            this.getReportType()
Deni Rinaldi's avatar
Deni Rinaldi committed
3516 3517 3518 3519 3520 3521 3522
                                        })}
                                        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
3523
                                        value={this.state.periode}
Deni Rinaldi's avatar
Deni Rinaldi committed
3524
                                    />
d.arizona's avatar
d.arizona committed
3525
                                </div> */}
rifkaki's avatar
rifkaki committed
3526 3527
                                {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
3528 3529 3530 3531 3532 3533 3534
                                        {...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
3535
                                        style={{ width: 250 }}
d.arizona's avatar
d.arizona committed
3536 3537
                                        renderInput={(params) => <TextField {...params} label="Quarter" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.quarter}
rifkaki's avatar
rifkaki committed
3538 3539
                                    /> 
                                </div> : null : null}
d.arizona's avatar
d.arizona committed
3540
                                {/* {this.state.report != null ? String(this.state.report.label).toLocaleLowerCase().includes('summary') ? <div style={{ marginTop: 15, display: 'flex' }}>
d.arizona's avatar
d.arizona committed
3541 3542 3543 3544 3545 3546 3547 3548
                                    <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
3549
                                        style={{ width: 250 }}
d.arizona's avatar
d.arizona committed
3550 3551 3552
                                        renderInput={(params) => <TextField {...params} label="Months" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.month}
                                    />
d.arizona's avatar
d.arizona committed
3553
                                </div> : null : null} */}
Deni Rinaldi's avatar
Deni Rinaldi committed
3554
                            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3555
                            <div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3556
                                <div style={{ display: 'flex', justifyContent: 'space-between', padding: '0px 20px 10px 20px' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581
                                    <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
3582
                                {this.state.loading && loadingComponent}
Deni Rinaldi's avatar
Deni Rinaldi committed
3583
                                {this.state.previewTable && (
Deni Rinaldi's avatar
Deni Rinaldi committed
3584 3585 3586 3587
                                    <TableSubHolding
                                        width={this.props.width}
                                        height={this.props.height}
                                        open={this.props.open}
Riri Novita's avatar
Riri Novita committed
3588
                                        month={this.state.month.month_value}
Riri Novita's avatar
Riri Novita committed
3589 3590
                                        approvedMB={this.state.approveMB}
                                        approveMonthly={this.state.approveMonthly}
Deni Rinaldi's avatar
Deni Rinaldi committed
3591
                                        type={this.state.report ? this.state.report.value : 1}
Deni Rinaldi's avatar
Deni Rinaldi committed
3592 3593 3594 3595
                                        dataTable={this.state.dataTable}
                                        periode={this.state.periode ? this.state.periode.periode : null}
                                    />
                                )}
faisalhamdi's avatar
faisalhamdi committed
3596 3597 3598 3599 3600 3601 3602 3603
                            </div>
                        </Paper>
                    </div>
                </div>
            </div>
        )
    }
}