SubHolding.js 282 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: [
faisalhamdi's avatar
faisalhamdi committed
31 32 33 34 35 36 37 38 39 40
                { value: 2, label: 'DB Balance Sheet' },
                { value: 3, label: 'DB Profit & Loss' },
                { value: 1, label: 'DB Profit & Loss Detail' },
                { value: 4, label: 'DB Ratio' },
                { value: 5, label: 'DB Tax Planning' },
                { value: 21, label: 'DB Operating Indicator' },
                { value: 6, label: 'Cash Flow - Summary' },
                { value: 7, label: 'Balance Sheet - Summary' },
                { value: 8, label: 'Profit Loss - Summary' },
                { value: 9, label: 'Financial Ratio - Summary' },
faisalhamdi's avatar
faisalhamdi committed
41 42
                { value: 11, label: 'CAT Performance Quarterly' },
                { value: 10, 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
    }

    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
78 79 80 81 82 83 84 85 86
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
Deni Rinaldi's avatar
Deni Rinaldi committed
87
                    }
Riri Novita's avatar
Riri Novita committed
88 89
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error'})
Deni Rinaldi's avatar
Deni Rinaldi committed
90 91 92 93 94
                }
            }
        })
    }

Riri Novita's avatar
Riri Novita committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    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
117
            console.log(payload);
Riri Novita's avatar
Riri Novita committed
118 119 120
            console.log(response);
            if (response.data) {
                if (response.data.status == "success") {
Riri Novita's avatar
Riri Novita committed
121
                    console.log(response.data.data);
Riri Novita's avatar
Riri Novita committed
122
                    let approveMonthly = 
Riri Novita's avatar
Riri Novita committed
123 124
                    this.state.month.month_id == 1?
                        response.data.data.januari.is_approve :
Riri Novita's avatar
Riri Novita committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
                    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
145
                        response.data.data.december.is_approve 
Riri Novita's avatar
Riri Novita committed
146 147

                    this.setState({ approveMonthly })
Riri Novita's avatar
Riri Novita committed
148
                    }
Riri Novita's avatar
Riri Novita committed
149 150 151 152 153
                
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
154 155
    getCompanyActive() {
        api.create().getPerusahaanActive().then((response) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
156
            // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
            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
176 177 178 179
                    if (arrayBaru.length > 0) {
                        arrayBaru = arrayBaru.sort((a,b) => a.company_name.localeCompare(b.company_name))
                    }

Deni Rinaldi's avatar
Deni Rinaldi committed
180 181 182 183 184 185 186 187 188 189
                    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' }, () => {
d.arizona's avatar
d.arizona committed
190
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Deni Rinaldi's avatar
Deni Rinaldi committed
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
                            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
206
            console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
            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
222
                    let listMonths = []
Deni Rinaldi's avatar
Deni Rinaldi committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
                    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
243 244
                    console.log(this.state.lastPeriod)
                    let periode = (this.state.lastPeriod == "" ? String(Number(currentYear)) : this.state.latestPeriode)
d.arizona's avatar
d.arizona committed
245 246 247 248 249
                    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
250
                    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
251

Deni Rinaldi's avatar
Deni Rinaldi committed
252 253 254
                    // console.log(data)
                    // console.log(this.state.latestPeriode)
                    // console.log(periodeData)
d.arizona's avatar
d.arizona committed
255
                    console.log(index)
Deni Rinaldi's avatar
Deni Rinaldi committed
256
                    this.setState({ listPeriode: defaultProps, periode: index === -1 ? periodeData[0] : periodeData[index] }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
257
                        // this.getDataTable()
258
                        // this.getSubmission()
d.arizona's avatar
d.arizona committed
259
                        this.getMonth()
Deni Rinaldi's avatar
Deni Rinaldi committed
260 261 262 263 264 265
                        // if (this.state.isApprover === true) {
                        //     this.getCompanySubmitted()
                        // } else {
                        //     this.getRevision()
                        // }
                    })
Riri Novita's avatar
Riri Novita committed
266 267
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
268
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
269 270 271 272 273 274
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
275 276 277 278 279
                }
            }
        })
    }

d.arizona's avatar
d.arizona committed
280 281
    getMonth() {
        api.create().getMonthTransaction().then(response => {
d.arizona's avatar
d.arizona committed
282 283 284
            let dateNow = new Date()
            dateNow.setMonth(dateNow.getMonth() - 1);
            let month = format(dateNow, 'MMMM') 
d.arizona's avatar
d.arizona committed
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
            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
303 304 305 306
                        { name: 'Q1', value: '3' },
                        { name: 'Q2', value: '6' },
                        { name: 'Q3', value: '9' },
                        { name: 'Q4', value: '12' },
d.arizona's avatar
d.arizona committed
307 308
                    ]

d.arizona's avatar
d.arizona committed
309
                    let listUom = [{ value: 'Mio IDR' }]
d.arizona's avatar
d.arizona committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332

                    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
333 334
                        // this.getLastPeriod()
                        // this.getPeriode()
d.arizona's avatar
d.arizona committed
335 336 337 338
                        // }
                    })
                } else {
                    // this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
339
                    //     if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
340 341 342 343 344 345 346 347 348 349 350 351 352
                    //         setTimeout(() => {
                    //             localStorage.removeItem(Constant.TOKEN)
                    //             window.location.reload();
                    //         }, 1000);
                    //     }
                    // })
                }
            } else {
                // this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
            }
        })
    }

353 354 355 356 357 358
    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
359 360
        this.getApproveMB()
        this.getApproveMonthly()
361 362 363 364 365 366 367
        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
368
                                this.setState({ revisionType: item.revision }, () => {
369 370 371 372 373 374 375
                                    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
376
                                this.setState({ revisionType: item.revision }, () => {
377 378 379 380
                                    this.getSubmission()
                                })
                            }
                        })
381 382 383
                    } 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
384
                                this.setState({ revisionType: item.revision }, () => {
385 386 387 388
                                    this.getSubmission()
                                })
                            }
                        })
389
                    } else {
d.arizona's avatar
d.arizona committed
390
                        this.setState({ revisionType: 0 }, () => {
391 392 393
                            this.getSubmission()
                        })
                    }
faisalhamdi's avatar
faisalhamdi committed
394 395
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
396
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
faisalhamdi's avatar
faisalhamdi committed
397 398 399 400 401 402
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
403
                }
faisalhamdi's avatar
faisalhamdi committed
404
            } else {
d.arizona's avatar
d.arizona committed
405
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
406 407 408 409
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
410 411
    getSubmission() {
        this.setState({ loading: true })
Deni Rinaldi's avatar
Deni Rinaldi committed
412 413
        let payload = {
            "company_id": this.state.company.company_id,
Deni Rinaldi's avatar
Deni Rinaldi committed
414 415
            "periode": this.state.periode.periode,
            "is_approver": true
Deni Rinaldi's avatar
Deni Rinaldi committed
416
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
417
        api.create().getSubmission(payload).then(response => {
418
            console.log(response)
Deni Rinaldi's avatar
Deni Rinaldi committed
419 420 421 422 423 424 425 426 427
            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 {
Riri Novita's avatar
Riri Novita committed
428
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
429
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
430 431 432 433 434 435
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
436
                }
Riri Novita's avatar
Riri Novita committed
437 438
            } else {
                this.setState({ submissionID: null, loading: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
439 440 441 442 443 444 445
            }
        })
    }

    getDataTable() {
        let payload = {
            "report_id": this.state.report.value,
446
            "revision": this.state.revisionType,
Deni Rinaldi's avatar
Deni Rinaldi committed
447 448 449 450
            "periode": this.state.periode.periode,
            "company_id": this.state.company.company_id,
            "submission_id": this.state.submissionID
        }
idlanirined's avatar
idlanirined committed
451
        if (this.state.report.value === 1) {
452
            api.create().getAllReportPLDetail(payload).then(response => {
Riri Novita's avatar
Riri Novita committed
453
                console.log(response);
Riri Novita's avatar
Riri Novita committed
454
                console.log(payload);
idlanirined's avatar
idlanirined committed
455 456
                let dataTable = []
                if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
                    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
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
                                    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,
Riri Novita's avatar
Riri Novita committed
559 560 561 562 563 564 565 566 567 568 569 570
                                    item.profit_loss.ol_pa_january,
                                    item.profit_loss.ol_pa_february,
                                    item.profit_loss.ol_pa_march,
                                    item.profit_loss.ol_pa_april,
                                    item.profit_loss.ol_pa_may,
                                    item.profit_loss.ol_pa_june,
                                    item.profit_loss.ol_pa_july,
                                    item.profit_loss.ol_pa_august,
                                    item.profit_loss.ol_pa_september,
                                    item.profit_loss.ol_pa_october,
                                    item.profit_loss.ol_pa_november,
                                    item.profit_loss.ol_pa_december,
Riri Novita's avatar
Riri Novita committed
571
                                    // item.profit_loss.historialLast10YearList,
Riri Novita's avatar
Riri Novita committed
572
                                    item.profit_loss.history_last_nine_year,
Riri Novita's avatar
Riri Novita committed
573
                                    item.profit_loss.history_last_eight_year,
Riri Novita's avatar
Riri Novita committed
574 575 576 577 578 579 580 581
                                    item.profit_loss.history_last_seven_year,
                                    item.profit_loss.history_last_six_year,
                                    item.profit_loss.history_last_five_year,
                                    item.profit_loss.history_last_four_year,
                                    item.profit_loss.history_last_three_year,
                                    item.profit_loss.history_last_two_year,
                                    item.profit_loss.history_last_year,
                                    item.profit_loss.history_current_year,
Riri Novita's avatar
Riri Novita committed
582

faisalhamdi's avatar
faisalhamdi committed
583 584 585 586 587 588 589 590 591 592 593
                                ])
                            }
                            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
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
                            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,
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
                                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,
641
                                item.profit_loss.monthly_last_year_december,
Riri Novita's avatar
Riri Novita committed
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
                                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,
Riri Novita's avatar
Riri Novita committed
691 692 693 694 695 696 697 698 699 700 701 702
                                item.profit_loss.ol_pa_january,
                                item.profit_loss.ol_pa_february,
                                item.profit_loss.ol_pa_march,
                                item.profit_loss.ol_pa_april,
                                item.profit_loss.ol_pa_may,
                                item.profit_loss.ol_pa_june,
                                item.profit_loss.ol_pa_july,
                                item.profit_loss.ol_pa_august,
                                item.profit_loss.ol_pa_september,
                                item.profit_loss.ol_pa_october,
                                item.profit_loss.ol_pa_november,
                                item.profit_loss.ol_pa_december,
Riri Novita's avatar
Riri Novita committed
703
                                // item.profit_loss.historialLast10YearList
Riri Novita's avatar
Riri Novita committed
704
                                item.profit_loss.history_last_nine_year,
Riri Novita's avatar
Riri Novita committed
705
                                item.profit_loss.history_last_eight_year,
Riri Novita's avatar
Riri Novita committed
706 707 708 709 710 711 712 713
                                item.profit_loss.history_last_seven_year,
                                item.profit_loss.history_last_six_year,
                                item.profit_loss.history_last_five_year,
                                item.profit_loss.history_last_four_year,
                                item.profit_loss.history_last_three_year,
                                item.profit_loss.history_last_two_year,
                                item.profit_loss.history_last_year,
                                item.profit_loss.history_current_year,
idlanirined's avatar
idlanirined committed
714
                            ])
faisalhamdi's avatar
faisalhamdi committed
715 716 717 718 719 720
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
idlanirined's avatar
idlanirined committed
721
                            }
faisalhamdi's avatar
faisalhamdi committed
722
                        })
Riri Novita's avatar
Riri Novita committed
723
                        console.log(dataTable)
faisalhamdi's avatar
faisalhamdi committed
724 725
                        // this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
726

faisalhamdi's avatar
faisalhamdi committed
727 728 729 730 731 732
                        // this.setState({ dataTable }, () => {
                        //     console.log(this.state.dataTable)
                        //     this.getPLDetailMR(payload)
                        // })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
733
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
faisalhamdi's avatar
faisalhamdi committed
734 735 736 737 738 739 740
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
idlanirined's avatar
idlanirined committed
741 742 743 744 745
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
            })
        } else if (this.state.report.value === 2) {
746
            api.create().getAllReportBS(payload).then(response => {
faisalhamdi's avatar
faisalhamdi committed
747 748
                console.log(payload);
                console.log(response);
idlanirined's avatar
idlanirined committed
749
                let dataTable = []
Deni Rinaldi's avatar
Deni Rinaldi committed
750
                if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
                    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
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
                                    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,
Riri Novita's avatar
Riri Novita committed
854 855 856 857 858 859 860 861 862 863 864 865
                                    item.balance_sheet.ol_pa_january,
                                    item.balance_sheet.ol_pa_february,
                                    item.balance_sheet.ol_pa_march,
                                    item.balance_sheet.ol_pa_april,
                                    item.balance_sheet.ol_pa_may,
                                    item.balance_sheet.ol_pa_june,
                                    item.balance_sheet.ol_pa_july,
                                    item.balance_sheet.ol_pa_august,
                                    item.balance_sheet.ol_pa_september,
                                    item.balance_sheet.ol_pa_october,
                                    item.balance_sheet.ol_pa_november,
                                    item.balance_sheet.ol_pa_december,
Riri Novita's avatar
Riri Novita committed
866
                                    // item.balance_sheet.historial_last_10_years_list,
Riri Novita's avatar
Riri Novita committed
867
                                    item.balance_sheet.history_last_nine_year,
Riri Novita's avatar
Riri Novita committed
868
                                    item.balance_sheet.history_last_eight_year,
Riri Novita's avatar
Riri Novita committed
869 870 871 872 873 874 875 876
                                    item.balance_sheet.history_last_seven_year,
                                    item.balance_sheet.history_last_six_year,
                                    item.balance_sheet.history_last_five_year,
                                    item.balance_sheet.history_last_four_year,
                                    item.balance_sheet.history_last_three_year,
                                    item.balance_sheet.history_last_two_year,
                                    item.balance_sheet.history_last_year,
                                    item.balance_sheet.history_current_year,
Riri Novita's avatar
Riri Novita committed
877

Riri Novita's avatar
Riri Novita committed
878
                                    
faisalhamdi's avatar
faisalhamdi committed
879 880 881 882 883 884 885 886 887 888 889
                                ])
                            }
                            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
890 891 892 893 894 895 896 897
                            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
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912
                                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
913 914
                                item.order,
                                item.condition_it_should_be,
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938
                                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
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
                                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,
Riri Novita's avatar
Riri Novita committed
988 989 990 991 992 993 994 995 996 997 998 999
                                item.balance_sheet.ol_pa_january,
                                item.balance_sheet.ol_pa_february,
                                item.balance_sheet.ol_pa_march,
                                item.balance_sheet.ol_pa_april,
                                item.balance_sheet.ol_pa_may,
                                item.balance_sheet.ol_pa_june,
                                item.balance_sheet.ol_pa_july,
                                item.balance_sheet.ol_pa_august,
                                item.balance_sheet.ol_pa_september,
                                item.balance_sheet.ol_pa_october,
                                item.balance_sheet.ol_pa_november,
                                item.balance_sheet.ol_pa_december,
Riri Novita's avatar
Riri Novita committed
1000
                                // item.balance_sheet.historial_last_10_years_list
Riri Novita's avatar
Riri Novita committed
1001
                                item.balance_sheet.history_last_nine_year,
Riri Novita's avatar
Riri Novita committed
1002
                                item.balance_sheet.history_last_eight_year,
Riri Novita's avatar
Riri Novita committed
1003 1004 1005 1006 1007 1008 1009 1010 1011
                                item.balance_sheet.history_last_seven_year,
                                item.balance_sheet.history_last_six_year,
                                item.balance_sheet.history_last_five_year,
                                item.balance_sheet.history_last_four_year,
                                item.balance_sheet.history_last_three_year,
                                item.balance_sheet.history_last_two_year,
                                item.balance_sheet.history_last_year,
                                item.balance_sheet.history_current_year,

Deni Rinaldi's avatar
Deni Rinaldi committed
1012
                            ])
faisalhamdi's avatar
faisalhamdi committed
1013 1014 1015 1016 1017 1018
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
1019
                            }
faisalhamdi's avatar
faisalhamdi committed
1020 1021 1022 1023 1024 1025 1026 1027
                        })
                        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 }, () => {
d.arizona's avatar
d.arizona committed
1028
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
faisalhamdi's avatar
faisalhamdi committed
1029 1030 1031 1032
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
Deni Rinaldi's avatar
Deni Rinaldi committed
1033
                            }
faisalhamdi's avatar
faisalhamdi committed
1034 1035
                        })
                    }    
Riri Novita's avatar
Riri Novita committed
1036
                    
Deni Rinaldi's avatar
Deni Rinaldi committed
1037
                } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
1038
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
1039
                }
Riri Novita's avatar
Riri Novita committed
1040
                console.log(dataTable);
idlanirined's avatar
idlanirined committed
1041 1042
            })
        } else if (this.state.report.value === 3) {
Riri Novita's avatar
Riri Novita committed
1043 1044 1045 1046 1047
            let PLID = null
            let payloadID = {
                "periode": this.state.periode.periode,
                "company_id": this.state.company.company_id
            }
Riri Novita's avatar
Riri Novita committed
1048
            // console.log(payloadID);
Riri Novita's avatar
Riri Novita committed
1049
            api.create().getPLID(payloadID).then(response => {
Riri Novita's avatar
Riri Novita committed
1050
                console.log(response);
Riri Novita's avatar
Riri Novita committed
1051 1052
                if (response) {
                    PLID = response.data.data == null ? null : response.data.data.profit_loss_id 
Riri Novita's avatar
Riri Novita committed
1053
                    // PLID = response.data.data.profit_loss_id 
Riri Novita's avatar
Riri Novita committed
1054 1055 1056 1057
                } else {
                    PLID = null
                }
                this.setState({ PLID }, () => {
Riri Novita's avatar
Riri Novita committed
1058
                    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
1059 1060 1061 1062
                    console.log(payloads);
                    api.create().getReportPL(payloads).then(response => {
                        console.log(response);
                        if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
                            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,
Riri Novita's avatar
Riri Novita committed
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
                                        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,
                                        item.profit_loss.ol_pa_january,
                                        item.profit_loss.ol_pa_february,
                                        item.profit_loss.ol_pa_march,
                                        item.profit_loss.ol_pa_april,
                                        item.profit_loss.ol_pa_may,
                                        item.profit_loss.ol_pa_june,
                                        item.profit_loss.ol_pa_july,
                                        item.profit_loss.ol_pa_august,
                                        item.profit_loss.ol_pa_september,
                                        item.profit_loss.ol_pa_october,
                                        item.profit_loss.ol_pa_november,
                                        item.profit_loss.ol_pa_december,
Riri Novita's avatar
Riri Novita committed
1181
                                        item.profit_loss.history_current_year,
r.kurnia's avatar
r.kurnia committed
1182 1183 1184 1185 1186 1187 1188 1189 1190
                                        item.profit_loss.history_last_year,
                                        item.profit_loss.history_last_two_year,
                                        item.profit_loss.history_last_three_year,
                                        item.profit_loss.history_last_four_year,
                                        item.profit_loss.history_last_five_year,
                                        item.profit_loss.history_last_six_year,
                                        item.profit_loss.history_last_seven_year,
                                        item.profit_loss.history_last_eight_year,
                                        item.profit_loss.history_last_nine_year,
faisalhamdi's avatar
faisalhamdi committed
1191
                                    ])
idlanirined's avatar
idlanirined committed
1192

faisalhamdi's avatar
faisalhamdi committed
1193 1194 1195 1196 1197 1198
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
Riri Novita's avatar
Riri Novita committed
1199 1200
                                    }
                                }
faisalhamdi's avatar
faisalhamdi committed
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253
                                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,
Riri Novita's avatar
Riri Novita committed
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
                                        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,
                                        item.profit_loss.ol_pa_january,
                                        item.profit_loss.ol_pa_february,
                                        item.profit_loss.ol_pa_march,
                                        item.profit_loss.ol_pa_april,
                                        item.profit_loss.ol_pa_may,
                                        item.profit_loss.ol_pa_june,
                                        item.profit_loss.ol_pa_july,
                                        item.profit_loss.ol_pa_august,
                                        item.profit_loss.ol_pa_september,
                                        item.profit_loss.ol_pa_october,
                                        item.profit_loss.ol_pa_november,
                                        item.profit_loss.ol_pa_december,
Riri Novita's avatar
Riri Novita committed
1315
                                        item.profit_loss.history_current_year,
r.kurnia's avatar
r.kurnia committed
1316 1317 1318 1319 1320 1321 1322 1323 1324
                                        item.profit_loss.history_last_year,
                                        item.profit_loss.history_last_two_year,
                                        item.profit_loss.history_last_three_year,
                                        item.profit_loss.history_last_four_year,
                                        item.profit_loss.history_last_five_year,
                                        item.profit_loss.history_last_six_year,
                                        item.profit_loss.history_last_seven_year,
                                        item.profit_loss.history_last_eight_year,
                                        item.profit_loss.history_last_nine_year,
faisalhamdi's avatar
faisalhamdi committed
1325 1326 1327 1328 1329 1330 1331
                                    ])
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
Riri Novita's avatar
Riri Novita committed
1332
                                    }
faisalhamdi's avatar
faisalhamdi committed
1333 1334 1335 1336 1337 1338 1339 1340
                                })
                                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 }, () => {
d.arizona's avatar
d.arizona committed
1341
                                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
faisalhamdi's avatar
faisalhamdi committed
1342 1343 1344 1345 1346 1347 1348
                                        setTimeout(() => {
                                            localStorage.removeItem(Constant.TOKEN)
                                            window.location.reload();
                                        }, 1000);
                                    }
                                })
                            }
Riri Novita's avatar
Riri Novita committed
1349 1350
                        } else {
                            this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
1351 1352
                        }
                    })
Riri Novita's avatar
Riri Novita committed
1353
                })
idlanirined's avatar
idlanirined committed
1354
            })
faisalhamdi's avatar
faisalhamdi committed
1355
        } else if (this.state.report.value === 4) {
Riri Novita's avatar
Riri Novita committed
1356 1357 1358 1359 1360 1361
            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
1362
                console.log(response);
Riri Novita's avatar
Riri Novita committed
1363 1364 1365 1366 1367 1368
                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
1369
                    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
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387
                    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,
Riri Novita's avatar
Riri Novita committed
1388
                                            0,
rifkaki's avatar
rifkaki committed
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
                                            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
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414
                                            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
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426
                                            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
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497
                                            item.ratio.ro_ol_january,
                                            item.ratio.ro_ol_february,
                                            item.ratio.ro_ol_march,
                                            item.ratio.ro_ol_april,
                                            item.ratio.ro_ol_may,
                                            item.ratio.ro_ol_june,
                                            item.ratio.ro_ol_july,
                                            item.ratio.ro_ol_august,
                                            item.ratio.ro_ol_september,
                                            item.ratio.ro_ol_october,
                                            item.ratio.ro_ol_november,
                                            item.ratio.ro_ol_december,
                                            item.ratio.q1_january,
                                            item.ratio.q1_february,
                                            item.ratio.q1_march,
                                            item.ratio.q1_april,
                                            item.ratio.q1_may,
                                            item.ratio.q1_june,
                                            item.ratio.q1_july,
                                            item.ratio.q1_august,
                                            item.ratio.q1_september,
                                            item.ratio.q1_october,
                                            item.ratio.q1_november,
                                            item.ratio.q1_december,
                                            item.ratio.q2_january,
                                            item.ratio.q2_february,
                                            item.ratio.q2_march,
                                            item.ratio.q2_april,
                                            item.ratio.q2_may,
                                            item.ratio.q2_june,
                                            item.ratio.q2_july,
                                            item.ratio.q2_august,
                                            item.ratio.q2_september,
                                            item.ratio.q2_october,
                                            item.ratio.q2_november,
                                            item.ratio.q2_december,
                                            item.ratio.q3_january,
                                            item.ratio.q3_february,
                                            item.ratio.q3_march,
                                            item.ratio.q3_april,
                                            item.ratio.q3_may,
                                            item.ratio.q3_june,
                                            item.ratio.q3_july,
                                            item.ratio.q3_august,
                                            item.ratio.q3_september,
                                            item.ratio.q3_october,
                                            item.ratio.q3_november,
                                            item.ratio.q3_december,
                                            item.ratio.ol_january,
                                            item.ratio.ol_february,
                                            item.ratio.ol_march,
                                            item.ratio.ol_april,
                                            item.ratio.ol_may,
                                            item.ratio.ol_june,
                                            item.ratio.ol_july,
                                            item.ratio.ol_august,
                                            item.ratio.ol_september,
                                            item.ratio.ol_october,
                                            item.ratio.ol_november,
                                            item.ratio.ol_december,
                                            item.ratio.history_last_nine_year,
                                            item.ratio.history_last_eight_year,
                                            item.ratio.history_last_seven_year,
                                            item.ratio.history_last_six_year,
                                            item.ratio.history_last_five_year,
                                            item.ratio.history_last_four_year,
                                            item.ratio.history_last_three_year,
                                            item.ratio.history_last_two_year,
                                            item.ratio.history_last_year,
                                            item.ratio.history_current_year,

Riri Novita's avatar
Riri Novita committed
1498
                                        ])
faisalhamdi's avatar
faisalhamdi committed
1499
                                }
Riri Novita's avatar
Riri Novita committed
1500 1501 1502 1503 1504 1505 1506
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
                                    }
faisalhamdi's avatar
faisalhamdi committed
1507
                                }
Riri Novita's avatar
Riri Novita committed
1508 1509 1510 1511 1512 1513 1514 1515 1516
                                res.map((item, index) => {
                                    dataTable.push([
                                        item.type_report_id,
                                        item.id,
                                        item.parent,
                                        item.formula,
                                        item.level,
                                        item.description,
                                        item.oum,
Riri Novita's avatar
Riri Novita committed
1517
                                        0,
rifkaki's avatar
rifkaki committed
1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531
                                        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
1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543
                                        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
1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
                                        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
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625
                                        item.ratio.ro_ol_january,
                                        item.ratio.ro_ol_february,
                                        item.ratio.ro_ol_march,
                                        item.ratio.ro_ol_april,
                                        item.ratio.ro_ol_may,
                                        item.ratio.ro_ol_june,
                                        item.ratio.ro_ol_july,
                                        item.ratio.ro_ol_august,
                                        item.ratio.ro_ol_september,
                                        item.ratio.ro_ol_october,
                                        item.ratio.ro_ol_november,
                                        item.ratio.ro_ol_december,
                                        item.ratio.q1_january,
                                        item.ratio.q1_february,
                                        item.ratio.q1_march,
                                        item.ratio.q1_april,
                                        item.ratio.q1_may,
                                        item.ratio.q1_june,
                                        item.ratio.q1_july,
                                        item.ratio.q1_august,
                                        item.ratio.q1_september,
                                        item.ratio.q1_october,
                                        item.ratio.q1_november,
                                        item.ratio.q1_december,
                                        item.ratio.q2_january,
                                        item.ratio.q2_february,
                                        item.ratio.q2_march,
                                        item.ratio.q2_april,
                                        item.ratio.q2_may,
                                        item.ratio.q2_june,
                                        item.ratio.q2_july,
                                        item.ratio.q2_august,
                                        item.ratio.q2_september,
                                        item.ratio.q2_october,
                                        item.ratio.q2_november,
                                        item.ratio.q2_december,
                                        item.ratio.q3_january,
                                        item.ratio.q3_february,
                                        item.ratio.q3_march,
                                        item.ratio.q3_april,
                                        item.ratio.q3_may,
                                        item.ratio.q3_june,
                                        item.ratio.q3_july,
                                        item.ratio.q3_august,
                                        item.ratio.q3_september,
                                        item.ratio.q3_october,
                                        item.ratio.q3_november,
                                        item.ratio.q3_december,
                                        item.ratio.ol_january,
                                        item.ratio.ol_february,
                                        item.ratio.ol_march,
                                        item.ratio.ol_april,
                                        item.ratio.ol_may,
                                        item.ratio.ol_june,
                                        item.ratio.ol_july,
                                        item.ratio.ol_august,
                                        item.ratio.ol_september,
                                        item.ratio.ol_october,
                                        item.ratio.ol_november,
                                        item.ratio.ol_december,
                                        item.ratio.history_last_nine_year,
                                        item.ratio.history_last_eight_year,
                                        item.ratio.history_last_seven_year,
                                        item.ratio.history_last_six_year,
                                        item.ratio.history_last_five_year,
                                        item.ratio.history_last_four_year,
                                        item.ratio.history_last_three_year,
                                        item.ratio.history_last_two_year,
                                        item.ratio.history_last_year,
                                        item.ratio.history_current_year,
Riri Novita's avatar
Riri Novita committed
1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642
                                    ])
                                    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 }, () => {
d.arizona's avatar
d.arizona committed
1643
                                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
1644 1645 1646 1647 1648 1649
                                        setTimeout(() => {
                                            localStorage.removeItem(Constant.TOKEN)
                                            window.location.reload();
                                        }, 1000);
                                    }
                                })
faisalhamdi's avatar
faisalhamdi committed
1650
                            }
Riri Novita's avatar
Riri Novita committed
1651 1652 1653 1654 1655
                        } else {
                            this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                        }
                    })
                })
faisalhamdi's avatar
faisalhamdi committed
1656
            })
d.arizona's avatar
d.arizona committed
1657
        } else if (this.state.report.value === 5) {
rifkaki's avatar
rifkaki committed
1658
            api.create().getReportTP(payload).then(response => {
rifkaki's avatar
rifkaki committed
1659
                console.log(payload);
d.arizona's avatar
d.arizona committed
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669
                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
1670 1671 1672 1673 1674 1675
                                    // 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
1676 1677 1678 1679 1680
                                    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
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692
                                    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
1693
                                    item.order,
rifkaki's avatar
rifkaki committed
1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
                                    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
1706
                                    item.tax_planning_report.monthly_full_year,
d.arizona's avatar
d.arizona committed
1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719
                                ])
                            }
                            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
1720 1721 1722 1723 1724 1725
                                // 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
1726 1727 1728 1729 1730
                                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
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742
                                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
1743
                                item.order,
rifkaki's avatar
rifkaki committed
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755
                                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
1756
                                item.tax_planning_report.monthly_full_year,
d.arizona's avatar
d.arizona committed
1757 1758 1759 1760 1761 1762 1763 1764 1765
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
rifkaki's avatar
rifkaki committed
1766
                        console.log(dataTable)
rifkaki's avatar
rifkaki committed
1767 1768 1769 1770
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                        // this.setState({ dataTable }, () => {
                        //     this.getTaxPlanMR(payload)
                        // })
d.arizona's avatar
d.arizona committed
1771
                    } else {
d.arizona's avatar
d.arizona committed
1772
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
1773
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
1774 1775 1776 1777 1778 1779
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
d.arizona's avatar
d.arizona committed
1780
                    }
d.arizona's avatar
d.arizona committed
1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797
                } 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
1798
                        OPID = null
d.arizona's avatar
d.arizona committed
1799
                    }
d.arizona's avatar
d.arizona committed
1800
                    this.setState({ OPID }, () => {
d.arizona's avatar
d.arizona committed
1801 1802 1803 1804 1805 1806
                        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
1807

1808
                        api.create().getAllReportOI(payloadOI).then(response => {
d.arizona's avatar
d.arizona committed
1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840
                            // 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),
1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853
                                                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
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886
                                            ])
                                        }
                                        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),
1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899
                                            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
1900 1901 1902 1903 1904 1905 1906 1907 1908
                                        ])
                                        if (item.children !== null) {
                                            if (item.children.length > 0) {
                                                item.children.map((items, indexs) => {
                                                    handlePushChild(items)
                                                })
                                            }
                                        }
                                    })
d.arizona's avatar
d.arizona committed
1909
                                    this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
1910 1911 1912 1913 1914

                                    // this.setState({ dataTable }, () => {
                                    //     console.log(this.state.dataTable)
                                    //     this.getOIMR(payloadOI)
                                    // })
d.arizona's avatar
d.arizona committed
1915
                                } else {
d.arizona's avatar
d.arizona committed
1916
                                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
1917
                                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
1918 1919 1920 1921 1922 1923
                                            setTimeout(() => {
                                                localStorage.removeItem(Constant.TOKEN)
                                                window.location.reload();
                                            }, 1000);
                                        }
                                    })
d.arizona's avatar
d.arizona committed
1924
                                }
d.arizona's avatar
d.arizona committed
1925 1926 1927 1928 1929
                            } else {
                                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                            }
                        })
                    })
d.arizona's avatar
d.arizona committed
1930 1931
                }
            })
d.arizona's avatar
d.arizona committed
1932
        } else if (this.state.report.value === 6) {
d.arizona's avatar
d.arizona committed
1933
            let dbSumaCF = []
d.arizona's avatar
d.arizona committed
1934
            let paylodCF = { ...payload, months: this.state.month.month_id }
d.arizona's avatar
d.arizona committed
1935
            api.create().getReportCFSuma(paylodCF).then(response => {
d.arizona's avatar
d.arizona committed
1936
                console.log(response)
d.arizona's avatar
d.arizona committed
1937 1938 1939
                if (response.data) {
                    if (response.data.status === 'success') {
                        let res = response.data.data
d.arizona's avatar
d.arizona committed
1940
                        console.log(res)
d.arizona's avatar
d.arizona committed
1941
                        const handlePushChild = (item) => {
rifkaki's avatar
rifkaki committed
1942
                            let indexIDzz = dbSumaCF.findIndex((val) => val[0] === item.id)
d.arizona's avatar
d.arizona committed
1943
                            if (indexIDzz === -1) {
rifkaki's avatar
rifkaki committed
1944 1945
                                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
1946
                                console.log(mtd)
rifkaki's avatar
rifkaki committed
1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974
                                // 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
1975

rifkaki's avatar
rifkaki committed
1976 1977
                                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
1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989
                                // 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
1990

rifkaki's avatar
rifkaki committed
1991 1992
                                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
1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004
                                // 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
2005 2006

                                dbSumaCF.push([
d.arizona's avatar
d.arizona committed
2007
                                    item.id,
d.arizona's avatar
d.arizona committed
2008 2009
                                    item.cash_flow.mtd_actual,
                                    item.cash_flow.mtd,
d.arizona's avatar
d.arizona committed
2010
                                    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
2011 2012 2013
                                    item.cash_flow.mtd_last_year,
                                    item.cash_flow.ytd_actual,
                                    item.cash_flow.ytd,
d.arizona's avatar
d.arizona committed
2014
                                    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
2015
                                    // isNaN(persenYtd)? 0 : persenYtd * 100,
d.arizona's avatar
d.arizona committed
2016 2017 2018
                                    item.cash_flow.ytd_last_year,
                                    item.cash_flow.quarter_actual,
                                    item.cash_flow.quarter,
d.arizona's avatar
d.arizona committed
2019
                                    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
2020
                                    // isNaN(persenQuarter)? 0 : persenQuarter * 100,
d.arizona's avatar
d.arizona committed
2021 2022 2023
                                    item.cash_flow.quarter_last_year,
                                    item.cash_flow.fy_actual,
                                    item.cash_flow.fy,
d.arizona's avatar
d.arizona committed
2024
                                    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
2025
                                    // isNaN(persenFy)? 0 : persenFy * 100,
d.arizona's avatar
d.arizona committed
2026
                                    item.cash_flow.fy_last_year,
d.arizona's avatar
d.arizona committed
2027 2028 2029 2030 2031 2032 2033 2034 2035 2036
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
d.arizona's avatar
d.arizona committed
2037
                        res.map((item, index) => {
rifkaki's avatar
rifkaki committed
2038 2039 2040
                            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
2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067
                            // 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
2068

rifkaki's avatar
rifkaki committed
2069 2070
                            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
2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082
                            // 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
2083

rifkaki's avatar
rifkaki committed
2084 2085
                            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
2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097
                            // 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
2098 2099

                            dbSumaCF.push([
d.arizona's avatar
d.arizona committed
2100
                                item.id,
d.arizona's avatar
d.arizona committed
2101 2102
                                item.cash_flow.mtd_actual,
                                item.cash_flow.mtd,
d.arizona's avatar
d.arizona committed
2103
                                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
2104 2105 2106
                                item.cash_flow.mtd_last_year,
                                item.cash_flow.ytd_actual,
                                item.cash_flow.ytd,
d.arizona's avatar
d.arizona committed
2107
                                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
2108
                                // isNaN(persenYtd)? 0 : persenYtd * 100,
d.arizona's avatar
d.arizona committed
2109 2110 2111
                                item.cash_flow.ytd_last_year,
                                item.cash_flow.quarter_actual,
                                item.cash_flow.quarter,
d.arizona's avatar
d.arizona committed
2112
                                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
2113
                                // isNaN(persenQuarter)? 0 : persenQuarter * 100,
d.arizona's avatar
d.arizona committed
2114 2115 2116
                                item.cash_flow.quarter_last_year,
                                item.cash_flow.fy_actual,
                                item.cash_flow.fy,
d.arizona's avatar
d.arizona committed
2117
                                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
2118
                                // isNaN(persenFy)? 0 : persenFy * 100,
d.arizona's avatar
d.arizona committed
2119
                                item.cash_flow.fy_last_year,
d.arizona's avatar
d.arizona committed
2120 2121 2122 2123 2124 2125 2126 2127 2128
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
d.arizona's avatar
d.arizona committed
2129
                        console.log(dbSumaCF)
d.arizona's avatar
d.arizona committed
2130
                        this.setState({ dbSumaCF }, () => {
d.arizona's avatar
d.arizona committed
2131 2132 2133 2134 2135 2136 2137
                            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
2138
                                        console.log(res)
d.arizona's avatar
d.arizona committed
2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167
                                        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
2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180
                                                    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
2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217
                                                ])
                                            }
                                            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
2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230
                                                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
2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241
                                            ])
                                            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
2242
                                            this.getCFSumaMR(paylodCF, dbSumaCF)
d.arizona's avatar
d.arizona committed
2243
                                        })
d.arizona's avatar
d.arizona committed
2244
                                    } else {
d.arizona's avatar
d.arizona committed
2245
                                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
2246
                                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
2247 2248 2249 2250 2251 2252
                                                setTimeout(() => {
                                                    localStorage.removeItem(Constant.TOKEN)
                                                    window.location.reload();
                                                }, 1000);
                                            }
                                        })
d.arizona's avatar
d.arizona committed
2253
                                    }
d.arizona's avatar
d.arizona committed
2254 2255 2256
                                } else {
                                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                                }
Riri Novita's avatar
Riri Novita committed
2257
                                console.log(dataTable);
d.arizona's avatar
d.arizona committed
2258
                            })
d.arizona's avatar
d.arizona committed
2259
                        })
d.arizona's avatar
d.arizona committed
2260
                    } else {
d.arizona's avatar
d.arizona committed
2261
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
2262
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
2263 2264 2265 2266 2267 2268
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
d.arizona's avatar
d.arizona committed
2269
                    }
d.arizona's avatar
d.arizona committed
2270 2271 2272 2273
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                }
            })
Riri Novita's avatar
Riri Novita committed
2274
        } else if (this.state.report.value === 7) {
faisalhamdi's avatar
faisalhamdi committed
2275 2276 2277 2278
            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
2279
                console.log(response);
faisalhamdi's avatar
faisalhamdi committed
2280
                if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292
                    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) {
2293
                                    if (parseFloat(mtd_actual) < parseFloat(mtd_mb)) {
faisalhamdi's avatar
faisalhamdi committed
2294 2295 2296 2297 2298 2299 2300 2301 2302
                                        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) {
2303
                                    if (parseFloat(mtd_actual) < parseFloat(mtd_ol)) {
faisalhamdi's avatar
faisalhamdi committed
2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346
                                        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) {
2347
                                if (parseFloat(mtd_actual) < parseFloat(mtd_mb)) {
faisalhamdi's avatar
faisalhamdi committed
2348 2349 2350 2351 2352 2353 2354 2355 2356
                                    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) {
2357
                                if (parseFloat(mtd_actual) < parseFloat(mtd_ol)) {
faisalhamdi's avatar
faisalhamdi committed
2358 2359 2360 2361 2362 2363 2364 2365 2366
                                    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
2367 2368 2369 2370 2371 2372
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
faisalhamdi's avatar
faisalhamdi committed
2373
                                item.balance_sheet.mtd_last_month,
d.arizona's avatar
d.arizona committed
2374 2375
                                item.balance_sheet.mtd_actual,
                                item.balance_sheet.mtd_mb,
faisalhamdi's avatar
faisalhamdi committed
2376
                                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
2377
                                item.balance_sheet.mtd_ol,
faisalhamdi's avatar
faisalhamdi committed
2378
                                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
2379
                                item.balance_sheet.mtd_last_year,
faisalhamdi's avatar
faisalhamdi committed
2380
                                item.balance_sheet.forecast_next_year,
d.arizona's avatar
d.arizona committed
2381
                                item.balance_sheet.forecast_more_year,
faisalhamdi's avatar
faisalhamdi committed
2382 2383
                                item.order
                            ])
faisalhamdi's avatar
faisalhamdi committed
2384 2385 2386 2387 2388 2389
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
faisalhamdi's avatar
faisalhamdi committed
2390
                            }
faisalhamdi's avatar
faisalhamdi committed
2391 2392
                        })
                        this.setState({ dataTable: dbSumaBS, previewTable: true, loading: false, previewDownload: true })
d.arizona's avatar
d.arizona committed
2393
                        console.log(this.state.dataTable)
faisalhamdi's avatar
faisalhamdi committed
2394 2395
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
2396
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
faisalhamdi's avatar
faisalhamdi committed
2397 2398 2399 2400 2401 2402 2403
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }                    
faisalhamdi's avatar
faisalhamdi committed
2404
                } else {
faisalhamdi's avatar
faisalhamdi committed
2405
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
faisalhamdi's avatar
faisalhamdi committed
2406
                }
Riri Novita's avatar
Riri Novita committed
2407 2408 2409
            })

        } else if (this.state.report.value === 8) {
Riri Novita's avatar
Riri Novita committed
2410
            let dbSumaPL = []
faisalhamdi's avatar
faisalhamdi committed
2411
            let payloadPL = {...payload, report_id: 28, months: this.state.month.month_id}
Riri Novita's avatar
Riri Novita committed
2412
            api.create().getReportPLSuma(payloadPL).then(response => {
Riri Novita's avatar
Riri Novita committed
2413
                console.log(response);
Riri Novita's avatar
Riri Novita committed
2414 2415 2416 2417 2418 2419 2420
                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) {
faisalhamdi's avatar
faisalhamdi committed
2421
                                let month = this.state.month.month_value;
Riri Novita's avatar
Riri Novita committed
2422 2423 2424
                                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
2425 2426 2427
                                let persenMtd = 0
                                if (mtd_mb  < 0) {
                                    if (mtd_actual >= mtd_mb) {
Riri Novita's avatar
Riri Novita committed
2428
                                        persenMtd = (mtd_mb - mtd_actual) / mtd_mb + 1  
Riri Novita's avatar
Riri Novita committed
2429
                                    }  else {
Riri Novita's avatar
Riri Novita committed
2430
                                        persenMtd = (mtd_mb - mtd_actual) / mtd_mb 
Riri Novita's avatar
Riri Novita committed
2431 2432 2433
                                    }
                                }
                                else {
Riri Novita's avatar
Riri Novita committed
2434
                                    persenMtd = mtd_actual / mtd_mb
Riri Novita's avatar
Riri Novita committed
2435 2436
                                }

Riri Novita's avatar
Riri Novita committed
2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449
                                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
2450 2451 2452 2453 2454 2455
                                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
2456
                                        persenYtdMB = (ytd_mb - ytd_actual) / ytd_mb + 1  
Riri Novita's avatar
Riri Novita committed
2457
                                    }  else {
Riri Novita's avatar
Riri Novita committed
2458
                                        persenYtdMB = (ytd_mb - ytd_actual) / ytd_mb 
Riri Novita's avatar
Riri Novita committed
2459 2460 2461
                                    }
                                }
                                else {
Riri Novita's avatar
Riri Novita committed
2462
                                    persenYtdMB = ytd_actual / ytd_mb 
Riri Novita's avatar
Riri Novita committed
2463 2464 2465 2466 2467
                                }

                                let persenYtdLY = 0
                                if (ytd_last_year  < 0) {
                                    if (ytd_actual >= ytd_last_year) {
Riri Novita's avatar
Riri Novita committed
2468 2469 2470 2471 2472 2473 2474 2475 2476
                                        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 
                                }

faisalhamdi's avatar
faisalhamdi committed
2477 2478 2479 2480 2481 2482
                                // let q1_actual = item.profit_loss.q1_actual == ''? 0 : Number(item.profit_loss.q1_actual)
                                let q_actual = month == "Mar" ? item.profit_loss.q1_actual == ''? 0 : Number(item.profit_loss.q1_actual) : month == "Jun" ? item.profit_loss.q2_actual == ''? 0 : Number(item.profit_loss.q2_actual) : month == "Sep" ? item.profit_loss.q3_actual == ''? 0 : Number(item.profit_loss.q3_actual) : 0
                                // let q1_mb = item.profit_loss.q1_mb == ''? 0 : Number(item.profit_loss.q1_mb)
                                let q_mb = month == "Mar" ? item.profit_loss.q1_mb == ''? 0 : Number(item.profit_loss.q1_mb) : month == "Jun" ? item.profit_loss.q2_mb == ''? 0 : Number(item.profit_loss.q2_mb) : month == "Sep" ? item.profit_loss.q3_mb == ''? 0 : Number(item.profit_loss.q3_mb) : 0
                                // let q1_last_year = item.profit_loss.q1_last_year == ''? 0 : Number(item.profit_loss.q1_last_year)
                                let q_last_year = month == "Mar" ? item.profit_loss.q1_last_year == ''? 0 : Number(item.profit_loss.q1_last_year) : month == "Jun" ? item.profit_loss.q2_last_year == ''? 0 : Number(item.profit_loss.q2_last_year) : month == "Sep" ? item.profit_loss.q3_last_year == ''? 0 : Number(item.profit_loss.q3_last_year) : 0
Riri Novita's avatar
Riri Novita committed
2483
                                let persenQuarterMB = 0
faisalhamdi's avatar
faisalhamdi committed
2484 2485 2486
                                if (q_mb  < 0) {
                                    if (q_actual >= q_mb) {
                                        persenQuarterMB = (q_mb - q_actual) / q_mb + 1  
Riri Novita's avatar
Riri Novita committed
2487
                                    }  else {
faisalhamdi's avatar
faisalhamdi committed
2488
                                        persenQuarterMB = (q_mb - q_actual) / q_mb 
Riri Novita's avatar
Riri Novita committed
2489 2490 2491
                                    }
                                }
                                else {
faisalhamdi's avatar
faisalhamdi committed
2492
                                    persenQuarterMB = q_actual / q_mb 
Riri Novita's avatar
Riri Novita committed
2493
                                }
Riri Novita's avatar
Riri Novita committed
2494

Riri Novita's avatar
Riri Novita committed
2495
                                let persenQuarterLY = 0
faisalhamdi's avatar
faisalhamdi committed
2496 2497 2498
                                if (q_last_year  < 0) {
                                    if (q_actual >= q_last_year) {
                                        persenQuarterLY = (q_last_year - q_actual) / q_last_year + 1  
Riri Novita's avatar
Riri Novita committed
2499
                                    }  else {
faisalhamdi's avatar
faisalhamdi committed
2500
                                        persenQuarterLY = (q_last_year - q_actual) / q_last_year 
Riri Novita's avatar
Riri Novita committed
2501 2502 2503
                                    }
                                }
                                else {
faisalhamdi's avatar
faisalhamdi committed
2504
                                    persenQuarterLY = q_actual / q_last_year 
Riri Novita's avatar
Riri Novita committed
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
                                }

                                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
2546

Riri Novita's avatar
Riri Novita committed
2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565
                                // if (item.id === 3297327) {
                                //     console.log(fy_actual);
                                //     console.log(fy_last_year);
                                //     console.log(persenFyLY);
                                // }

                                // let persenFyOLMB = Number(fy_ol/fy_mb)
                                // 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 
                                // }

                                let persenFyOLMB = 0
Riri Novita's avatar
Riri Novita committed
2566 2567
                                if (fy_mb  < 0) {
                                    if (fy_ol >= fy_mb) {
Riri Novita's avatar
Riri Novita committed
2568
                                        persenFyOLMB = (fy_mb - fy_ol) / fy_mb + 1  
Riri Novita's avatar
Riri Novita committed
2569
                                    }  else {
Riri Novita's avatar
Riri Novita committed
2570
                                        persenFyOLMB = (fy_mb - fy_ol) / fy_mb 
Riri Novita's avatar
Riri Novita committed
2571 2572 2573
                                    }
                                }
                                else {
Riri Novita's avatar
Riri Novita committed
2574
                                    persenFyOLMB = fy_ol / fy_mb 
Riri Novita's avatar
Riri Novita committed
2575
                                }
Riri Novita's avatar
Riri Novita committed
2576 2577

                                dbSumaPL.push([
Riri Novita's avatar
Riri Novita committed
2578
                                    item.type_report_id,
Riri Novita's avatar
Riri Novita committed
2579
                                    item.id,
Riri Novita's avatar
Riri Novita committed
2580 2581 2582 2583
                                    item.parent,
                                    item.formula,
                                    item.level,
                                    item.description,
Riri Novita's avatar
Riri Novita committed
2584
                                    item.profit_loss.mtd_actual,
Riri Novita's avatar
Riri Novita committed
2585 2586
                                    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
2587
                                    item.profit_loss.mtd_last_year,
Riri Novita's avatar
Riri Novita committed
2588
                                    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
2589
                                    item.profit_loss.ytd_actual,
Riri Novita's avatar
Riri Novita committed
2590 2591
                                    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
2592
                                    item.profit_loss.ytd_last_year,
Riri Novita's avatar
Riri Novita committed
2593
                                    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),
faisalhamdi's avatar
faisalhamdi committed
2594 2595 2596 2597 2598 2599 2600
                                    month == "Mar" ? item.profit_loss.q1_actual : month = "Jun" ? item.profit_loss.q2_actual : month = "Sep" ? item.profit_loss.q3_actual : 0,
                                    month == "Mar" ? item.profit_loss.q1_mb : month = "Jun" ? item.profit_loss.q2_mb : month = "Sep" ? item.profit_loss.q3_mb : 0,
                                    isNaN(persenQuarterMB) || persenQuarterMB == 'Infinity' || persenQuarterMB == '-Infinity'? (q_mb == '' || q_mb == 0? -0 : 0) : (q_mb == '' || q_mb == 0? persenQuarterMB * -100 : persenQuarterMB * 100),
                                    // 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),
                                    month == "Mar" ? item.profit_loss.q1_last_year : month = "Jun" ? item.profit_loss.q2_last_year : month = "Sep" ? item.profit_loss.q3_last_year : 0,
                                    isNaN(persenQuarterLY) || persenQuarterLY == 'Infinity' || persenQuarterLY == '-Infinity'? (q_last_year == '' || q_last_year == 0? -0 : 0) : (q_last_year == '' || q_last_year == 0? persenQuarterLY * -100 : persenQuarterLY * 100),
                                    // 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
2601
                                    item.profit_loss.fy_actual,
Riri Novita's avatar
Riri Novita committed
2602 2603 2604 2605
                                    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
2606
                                    item.profit_loss.fy_last_year,
Riri Novita's avatar
Riri Novita committed
2607 2608 2609
                                    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
2610 2611
                                    item.profit_loss.forecast_more_year,
                                    item.profit_loss.notes,
Riri Novita's avatar
Riri Novita committed
2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
                        res.map((item,index) => {
faisalhamdi's avatar
faisalhamdi committed
2623
                            let month = this.state.month.month_value;
Riri Novita's avatar
Riri Novita committed
2624 2625
                            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
2626
                            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
2627 2628 2629
                            let persenMtd = 0
                            if (mtd_mb  < 0) {
                                if (mtd_actual >= mtd_mb) {
Riri Novita's avatar
Riri Novita committed
2630
                                    persenMtd = (mtd_mb - mtd_actual) / mtd_mb + 1  
Riri Novita's avatar
Riri Novita committed
2631
                                }  else {
Riri Novita's avatar
Riri Novita committed
2632
                                    persenMtd = (mtd_mb - mtd_actual) / mtd_mb 
Riri Novita's avatar
Riri Novita committed
2633 2634
                                }
                            }
Riri Novita's avatar
Riri Novita committed
2635 2636
                            else {
                                persenMtd = mtd_actual / mtd_mb
Riri Novita's avatar
Riri Novita committed
2637
                            }
Riri Novita's avatar
Riri Novita committed
2638

Riri Novita's avatar
Riri Novita committed
2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677
                            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
2678

faisalhamdi's avatar
faisalhamdi committed
2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708
                            // 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 q_actual = month == "Mar" ? item.profit_loss.q1_actual == ''? 0 : Number(item.profit_loss.q1_actual) : month == "Jun" ? item.profit_loss.q2_actual == ''? 0 : Number(item.profit_loss.q2_actual) : month == "Sep" ? item.profit_loss.q3_actual == ''? 0 : Number(item.profit_loss.q3_actual) : 0
                            let q_mb = month == "Mar" ? item.profit_loss.q1_mb == ''? 0 : Number(item.profit_loss.q1_mb) : month == "Jun" ? item.profit_loss.q2_mb == ''? 0 : Number(item.profit_loss.q2_mb) : month == "Sep" ? item.profit_loss.q3_mb == ''? 0 : Number(item.profit_loss.q3_mb) : 0
                            let q_last_year = month == "Mar" ? item.profit_loss.q1_last_year == ''? 0 : Number(item.profit_loss.q1_last_year) : month == "Jun" ? item.profit_loss.q2_last_year == ''? 0 : Number(item.profit_loss.q2_last_year) : month == "Sep" ? item.profit_loss.q3_last_year == ''? 0 : Number(item.profit_loss.q3_last_year) : 0
Riri Novita's avatar
Riri Novita committed
2709
                            let persenQuarterMB = 0
faisalhamdi's avatar
faisalhamdi committed
2710 2711 2712
                            if (q_mb  < 0) {
                                if (q_actual >= q_mb) {
                                    persenQuarterMB = (q_mb - q_actual) / q_mb + 1  
Riri Novita's avatar
Riri Novita committed
2713
                                }  else {
faisalhamdi's avatar
faisalhamdi committed
2714
                                    persenQuarterMB = (q_mb - q_actual) / q_mb 
Riri Novita's avatar
Riri Novita committed
2715 2716 2717
                                }
                            }
                            else {
faisalhamdi's avatar
faisalhamdi committed
2718
                                persenQuarterMB = q_actual / q_mb 
Riri Novita's avatar
Riri Novita committed
2719 2720 2721
                            }

                            let persenQuarterLY = 0
faisalhamdi's avatar
faisalhamdi committed
2722 2723 2724
                            if (q_last_year  < 0) {
                                if (q_actual >= q_last_year) {
                                    persenQuarterLY = (q_last_year - q_actual) / q_last_year + 1  
Riri Novita's avatar
Riri Novita committed
2725
                                }  else {
faisalhamdi's avatar
faisalhamdi committed
2726
                                    persenQuarterLY = (q_last_year - q_actual) / q_last_year 
Riri Novita's avatar
Riri Novita committed
2727 2728 2729
                                }
                            }
                            else {
faisalhamdi's avatar
faisalhamdi committed
2730
                                persenQuarterLY = q_actual / q_last_year 
Riri Novita's avatar
Riri Novita committed
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 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771
                            }

                            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
2772

Riri Novita's avatar
Riri Novita committed
2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794
                            // let persenFyOLMB = Number(fy_ol/fy_mb)
                            // 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 
                            // }

                            let persenFyOLMB = 0
                                if (fy_mb  < 0) {
                                    if (fy_ol >= fy_mb) {
                                        persenFyOLMB = (fy_mb - fy_ol) / fy_mb + 1  
                                    }  else {
                                        persenFyOLMB = (fy_mb - fy_ol) / fy_mb 
                                    }
                                }
                                else {
                                    persenFyOLMB = fy_ol / fy_mb 
Riri Novita's avatar
Riri Novita committed
2795
                                }
Riri Novita's avatar
Riri Novita committed
2796 2797

                            dbSumaPL.push([
Riri Novita's avatar
Riri Novita committed
2798
                                item.type_report_id,
Riri Novita's avatar
Riri Novita committed
2799
                                item.id,
Riri Novita's avatar
Riri Novita committed
2800 2801 2802 2803
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
Riri Novita's avatar
Riri Novita committed
2804
                                item.profit_loss.mtd_actual,
Riri Novita's avatar
Riri Novita committed
2805
                                item.profit_loss.mtd_mb,
Riri Novita's avatar
Riri Novita committed
2806
                                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
2807
                                item.profit_loss.mtd_last_year,
Riri Novita's avatar
Riri Novita committed
2808
                                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
2809
                                item.profit_loss.ytd_actual,
Riri Novita's avatar
Riri Novita committed
2810 2811
                                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
2812
                                item.profit_loss.ytd_last_year,
Riri Novita's avatar
Riri Novita committed
2813
                                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),
faisalhamdi's avatar
faisalhamdi committed
2814 2815 2816 2817 2818
                                month == "Mar" ? item.profit_loss.q1_actual : month = "Jun" ? item.profit_loss.q2_actual : month = "Sep" ? item.profit_loss.q3_actual : 0,
                                month == "Mar" ? item.profit_loss.q1_mb : month = "Jun" ? item.profit_loss.q2_mb : month = "Sep" ? item.profit_loss.q3_mb : 0,
                                isNaN(persenQuarterMB) || persenQuarterMB == 'Infinity' || persenQuarterMB == '-Infinity'? (q_mb == '' || q_mb == 0? -0 : 0) : (q_mb == '' || q_mb == 0? persenQuarterMB * -100 : persenQuarterMB * 100),
                                month == "Mar" ? item.profit_loss.q1_last_year : month = "Jun" ? item.profit_loss.q2_last_year : month = "Sep" ? item.profit_loss.q3_last_year : 0,
                                isNaN(persenQuarterLY) || persenQuarterLY == 'Infinity' || persenQuarterLY == '-Infinity'? (q_last_year == '' || q_last_year == 0? -0 : 0) : (q_last_year == '' || q_last_year == 0? persenQuarterLY * -100 : persenQuarterLY * 100),
Riri Novita's avatar
Riri Novita committed
2819
                                item.profit_loss.fy_actual,
Riri Novita's avatar
Riri Novita committed
2820 2821 2822 2823
                                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
2824
                                item.profit_loss.fy_last_year,
Riri Novita's avatar
Riri Novita committed
2825 2826
                                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
2827 2828 2829
                                item.profit_loss.forecast_next_year,
                                item.profit_loss.forecast_more_year,
                                item.profit_loss.notes,
Riri Novita's avatar
Riri Novita committed
2830 2831 2832 2833 2834 2835 2836
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
Riri Novita's avatar
Riri Novita committed
2837
                            } 
Riri Novita's avatar
Riri Novita committed
2838
                        })
Riri Novita's avatar
Riri Novita committed
2839
                        console.log(dbSumaPL);
Riri Novita's avatar
Riri Novita committed
2840
                        this.setState({ dataTable: dbSumaPL, loading: false, previewTable: true, previewDownload: true })
Riri Novita's avatar
Riri Novita committed
2841 2842
                    } else {                            
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
2843
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
2844 2845 2846 2847 2848 2849 2850 2851 2852 2853
                                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
2854
                
Riri Novita's avatar
Riri Novita committed
2855 2856
            })
        } else if (this.state.report.value === 9) {
rifkaki's avatar
rifkaki committed
2857 2858 2859 2860 2861 2862
            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
2863
                console.log(response);
rifkaki's avatar
rifkaki committed
2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063
                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 }, () => {
d.arizona's avatar
d.arizona committed
3064
                                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
rifkaki's avatar
rifkaki committed
3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077
                                        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
3078
            })
faisalhamdi's avatar
faisalhamdi committed
3079
        } else if (this.state.report.value === 11) {
faisalhamdi's avatar
faisalhamdi committed
3080
            let dbCATPQ = [];
faisalhamdi's avatar
faisalhamdi committed
3081
            let payloadCATPQ = {...payload, report_id: 10, quarter: this.state.quarter.name}                
faisalhamdi's avatar
faisalhamdi committed
3082 3083 3084 3085 3086 3087
            api.create().getReportCATPQ(payloadCATPQ).then(response => {
                console.log(payloadCATPQ);
                console.log(response);
                if (response.data) {
                    if (response.data.status === 'success') {
                        let res = response.data.data
faisalhamdi's avatar
faisalhamdi committed
3088 3089 3090 3091
                        const handlePushChild = (item) => {
                            let indexIDzz = dbCATPQ.findIndex((val) => val[1] === item.id)
                            if (indexIDzz === -1) {
                                let parentTrue = item.parent_name == 'INTERNAL BUSINESS PROCESS PERSPECTIVE' || item.parent_name == 'CUSTOMER PERSPECTIVE'
faisalhamdi's avatar
faisalhamdi committed
3092
                                let weight = String(item.corporate_annual_target.weight).substr(0, String(item.corporate_annual_target.weight).length - 1)  
faisalhamdi's avatar
faisalhamdi committed
3093 3094
                                let percentVar = Number(item.corporate_annual_target.thisYearOlFy) / Number(item.corporate_annual_target.thisYearBudgetFy)  
                                percentVar = String(percentVar) == 'NaN' || String(percentVar) == 'Infinity' || String(percentVar) == '-Infinity' ? 0 : percentVar
faisalhamdi's avatar
faisalhamdi committed
3095 3096 3097 3098 3099 3100 3101 3102
                                dbCATPQ.push([
                                    item.typeItemReportId,
                                    item.itemReportId,
                                    item.parent,
                                    item.formula,
                                    item.level,
                                    item.itemName,
                                    item.corporate_annual_target.weight == "" ? Number(0).toFixed(1) : Number(weight).toFixed(1),
faisalhamdi's avatar
faisalhamdi committed
3103 3104 3105 3106
                                    parentTrue ? item.corporate_annual_target.uom : item.uom,
                                    parentTrue ? item.corporate_annual_target.kpiType  : item.typeKpi,
                                    parentTrue ? titleCase(item.corporate_annual_target.maxAch) : titleCase(item.maxAch),
                                    parentTrue ? item.corporate_annual_target.formulaYtd  : item.formulaYtd,
faisalhamdi's avatar
faisalhamdi committed
3107 3108 3109

                                    item.corporate_annual_target.lastYearActualQx,
                                    item.corporate_annual_target.lastYearActualFy,
faisalhamdi's avatar
faisalhamdi committed
3110
                                    
faisalhamdi's avatar
faisalhamdi committed
3111 3112 3113
                                    item.corporate_annual_target.thisYearbudgetQx,
                                    item.corporate_annual_target.thisYearActualQx,
                                    item.corporate_annual_target.thisYearPercentAch,
faisalhamdi's avatar
faisalhamdi committed
3114
                                    item.corporate_annual_target.thisYearPercentGrowthYoy,
faisalhamdi's avatar
faisalhamdi committed
3115
                                    item.corporate_annual_target.thisYearScore === null ? "0" : item.corporate_annual_target.thisYearScore,
faisalhamdi's avatar
faisalhamdi committed
3116 3117 3118 3119 3120 3121 3122 3123
                                    item.corporate_annual_target.thisYearScoreXWeight,

                                    item.corporate_annual_target.thisYearBudgetYtd,
                                    item.corporate_annual_target.thisYearActualYtd,
                                    item.corporate_annual_target.thisYearPercentAchYtd,

                                    item.corporate_annual_target.thisYearBudgetFy,
                                    item.corporate_annual_target.thisYearOlFy,
faisalhamdi's avatar
faisalhamdi committed
3124
                                    item.corporate_annual_target.thisYearPercentAchFy,
faisalhamdi's avatar
faisalhamdi committed
3125
                                    item.corporate_annual_target.thisYearScoreFy === null ? "0" : item.corporate_annual_target.thisYearScoreFy,
faisalhamdi's avatar
faisalhamdi committed
3126 3127
                                    item.corporate_annual_target.thisYearScoreXWeightFy,

faisalhamdi's avatar
faisalhamdi committed
3128
                                    item.orders
faisalhamdi's avatar
faisalhamdi committed
3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
                        res.map((item, index) => {
                            dbCATPQ.push([
                                item.typeItemReportId,
                                item.itemReportId,
                                item.parent,
                                item.formula,
                                item.level,
                                item.itemName,
                                item.weight == '' ? Number(0).toFixed(1) : Number(Number(item.weight) * 100).toFixed(1),
                                item.uom,
faisalhamdi's avatar
faisalhamdi committed
3149 3150 3151
                                item.typeKpi,
                                item.maxAch,
                                item.formulaYtd,
faisalhamdi's avatar
faisalhamdi committed
3152 3153 3154

                                item.corporate_annual_target.lastYearActualQx,
                                item.corporate_annual_target.lastYearActualFy,
faisalhamdi's avatar
faisalhamdi committed
3155
                                
faisalhamdi's avatar
faisalhamdi committed
3156 3157 3158
                                item.corporate_annual_target.thisYearbudgetQx,
                                item.corporate_annual_target.thisYearActualQx,
                                item.corporate_annual_target.thisYearPercentAch,
faisalhamdi's avatar
faisalhamdi committed
3159
                                item.corporate_annual_target.thisYearPercentGrowthYoy,
faisalhamdi's avatar
faisalhamdi committed
3160 3161 3162 3163 3164 3165 3166 3167 3168
                                item.corporate_annual_target.thisYearScore,
                                item.corporate_annual_target.thisYearScoreXWeight,

                                item.corporate_annual_target.thisYearBudgetYtd,
                                item.corporate_annual_target.thisYearActualYtd,
                                item.corporate_annual_target.thisYearPercentAchYtd,

                                item.corporate_annual_target.thisYearBudgetFy,
                                item.corporate_annual_target.thisYearOlFy,
faisalhamdi's avatar
faisalhamdi committed
3169 3170 3171 3172
                                item.corporate_annual_target.thisYearPercentAchFy,
                                item.corporate_annual_target.thisYearScoreFy,
                                item.corporate_annual_target.thisYearScoreXWeightFy,
                                
faisalhamdi's avatar
faisalhamdi committed
3173
                                item.orders
faisalhamdi's avatar
faisalhamdi committed
3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
                        this.setState({ dataTable: dbCATPQ, previewTable: true, loading: false, previewDownload: true })
                        console.log(this.state.dataTable)
faisalhamdi's avatar
faisalhamdi committed
3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }                    
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                }
            })        
faisalhamdi's avatar
faisalhamdi committed
3199
        } else if (this.state.report.value === 10) {
faisalhamdi's avatar
faisalhamdi committed
3200
            let dbCATPA = []
faisalhamdi's avatar
faisalhamdi committed
3201
            let payloadCATPA = {...payload, months: this.state.month.month_id, get_for: "view"}                
faisalhamdi's avatar
faisalhamdi committed
3202 3203 3204 3205 3206 3207 3208 3209
            api.create().getReportCATPA(payloadCATPA).then(response => {
                console.log(payloadCATPA);
                console.log(response);
                if (response.data) {
                    if (response.data.status === 'success') {
                        let res = response.data.data
                        const handlePushChild = (item) => {
                            let indexIDzz = dbCATPA.findIndex((val) => val[1] === item.id)
faisalhamdi's avatar
faisalhamdi committed
3210 3211
                            if (indexIDzz === -1) {
                                let parentTrue = item.parent_name == 'INTERNAL BUSINESS PROCESS PERSPECTIVE' || item.parent_name == 'CUSTOMER PERSPECTIVE'
faisalhamdi's avatar
faisalhamdi committed
3212 3213
                                let weight = String(item.corporate_annual_target.weight).substr(0, String(item.corporate_annual_target.weight).length - 1) 

faisalhamdi's avatar
faisalhamdi committed
3214 3215 3216 3217 3218 3219 3220
                                dbCATPA.push([
                                    item.type_report_id,
                                    item.id,
                                    item.parent,
                                    item.formula,
                                    item.level,
                                    item.description,
faisalhamdi's avatar
faisalhamdi committed
3221
                                    item.corporate_annual_target.weight == "" ? Number(0).toFixed(1) : Number(weight).toFixed(1),
faisalhamdi's avatar
faisalhamdi committed
3222 3223 3224
                                    parentTrue ? item.corporate_annual_target.uom : item.uom,
                                    parentTrue ? item.corporate_annual_target.jenis_kpi == "" ? null : item.corporate_annual_target.jenis_kpi : item.jenis_kpi == "" ? null : item.kpi_type,
                                    parentTrue ? item.corporate_annual_target.max_ach == "" ? null : titleCase(item.corporate_annual_target.max_ach) : item.max_ach == "" ? null : titleCase(item.max_ach),
faisalhamdi's avatar
faisalhamdi committed
3225
                                    item.corporate_annual_target.formula_ytd == "" ? null : item.corporate_annual_target.formula_ytd,    
faisalhamdi's avatar
faisalhamdi committed
3226 3227
                                    item.corporate_annual_target.actual_ytd,
                                    item.corporate_annual_target.target_ytd,
faisalhamdi's avatar
faisalhamdi committed
3228
                                    item.corporate_annual_target.achivement_ytd,
faisalhamdi's avatar
faisalhamdi committed
3229 3230
                                    item.corporate_annual_target.score,
                                    item.corporate_annual_target.score_x_weight,
faisalhamdi's avatar
faisalhamdi committed
3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244
                                    item.order
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
                        res.map((item, index) => {
                            dbCATPA.push([
                                item.type_report_id,
faisalhamdi's avatar
faisalhamdi committed
3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
                                item.weight == '' ? Number(0).toFixed(1) : Number(Number(item.weight) * 100).toFixed(1),
                                item.uom,
                                item.kpi_type,
                                item.max_ach,
                                item.formula_ytd,
                                item.corporate_annual_target.actual_ytd,
                                item.corporate_annual_target.target_ytd,
                                item.corporate_annual_target.achivement_ytd,
                                item.corporate_annual_target.score,
                                item.corporate_annual_target.score_x_weight,
                                item.order
faisalhamdi's avatar
faisalhamdi committed
3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
                        this.setState({ dataTable: dbCATPA, previewTable: true, loading: false, previewDownload: true })
                        console.log(this.state.dataTable)
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
3274
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
faisalhamdi's avatar
faisalhamdi committed
3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }                    
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                }
            })
d.arizona's avatar
d.arizona committed
3286
        }
Riri Novita's avatar
Riri Novita committed
3287

d.arizona's avatar
d.arizona committed
3288 3289
    }

d.arizona's avatar
d.arizona committed
3290
    getCFSumaMR(payload, dbSumaCF) {
d.arizona's avatar
d.arizona committed
3291
        let payloadLast = { ...payload, "periode": Number(this.state.periode.periode) - 1 }
d.arizona's avatar
d.arizona committed
3292 3293 3294 3295 3296 3297 3298 3299
        // 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
3300 3301 3302 3303 3304 3305 3306
        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
3307
                res.map((item, index) => {
d.arizona's avatar
d.arizona committed
3308 3309 3310 3311 3312 3313 3314
                    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
3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326
                                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
3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362
                                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,
r.kurnia's avatar
r.kurnia committed
3363 3364 3365 3366 3367 3368 3369 3370 3371 3372
                                items.cash_flow.history_current_year,
                                items.cash_flow.history_last_year,
                                items.cash_flow.history_last_two_year,
                                items.cash_flow.history_last_three_year,
                                items.cash_flow.history_last_four_year,
                                items.cash_flow.history_last_five_year,
                                items.cash_flow.history_last_six_year,
                                items.cash_flow.history_last_seven_year,
                                items.cash_flow.history_last_eight_year,
                                items.cash_flow.history_last_nine_year,
d.arizona's avatar
d.arizona committed
3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384
                                ])
                            }
                            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
3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396
                        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
3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432
                        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,
r.kurnia's avatar
r.kurnia committed
3433 3434 3435 3436 3437 3438 3439 3440 3441 3442
                        item.cash_flow.history_current_year,
                        item.cash_flow.history_last_year,
                        item.cash_flow.history_last_two_year,
                        item.cash_flow.history_last_three_year,
                        item.cash_flow.history_last_four_year,
                        item.cash_flow.history_last_five_year,
                        item.cash_flow.history_last_six_year,
                        item.cash_flow.history_last_seven_year,
                        item.cash_flow.history_last_eight_year,
                        item.cash_flow.history_last_nine_year,
d.arizona's avatar
d.arizona committed
3443 3444 3445 3446 3447 3448 3449 3450 3451
                        ])

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

d.arizona's avatar
d.arizona committed
3453
                    }
d.arizona's avatar
d.arizona committed
3454

d.arizona's avatar
d.arizona committed
3455 3456 3457
                })
                this.setState({ dataTable2 }, () => {
                    // console.log(this.state.dataTable2)
d.arizona's avatar
d.arizona committed
3458
                    this.getCFSumaLastMR(payloadLast, dbSumaCF)
d.arizona's avatar
d.arizona committed
3459 3460 3461 3462 3463 3464 3465 3466 3467
                })
                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
3468
    getCFSumaLastMR(payload, dbSumaCF) {
rifkaki's avatar
rifkaki committed
3469 3470
        console.log(dbSumaCF)
        console.log(this.state.dbSumaCF)
d.arizona's avatar
d.arizona committed
3471 3472 3473 3474 3475 3476 3477
        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
3478
                res.map((item, index) => {
d.arizona's avatar
d.arizona committed
3479
                    let indexID = dataTable2.findIndex((val) => val[1] == item.id)
d.arizona's avatar
d.arizona committed
3480
                    let indexIDSuma = dbSumaCF.findIndex((val) => val[0] == item.id)
d.arizona's avatar
d.arizona committed
3481 3482 3483
                    if (indexID != -1) {
                        const handlePushChild = (items) => {
                            let indexIDzz = dataTable2.findIndex((val) => val[1] === items.id)
rifkaki's avatar
rifkaki committed
3484
                            let indexIDSumaChild = dbSumaCF.findIndex((val) => val[0] == items.id)
d.arizona's avatar
d.arizona committed
3485 3486 3487
                            // console.log(indexIDzz)
                            if (indexIDzz != -1) {
                                dataTable3.push([...dataTable2[indexIDzz],
d.arizona's avatar
d.arizona committed
3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499
                                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
3500
                                ...dbSumaCF[indexIDSumaChild]
d.arizona's avatar
d.arizona committed
3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512
                                ])
                            }
                            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
3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525
                        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
3526 3527 3528 3529 3530 3531 3532 3533 3534
                        ])

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

d.arizona's avatar
d.arizona committed
3536
                    }
d.arizona's avatar
d.arizona committed
3537

d.arizona's avatar
d.arizona committed
3538
                })
rifkaki's avatar
rifkaki committed
3539
                console.log(dbSumaCF)
d.arizona's avatar
d.arizona committed
3540 3541 3542 3543 3544 3545 3546 3547
                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
3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562
    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
3563
                res.map((item, index) => {
Riri Novita's avatar
Riri Novita committed
3564 3565 3566 3567 3568 3569 3570
                    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
3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583
                                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
3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595
                                ])
                            }
                            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
3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608
                        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
3609 3610 3611 3612 3613 3614 3615 3616 3617
                        ])

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

Riri Novita's avatar
Riri Novita committed
3619
                    }
d.arizona's avatar
d.arizona committed
3620

Riri Novita's avatar
Riri Novita committed
3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641
                })
                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
3642
                res.map((item, index) => {
Riri Novita's avatar
Riri Novita committed
3643 3644 3645 3646 3647 3648 3649
                    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
3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661
                                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
3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673
                                ])
                            }
                            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
3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685
                        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
3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697
                        ])

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

                    }

d.arizona's avatar
d.arizona committed
3698 3699 3700 3701 3702 3703 3704 3705 3706
                })
                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
3707
    getRatioMR(payload) {
rifkaki's avatar
rifkaki committed
3708 3709 3710 3711 3712 3713 3714
        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
3715 3716 3717 3718 3719 3720 3721 3722
        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
3723
                    res.map((item, index) => {
d.arizona's avatar
d.arizona committed
3724 3725 3726 3727 3728 3729 3730
                        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
3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754
                                    // 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
3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766
                                    ])
                                }
                                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
3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790
                            // 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
3791 3792 3793 3794 3795 3796 3797 3798 3799
                            ])

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

d.arizona's avatar
d.arizona committed
3801
                        }
d.arizona's avatar
d.arizona committed
3802

d.arizona's avatar
d.arizona committed
3803 3804
                    })
                    console.log(dataTable2)
rifkaki's avatar
rifkaki committed
3805 3806 3807 3808 3809
                    // 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
3810
                } else {
rifkaki's avatar
rifkaki committed
3811
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
3812
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
rifkaki's avatar
rifkaki committed
3813 3814 3815 3816 3817 3818
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
d.arizona's avatar
d.arizona committed
3819
                }
rifkaki's avatar
rifkaki committed
3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834
            } 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
3835
                    res.map((item, index) => {
rifkaki's avatar
rifkaki committed
3836 3837 3838 3839 3840 3841 3842
                        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
3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866
                                    // 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
3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878
                                    ])
                                }
                                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
3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902
                            // 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
3903 3904 3905 3906 3907 3908 3909 3910 3911
                            ])

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

rifkaki's avatar
rifkaki committed
3913
                        }
d.arizona's avatar
d.arizona committed
3914

rifkaki's avatar
rifkaki committed
3915 3916 3917
                    })
                    console.log(dataTable3)
                    this.setState({ dataTable: dataTable3, previewTable: true, loading: false, previewDownload: true })
d.arizona's avatar
d.arizona committed
3918
                } else {
d.arizona's avatar
d.arizona committed
3919
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
3920
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
3921 3922 3923 3924 3925 3926
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
d.arizona's avatar
d.arizona committed
3927
                }
d.arizona's avatar
d.arizona committed
3928 3929 3930 3931 3932 3933
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
3934
    async downloadAllData() {
faisalhamdi's avatar
faisalhamdi committed
3935
        if (this.state.report.value === 1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
3936
            let res = await fetch(
d.arizona's avatar
d.arizona committed
3937
                `${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
3938 3939 3940 3941 3942 3943 3944
            )
            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
3945
                a.download = 'Report DB Profit & Loss Detail.xlsx';
Deni Rinaldi's avatar
Deni Rinaldi committed
3946 3947
                a.click();
            }
faisalhamdi's avatar
faisalhamdi committed
3948
        } else if (this.state.report.value === 2) {
Deni Rinaldi's avatar
Deni Rinaldi committed
3949
            let res = await fetch(
d.arizona's avatar
d.arizona committed
3950
                `${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
3951 3952 3953 3954 3955 3956 3957
            )
            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
3958
                a.download = 'Report DB Balance Sheet.xlsx';
Deni Rinaldi's avatar
Deni Rinaldi committed
3959 3960 3961 3962
                a.click();
            }
        } else if (this.state.report.value === 3) {
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
3963
                `${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
3964 3965 3966 3967 3968 3969 3970
            )
            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
3971
                a.download = 'Report DB Profit & Loss.xlsx';
Deni Rinaldi's avatar
Deni Rinaldi committed
3972 3973
                a.click();
            }
faisalhamdi's avatar
faisalhamdi committed
3974
        } else if (this.state.report.value === 4) {
Riri Novita's avatar
Riri Novita committed
3975
            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
3976
            console.log(url);
faisalhamdi's avatar
faisalhamdi committed
3977
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
3978
                `${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
3979 3980 3981 3982 3983 3984 3985 3986 3987 3988
            )
            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
3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001
        } 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
4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014
        } 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
4015 4016 4017
                a.click();
            }
        } else if (this.state.report.value === 6) {
rifkaki's avatar
rifkaki committed
4018 4019
            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
4020
            let res = await fetch(
Arfin Syadziy's avatar
Arfin Syadziy committed
4021
                `${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
4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033
            )
            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
4034
                `${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
4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045
            )
            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) {
Riri Novita's avatar
Riri Novita committed
4046
            let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_profit_loss/export_report?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
4047
            console.log(url);
d.arizona's avatar
d.arizona committed
4048
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
4049
                `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_profit_loss/export_report?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
4050 4051 4052 4053 4054 4055 4056 4057
            )
            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
4058 4059
                a.click();
            }
rifkaki's avatar
rifkaki committed
4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072
        } 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();
            }
faisalhamdi's avatar
faisalhamdi committed
4073
        } else if (this.state.report.value === 11) {
faisalhamdi's avatar
faisalhamdi committed
4074
            let res = await fetch(
faisalhamdi's avatar
faisalhamdi committed
4075
                `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/cat/quarterly/export_report?report_id=10&&company_id=${this.state.company.company_id}&&periode=${this.state.periode.periode}&&quarter=${this.state.quarter.name}`
faisalhamdi's avatar
faisalhamdi committed
4076
            )
faisalhamdi's avatar
faisalhamdi committed
4077
            console.log(res);
faisalhamdi's avatar
faisalhamdi committed
4078 4079 4080 4081 4082 4083 4084 4085 4086
            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 CAT Performance Quarterly.xlsx';
                a.click();
            }
faisalhamdi's avatar
faisalhamdi committed
4087
        } else if (this.state.report.value === 10) {
faisalhamdi's avatar
faisalhamdi committed
4088
            let res = await fetch(
faisalhamdi's avatar
faisalhamdi committed
4089
                `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/cat/performance_appraisal/export?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}`
faisalhamdi's avatar
faisalhamdi committed
4090 4091 4092 4093 4094 4095 4096 4097 4098 4099
            )
            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 CAT Performance Appraisal.xlsx';
                a.click();
            }
rifkaki's avatar
rifkaki committed
4100
        }else {
Deni Rinaldi's avatar
Deni Rinaldi committed
4101 4102 4103
            setTimeout(() => {
                this.setState({ loading: false })
            }, 1000);
Deni Rinaldi's avatar
Deni Rinaldi committed
4104 4105 4106
        }
    }

faisalhamdi's avatar
faisalhamdi committed
4107 4108 4109 4110
    closeAlert() {
        this.setState({ alert: false })
    }

faisalhamdi's avatar
faisalhamdi committed
4111
    render() {
Deni Rinaldi's avatar
Deni Rinaldi committed
4112
        const loadingComponent = (
Deni Rinaldi's avatar
Deni Rinaldi committed
4113
            <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
4114 4115 4116 4117 4118 4119 4120 4121
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
            </div>
        );
faisalhamdi's avatar
faisalhamdi committed
4122 4123 4124 4125 4126 4127
        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
4128 4129 4130 4131 4132
                    <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
4133 4134 4135 4136 4137
                    <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
4138
                            <div style={{ minWidth: 'max-content', padding: '20px 20px 0px 20px' }}>
d.arizona's avatar
d.arizona committed
4139
                                <div style={{ marginTop: 15, display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
4140 4141
                                    <Autocomplete
                                        options={this.state.reportType}
Deni Rinaldi's avatar
Deni Rinaldi committed
4142
                                        getOptionLabel={(option) => titleCase(option.label)}
Deni Rinaldi's avatar
Deni Rinaldi committed
4143
                                        id="typereport"
idlanirined's avatar
idlanirined committed
4144
                                        onChange={(event, newInputValue) => this.setState({ report: newInputValue, loading: true, previewTable: false }, () => {
d.arizona's avatar
d.arizona committed
4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163
                                            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
4164
                                        })}
Deni Rinaldi's avatar
Deni Rinaldi committed
4165
                                        disableClearable
faisalhamdi's avatar
faisalhamdi committed
4166
                                        style={{ width: 250 }}
Deni Rinaldi's avatar
Deni Rinaldi committed
4167 4168 4169
                                        renderInput={(params) => <TextField {...params} label="Report Type" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.report}
                                    />
d.arizona's avatar
d.arizona committed
4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183
                                    <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
4184
                                </div>
d.arizona's avatar
d.arizona committed
4185
                                <div style={{ marginTop: 15, display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
4186 4187 4188 4189
                                    <Autocomplete
                                        {...this.state.listCompany}
                                        id="company"
                                        disabled={this.state.intent === 'Home' ? true : false}
idlanirined's avatar
idlanirined committed
4190
                                        onChange={(event, newInputValue) => this.setState({ company: newInputValue, loading: true, previewTable: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
4191
                                            this.getReportType()
Deni Rinaldi's avatar
Deni Rinaldi committed
4192
                                        })}
Deni Rinaldi's avatar
Deni Rinaldi committed
4193 4194 4195 4196 4197
                                        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
4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210
                                    {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
4211
                                    {/* {this.state.report != null ? String(this.state.report.label).toLocaleLowerCase().includes('summary') ? <Autocomplete
d.arizona's avatar
d.arizona committed
4212
                                        {...this.state.listUom}
d.arizona's avatar
d.arizona committed
4213
                                        // getOptionLabel={(option) => titleCase(option.label)}
d.arizona's avatar
d.arizona committed
4214 4215
                                        id="uom"
                                        onChange={(event, newInputValue) => this.setState({ uom: newInputValue, loading: true, previewTable: false }, () => {
d.arizona's avatar
d.arizona committed
4216 4217 4218 4219
                                            this.getReportType()
                                        })}
                                        disableClearable
                                        style={{ width: 250, marginLeft: 10 }}
d.arizona's avatar
d.arizona committed
4220 4221
                                        renderInput={(params) => <TextField {...params} label="Uom" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.uom}
d.arizona's avatar
d.arizona committed
4222
                                    /> : null : null} */}
faisalhamdi's avatar
faisalhamdi committed
4223
                                </div>
d.arizona's avatar
d.arizona committed
4224
                                {/* <div style={{ marginTop: 15, display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
4225 4226
                                    <Autocomplete
                                        {...this.state.listPeriode}
faisalhamdi's avatar
faisalhamdi committed
4227
                                        id="periode"
idlanirined's avatar
idlanirined committed
4228
                                        onChange={(event, newInputValue) => this.setState({ periode: newInputValue, loading: true, previewTable: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
4229
                                            this.getReportType()
Deni Rinaldi's avatar
Deni Rinaldi committed
4230 4231 4232 4233 4234 4235 4236
                                        })}
                                        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
4237
                                        value={this.state.periode}
Deni Rinaldi's avatar
Deni Rinaldi committed
4238
                                    />
d.arizona's avatar
d.arizona committed
4239
                                </div> */}
rifkaki's avatar
rifkaki committed
4240 4241
                                {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
4242 4243 4244 4245 4246 4247 4248
                                        {...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
4249
                                        style={{ width: 250 }}
d.arizona's avatar
d.arizona committed
4250 4251
                                        renderInput={(params) => <TextField {...params} label="Quarter" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.quarter}
rifkaki's avatar
rifkaki committed
4252 4253
                                    /> 
                                </div> : null : null}
d.arizona's avatar
d.arizona committed
4254
                                {/* {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
4255 4256 4257 4258 4259 4260 4261 4262
                                    <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
4263
                                        style={{ width: 250 }}
d.arizona's avatar
d.arizona committed
4264 4265 4266
                                        renderInput={(params) => <TextField {...params} label="Months" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.month}
                                    />
d.arizona's avatar
d.arizona committed
4267
                                </div> : null : null} */}
Deni Rinaldi's avatar
Deni Rinaldi committed
4268
                            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
4269
                            <div>
Deni Rinaldi's avatar
Deni Rinaldi committed
4270
                                <div style={{ display: 'flex', justifyContent: 'space-between', padding: '0px 20px 10px 20px' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295
                                    <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
4296
                                {this.state.loading && loadingComponent}
Deni Rinaldi's avatar
Deni Rinaldi committed
4297
                                {this.state.previewTable && (
Deni Rinaldi's avatar
Deni Rinaldi committed
4298 4299 4300 4301
                                    <TableSubHolding
                                        width={this.props.width}
                                        height={this.props.height}
                                        open={this.props.open}
Riri Novita's avatar
Riri Novita committed
4302
                                        month={this.state.month.month_value}
Riri Novita's avatar
Riri Novita committed
4303 4304
                                        approvedMB={this.state.approveMB}
                                        approveMonthly={this.state.approveMonthly}
Deni Rinaldi's avatar
Deni Rinaldi committed
4305
                                        type={this.state.report ? this.state.report.value : 1}
Deni Rinaldi's avatar
Deni Rinaldi committed
4306 4307
                                        dataTable={this.state.dataTable}
                                        periode={this.state.periode ? this.state.periode.periode : null}
faisalhamdi's avatar
faisalhamdi committed
4308
                                        quarter={this.state.quarter.name}
faisalhamdi's avatar
faisalhamdi committed
4309
                                        company={this.state.company}
Deni Rinaldi's avatar
Deni Rinaldi committed
4310 4311
                                    />
                                )}
faisalhamdi's avatar
faisalhamdi committed
4312 4313 4314 4315 4316 4317 4318 4319
                            </div>
                        </Paper>
                    </div>
                </div>
            </div>
        )
    }
}