SubHolding.js 294 KB
Newer Older
faisalhamdi's avatar
faisalhamdi committed
1
import React, { Component } from 'react'
syadziy's avatar
syadziy committed
2
import { Typography, TextField, Paper, 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 { format } from 'date-fns';
faisalhamdi's avatar
faisalhamdi committed
13 14 15

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

Riri Novita's avatar
Riri Novita committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
const defaultReport = [
    { value: 2, label: 'DB Balance Sheet', report: 1 },
    { value: 3, label: 'DB Profit & Loss', report: 2 },
    { value: 1, label: 'DB Profit & Loss Detail', report: 2 },
    { value: 4, label: 'DB Ratio', report: 1 },
    { value: 5, label: 'DB Tax Planning', report: 1 },
    { value: 21, label: 'DB Operating Indicator', report: 1 },
    { value: 6, label: 'Cash Flow - Summary', report: 1 },
    { value: 7, label: 'Balance Sheet - Summary', report: 1 },
    { value: 8, label: 'Profit Loss - Summary', report: 2 },
    { value: 9, label: 'Financial Ratio - Summary', report: 1 },
    { value: 11, label: 'CAT Performance Quarterly', report: 1 },
    { value: 10, label: 'CAT Performance Appraisal', report: 1 },
]

faisalhamdi's avatar
faisalhamdi committed
32 33 34 35 36 37 38
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
39 40 41 42 43
            tab: 0,
            listCompany: null,
            company: null,
            listPeriode: null,
            periode: null,
Riri Novita's avatar
Riri Novita committed
44 45
            reportType: defaultReport,
            reportType2: [
faisalhamdi's avatar
faisalhamdi committed
46 47 48
                { value: 3, label: 'DB Profit & Loss' },
                { value: 1, label: 'DB Profit & Loss Detail' },
                { value: 8, label: 'Profit Loss - Summary' },
Deni Rinaldi's avatar
Deni Rinaldi committed
49 50
            ],
            report: null,
Deni Rinaldi's avatar
Deni Rinaldi committed
51
            loading: false,
d.arizona's avatar
d.arizona committed
52
            previewTable: false,
d.arizona's avatar
d.arizona committed
53 54 55 56 57 58
            OPID: null,
            listMonths: null,
            listUom: null,
            listQuarter: null,
            month: null,
            quarter: null,
Riri Novita's avatar
Riri Novita committed
59 60
            uom: null,
            approveMB: false,
Riri Novita's avatar
Riri Novita committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
            approveMonthly: false,
            defaultCurrency: null,
            defaultCurrencyID: null,
            dataCurrency: [],
            currency: [],
            visibleAlertSave: false,
            dataCurrency: [
                {
                    "id": 1,
                    "value": "IDR"
                },
                {
                    "id": 2,
                    "value": "USD",
                }
            ]
faisalhamdi's avatar
faisalhamdi committed
77 78 79 80 81 82 83
        }
    }

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

Deni Rinaldi's avatar
Deni Rinaldi committed
84 85 86
    componentDidMount() {
        this.getDetailUser()
        this.setState({ report: this.state.reportType[0], loading: true })
Riri Novita's avatar
Riri Novita committed
87
        // this.getApproveMB()
Deni Rinaldi's avatar
Deni Rinaldi committed
88 89 90 91 92 93 94 95 96 97 98
    }

    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
99 100 101 102 103 104 105 106 107
                    } 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
108
                    }
Riri Novita's avatar
Riri Novita committed
109
                } else {
110
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
Deni Rinaldi's avatar
Deni Rinaldi committed
111 112 113 114 115
                }
            }
        })
    }

Riri Novita's avatar
Riri Novita committed
116 117 118 119 120 121 122 123 124
    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") {
125
                    this.setState({ approveMB: response.data.data.is_master_budget_approve })
Riri Novita's avatar
Riri Novita committed
126
                }
127

Riri Novita's avatar
Riri Novita committed
128 129 130 131 132 133 134 135 136 137
            }
        })
    }

    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
138
            console.log(payload);
Riri Novita's avatar
Riri Novita committed
139 140 141
            console.log(response);
            if (response.data) {
                if (response.data.status == "success") {
Riri Novita's avatar
Riri Novita committed
142
                    console.log(response.data.data);
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
                    let approveMonthly =
                        this.state.month.month_id == 1 ?
                            response.data.data.januari.is_approve :
                            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 :
                                                                    response.data.data.december.is_approve
Riri Novita's avatar
Riri Novita committed
167 168

                    this.setState({ approveMonthly })
169 170
                }

Riri Novita's avatar
Riri Novita committed
171 172 173 174
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
175 176
    getCompanyActive() {
        api.create().getPerusahaanActive().then((response) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
177
            // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
            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
197
                    if (arrayBaru.length > 0) {
198
                        arrayBaru = arrayBaru.sort((a, b) => a.company_name.localeCompare(b.company_name))
d.arizona's avatar
d.arizona committed
199 200
                    }

Deni Rinaldi's avatar
Deni Rinaldi committed
201 202 203 204 205 206 207
                    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()
Riri Novita's avatar
Riri Novita committed
208
                        this.getCurrency(this.state.company.company_id)
Deni Rinaldi's avatar
Deni Rinaldi committed
209 210 211
                    })
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
212
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Deni Rinaldi's avatar
Deni Rinaldi committed
213 214 215 216 217 218 219 220 221 222 223 224 225
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listCompany: null, company: null })
            }
        })
    }

Riri Novita's avatar
Riri Novita committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
    getCurrency(companyID) {
        // console.log(companyID);
        api.create().getDetailPerusahaan(companyID).then(response => {
            console.log(response);
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === "success") {
                        let data = response.data.data
                        let datas = []
                        if (response.data.data.currency.length > 0) {
                            response.data.data.currency.map((item) => {
                                // console.log(item);
                                datas.push({
                                    id: item.currencyId,
                                    value: item.currencyName
                                })

                            })
                        }
                        let index = datas.findIndex((val) => val.id == response.data.data.default_currency)
                        this.setState({
                            defaultCurrencyID: response.data.data.default_currency,
                            currency: datas,
                            // report: response.data.data.default_currency == 2 && this.state.defaultCurrency == 1 ? this.state.reportType2[0] : this.state.reportType[0],
                            defaultCurrency: index == -1 ? null : datas[index]
                        })
                    } 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);
                            }
                        })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
            }

        })
    }

    changeCurrency(idCurrency) {
        if (this.state.defaultCurrencyID == 2 && idCurrency == 1) {
            this.setState({ reportType: this.state.reportType2, report: this.state.reportType2[0] })
        } else {
            this.setState({ reportType: this.state.reportType, report: this.state.reportType[0] })
        }
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
280 281
    getLastPeriod() {
        api.create().getLastPeriod(this.state.company.company_id).then(response => {
Riri Novita's avatar
Riri Novita committed
282
            console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
            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
298
                    let listMonths = []
Deni Rinaldi's avatar
Deni Rinaldi committed
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
                    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
319 320
                    console.log(this.state.lastPeriod)
                    let periode = (this.state.lastPeriod == "" ? String(Number(currentYear)) : this.state.latestPeriode)
d.arizona's avatar
d.arizona committed
321 322 323 324 325
                    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
326
                    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
327

Deni Rinaldi's avatar
Deni Rinaldi committed
328 329 330
                    // console.log(data)
                    // console.log(this.state.latestPeriode)
                    // console.log(periodeData)
d.arizona's avatar
d.arizona committed
331
                    console.log(index)
Deni Rinaldi's avatar
Deni Rinaldi committed
332
                    this.setState({ listPeriode: defaultProps, periode: index === -1 ? periodeData[0] : periodeData[index] }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
333
                        // this.getDataTable()
334
                        // this.getSubmission()
d.arizona's avatar
d.arizona committed
335
                        this.getMonth()
Deni Rinaldi's avatar
Deni Rinaldi committed
336 337 338 339 340 341
                        // if (this.state.isApprover === true) {
                        //     this.getCompanySubmitted()
                        // } else {
                        //     this.getRevision()
                        // }
                    })
Riri Novita's avatar
Riri Novita committed
342 343
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
344
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
345 346 347 348 349 350
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
351 352 353 354 355
                }
            }
        })
    }

d.arizona's avatar
d.arizona committed
356 357
    getMonth() {
        api.create().getMonthTransaction().then(response => {
d.arizona's avatar
d.arizona committed
358 359
            let dateNow = new Date()
            dateNow.setMonth(dateNow.getMonth() - 1);
360
            let month = format(dateNow, 'MMMM')
d.arizona's avatar
d.arizona committed
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
            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
379 380 381 382
                        { name: 'Q1', value: '3' },
                        { name: 'Q2', value: '6' },
                        { name: 'Q3', value: '9' },
                        { name: 'Q4', value: '12' },
d.arizona's avatar
d.arizona committed
383 384
                    ]

d.arizona's avatar
d.arizona committed
385
                    let listUom = [{ value: 'Mio IDR' }]
d.arizona's avatar
d.arizona committed
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408

                    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
409 410
                        // this.getLastPeriod()
                        // this.getPeriode()
d.arizona's avatar
d.arizona committed
411 412 413 414
                        // }
                    })
                } else {
                    // this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
415
                    //     if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
416 417 418 419 420 421 422 423 424 425 426 427 428
                    //         setTimeout(() => {
                    //             localStorage.removeItem(Constant.TOKEN)
                    //             window.location.reload();
                    //         }, 1000);
                    //     }
                    // })
                }
            } else {
                // this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
            }
        })
    }

429
    getReportType() {
Riri Novita's avatar
Riri Novita committed
430
        console.log(this.state.defaultCurrency);
431 432 433 434
        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
435
            "currency_id": this.state.defaultCurrency.id
436
        }
Riri Novita's avatar
Riri Novita committed
437 438
        this.getApproveMB()
        this.getApproveMonthly()
439 440 441 442 443 444 445
        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
446
                                this.setState({ revisionType: item.revision }, () => {
447 448 449 450 451 452 453
                                    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
454
                                this.setState({ revisionType: item.revision }, () => {
455 456 457 458
                                    this.getSubmission()
                                })
                            }
                        })
459 460 461
                    } 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
462
                                this.setState({ revisionType: item.revision }, () => {
463 464 465 466
                                    this.getSubmission()
                                })
                            }
                        })
467
                    } else {
d.arizona's avatar
d.arizona committed
468
                        this.setState({ revisionType: 0 }, () => {
469 470 471
                            this.getSubmission()
                        })
                    }
faisalhamdi's avatar
faisalhamdi committed
472 473
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
474
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
faisalhamdi's avatar
faisalhamdi committed
475 476 477 478 479 480
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
481
                }
faisalhamdi's avatar
faisalhamdi committed
482
            } else {
d.arizona's avatar
d.arizona committed
483
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
484 485 486 487
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
488 489
    getSubmission() {
        this.setState({ loading: true })
Deni Rinaldi's avatar
Deni Rinaldi committed
490 491
        let payload = {
            "company_id": this.state.company.company_id,
Deni Rinaldi's avatar
Deni Rinaldi committed
492 493
            "periode": this.state.periode.periode,
            "is_approver": true
Deni Rinaldi's avatar
Deni Rinaldi committed
494
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
495
        api.create().getSubmission(payload).then(response => {
496
            console.log(response)
Deni Rinaldi's avatar
Deni Rinaldi committed
497 498 499 500 501 502 503 504 505
            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
506
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
507
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
508 509 510 511 512 513
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
514
                }
Riri Novita's avatar
Riri Novita committed
515 516
            } else {
                this.setState({ submissionID: null, loading: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
517 518 519 520 521 522 523
            }
        })
    }

    getDataTable() {
        let payload = {
            "report_id": this.state.report.value,
524
            "revision": this.state.revisionType,
qorri_di's avatar
qorri_di committed
525
            "periode": this.state.periode.periode,
Deni Rinaldi's avatar
Deni Rinaldi committed
526
            "company_id": this.state.company.company_id,
Riri Novita's avatar
Riri Novita committed
527 528 529
            "submission_id": this.state.submissionID,
            "currency_id": this.state.defaultCurrency.id

Deni Rinaldi's avatar
Deni Rinaldi committed
530
        }
idlanirined's avatar
idlanirined committed
531
        if (this.state.report.value === 1) {
532
            api.create().getAllReportPLDetail(payload).then(response => {
Riri Novita's avatar
Riri Novita committed
533
                console.log(response);
Riri Novita's avatar
Riri Novita committed
534
                console.log(payload);
idlanirined's avatar
idlanirined committed
535 536
                let dataTable = []
                if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
                    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
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
                                    item.profit_loss.notes,
                                    item.profit_loss.ro_full_year_january,
                                    item.profit_loss.ro_full_year_february,
                                    item.profit_loss.ro_full_year_march,
                                    item.profit_loss.ro_full_year_april,
                                    item.profit_loss.ro_full_year_may,
                                    item.profit_loss.ro_full_year_june,
                                    item.profit_loss.ro_full_year_july,
                                    item.profit_loss.ro_full_year_august,
                                    item.profit_loss.ro_full_year_september,
                                    item.profit_loss.ro_full_year_october,
                                    item.profit_loss.ro_full_year_november,
                                    item.profit_loss.ro_full_year_december,
                                    item.profit_loss.ol_q1_january,
                                    item.profit_loss.ol_q1_february,
                                    item.profit_loss.ol_q1_march,
                                    item.profit_loss.ol_q1_april,
                                    item.profit_loss.ol_q1_may,
                                    item.profit_loss.ol_q1_june,
                                    item.profit_loss.ol_q1_july,
                                    item.profit_loss.ol_q1_august,
                                    item.profit_loss.ol_q1_september,
                                    item.profit_loss.ol_q1_october,
                                    item.profit_loss.ol_q1_november,
                                    item.profit_loss.ol_q1_december,
                                    item.profit_loss.ol_q2_january,
                                    item.profit_loss.ol_q2_february,
                                    item.profit_loss.ol_q2_march,
                                    item.profit_loss.ol_q2_april,
                                    item.profit_loss.ol_q2_may,
                                    item.profit_loss.ol_q2_june,
                                    item.profit_loss.ol_q2_july,
                                    item.profit_loss.ol_q2_august,
                                    item.profit_loss.ol_q2_september,
                                    item.profit_loss.ol_q2_october,
                                    item.profit_loss.ol_q2_november,
                                    item.profit_loss.ol_q2_december,
                                    item.profit_loss.ol_q3_january,
                                    item.profit_loss.ol_q3_february,
                                    item.profit_loss.ol_q3_march,
                                    item.profit_loss.ol_q3_april,
                                    item.profit_loss.ol_q3_may,
                                    item.profit_loss.ol_q3_june,
                                    item.profit_loss.ol_q3_july,
                                    item.profit_loss.ol_q3_august,
                                    item.profit_loss.ol_q3_september,
                                    item.profit_loss.ol_q3_october,
                                    item.profit_loss.ol_q3_november,
                                    item.profit_loss.ol_q3_december,
Riri Novita's avatar
Riri Novita committed
639 640 641 642 643 644 645 646 647 648 649 650
                                    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
651
                                    // item.profit_loss.historialLast10YearList,
Riri Novita's avatar
Riri Novita committed
652
                                    item.profit_loss.history_last_nine_year,
Riri Novita's avatar
Riri Novita committed
653
                                    item.profit_loss.history_last_eight_year,
Riri Novita's avatar
Riri Novita committed
654 655 656 657 658 659 660 661
                                    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
662

faisalhamdi's avatar
faisalhamdi committed
663 664 665 666 667 668 669 670 671 672 673
                                ])
                            }
                            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
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
                            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,
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
                                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,
721
                                item.profit_loss.monthly_last_year_december,
Riri Novita's avatar
Riri Novita committed
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
                                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
771 772 773 774 775 776 777 778 779 780 781 782
                                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
783
                                // item.profit_loss.historialLast10YearList
Riri Novita's avatar
Riri Novita committed
784
                                item.profit_loss.history_last_nine_year,
Riri Novita's avatar
Riri Novita committed
785
                                item.profit_loss.history_last_eight_year,
Riri Novita's avatar
Riri Novita committed
786 787 788 789 790 791 792 793
                                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
794
                            ])
faisalhamdi's avatar
faisalhamdi committed
795 796 797 798 799 800
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
idlanirined's avatar
idlanirined committed
801
                            }
faisalhamdi's avatar
faisalhamdi committed
802
                        })
Riri Novita's avatar
Riri Novita committed
803
                        console.log(dataTable)
faisalhamdi's avatar
faisalhamdi committed
804 805
                        // this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
806

faisalhamdi's avatar
faisalhamdi committed
807 808 809 810 811 812
                        // 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
813
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
faisalhamdi's avatar
faisalhamdi committed
814 815 816 817 818 819 820
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
idlanirined's avatar
idlanirined committed
821 822 823 824 825
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
            })
        } else if (this.state.report.value === 2) {
826
            api.create().getAllReportBS(payload).then(response => {
faisalhamdi's avatar
faisalhamdi committed
827 828
                console.log(payload);
                console.log(response);
idlanirined's avatar
idlanirined committed
829
                let dataTable = []
Deni Rinaldi's avatar
Deni Rinaldi committed
830
                if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
831 832 833 834 835 836 837 838 839 840 841 842 843
                    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,
Riri Novita's avatar
Riri Novita committed
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
                                    Number(item.balance_sheet.january),
                                    Number(item.balance_sheet.february),
                                    Number(item.balance_sheet.march),
                                    Number(item.balance_sheet.april),
                                    Number(item.balance_sheet.may),
                                    Number(item.balance_sheet.june),
                                    Number(item.balance_sheet.july),
                                    Number(item.balance_sheet.august),
                                    Number(item.balance_sheet.september),
                                    Number(item.balance_sheet.october),
                                    Number(item.balance_sheet.november),
                                    Number(item.balance_sheet.december),
                                    Number(item.balance_sheet.total_current_year),
                                    Number(item.balance_sheet.total_next_year),
                                    Number(item.balance_sheet.total_more_year),
faisalhamdi's avatar
faisalhamdi committed
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
                                    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
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
                                    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
934 935 936 937 938 939 940 941 942 943 944 945
                                    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
946
                                    // item.balance_sheet.historial_last_10_years_list,
Riri Novita's avatar
Riri Novita committed
947
                                    item.balance_sheet.history_last_nine_year,
Riri Novita's avatar
Riri Novita committed
948
                                    item.balance_sheet.history_last_eight_year,
Riri Novita's avatar
Riri Novita committed
949 950 951 952 953 954 955 956
                                    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
957

958

faisalhamdi's avatar
faisalhamdi committed
959 960 961 962 963 964 965 966 967 968 969
                                ])
                            }
                            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
970 971 972 973 974 975 976 977
                            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,
Riri Novita's avatar
Riri Novita committed
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
                                Number(item.balance_sheet.january),
                                Number(item.balance_sheet.february),
                                Number(item.balance_sheet.march),
                                Number(item.balance_sheet.april),
                                Number(item.balance_sheet.may),
                                Number(item.balance_sheet.june),
                                Number(item.balance_sheet.july),
                                Number(item.balance_sheet.august),
                                Number(item.balance_sheet.september),
                                Number(item.balance_sheet.october),
                                Number(item.balance_sheet.november),
                                Number(item.balance_sheet.december),
                                Number(item.balance_sheet.total_current_year),
                                Number(item.balance_sheet.total_next_year),
                                Number(item.balance_sheet.total_more_year),
Deni Rinaldi's avatar
Deni Rinaldi committed
993 994
                                item.order,
                                item.condition_it_should_be,
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
                                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
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
                                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
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
                                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
1080
                                // item.balance_sheet.historial_last_10_years_list
Riri Novita's avatar
Riri Novita committed
1081
                                item.balance_sheet.history_last_nine_year,
Riri Novita's avatar
Riri Novita committed
1082
                                item.balance_sheet.history_last_eight_year,
Riri Novita's avatar
Riri Novita committed
1083 1084 1085 1086 1087 1088 1089 1090 1091
                                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
1092
                            ])
faisalhamdi's avatar
faisalhamdi committed
1093 1094 1095 1096 1097 1098
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
1099
                            }
faisalhamdi's avatar
faisalhamdi committed
1100 1101 1102
                        })
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                        // this.setState({ dataTable }, () => {
1103
                        // console.log(this.state.dataTable)
faisalhamdi's avatar
faisalhamdi committed
1104 1105 1106 1107
                        //     this.getBalanceSheetMR(payload)
                        // })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
1108
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
faisalhamdi's avatar
faisalhamdi committed
1109 1110 1111 1112
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
Deni Rinaldi's avatar
Deni Rinaldi committed
1113
                            }
faisalhamdi's avatar
faisalhamdi committed
1114
                        })
1115 1116
                    }

Deni Rinaldi's avatar
Deni Rinaldi committed
1117
                } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
1118
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
1119
                }
Riri Novita's avatar
Riri Novita committed
1120
                console.log(dataTable);
idlanirined's avatar
idlanirined committed
1121 1122
            })
        } else if (this.state.report.value === 3) {
Riri Novita's avatar
Riri Novita committed
1123 1124 1125 1126 1127
            let PLID = null
            let payloadID = {
                "periode": this.state.periode.periode,
                "company_id": this.state.company.company_id
            }
Riri Novita's avatar
Riri Novita committed
1128
            // console.log(payloadID);
Riri Novita's avatar
Riri Novita committed
1129
            api.create().getPLID(payloadID).then(response => {
Riri Novita's avatar
Riri Novita committed
1130
                console.log(response);
Riri Novita's avatar
Riri Novita committed
1131
                if (response) {
1132
                    PLID = response.data.data == null ? null : response.data.data.profit_loss_id
Riri Novita's avatar
Riri Novita committed
1133
                    // PLID = response.data.data.profit_loss_id 
Riri Novita's avatar
Riri Novita committed
1134 1135 1136 1137
                } else {
                    PLID = null
                }
                this.setState({ PLID }, () => {
1138
                    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
1139 1140 1141 1142
                    console.log(payloads);
                    api.create().getReportPL(payloads).then(response => {
                        console.log(response);
                        if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
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 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
                            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
1200 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 1254 1255 1256 1257 1258 1259 1260
                                        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
1261
                                        item.profit_loss.history_current_year,
r.kurnia's avatar
r.kurnia committed
1262 1263 1264 1265 1266 1267 1268 1269 1270
                                        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
1271
                                    ])
idlanirined's avatar
idlanirined committed
1272

faisalhamdi's avatar
faisalhamdi committed
1273 1274 1275 1276 1277 1278
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
Riri Novita's avatar
Riri Novita committed
1279 1280
                                    }
                                }
faisalhamdi's avatar
faisalhamdi committed
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 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
                                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
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394
                                        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
1395
                                        item.profit_loss.history_current_year,
r.kurnia's avatar
r.kurnia committed
1396 1397 1398 1399 1400 1401 1402 1403 1404
                                        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
1405 1406 1407 1408 1409 1410 1411
                                    ])
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
Riri Novita's avatar
Riri Novita committed
1412
                                    }
faisalhamdi's avatar
faisalhamdi committed
1413 1414 1415
                                })
                                this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                                // this.setState({ dataTable , loading: false}, () => {
1416 1417
                                console.log(this.state.dataTable)
                                // this.getReportPLMR(payload)
faisalhamdi's avatar
faisalhamdi committed
1418 1419 1420
                                // })
                            } else {
                                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
1421
                                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
faisalhamdi's avatar
faisalhamdi committed
1422 1423 1424 1425 1426 1427 1428
                                        setTimeout(() => {
                                            localStorage.removeItem(Constant.TOKEN)
                                            window.location.reload();
                                        }, 1000);
                                    }
                                })
                            }
Riri Novita's avatar
Riri Novita committed
1429 1430
                        } else {
                            this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
1431 1432
                        }
                    })
Riri Novita's avatar
Riri Novita committed
1433
                })
idlanirined's avatar
idlanirined committed
1434
            })
faisalhamdi's avatar
faisalhamdi committed
1435
        } else if (this.state.report.value === 4) {
Riri Novita's avatar
Riri Novita committed
1436 1437 1438 1439 1440 1441
            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
1442
                console.log(response);
Riri Novita's avatar
Riri Novita committed
1443
                if (response) {
1444
                    FRID = response.data.data == null ? null : response.data.data.ratio_id
Riri Novita's avatar
Riri Novita committed
1445 1446 1447 1448
                } else {
                    FRID = null
                }
                this.setState({ FRID }, () => {
1449
                    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
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467
                    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
1468
                                            0,
rifkaki's avatar
rifkaki committed
1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482
                                            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
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494
                                            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
1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506
                                            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
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577
                                            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
1578
                                        ])
1579
                                    }
Riri Novita's avatar
Riri Novita committed
1580 1581 1582 1583 1584 1585 1586
                                    if (item.children !== null) {
                                        if (item.children.length > 0) {
                                            item.children.map((items, indexs) => {
                                                handlePushChild(items)
                                            })
                                        }
                                    }
faisalhamdi's avatar
faisalhamdi committed
1587
                                }
Riri Novita's avatar
Riri Novita committed
1588 1589 1590 1591 1592 1593 1594 1595 1596
                                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
1597
                                        0,
rifkaki's avatar
rifkaki committed
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611
                                        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
1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623
                                        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
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635
                                        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
1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
                                        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
1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722
                                    ])
                                    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
1723
                                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
1724 1725 1726 1727 1728 1729
                                        setTimeout(() => {
                                            localStorage.removeItem(Constant.TOKEN)
                                            window.location.reload();
                                        }, 1000);
                                    }
                                })
faisalhamdi's avatar
faisalhamdi committed
1730
                            }
Riri Novita's avatar
Riri Novita committed
1731 1732 1733 1734 1735
                        } else {
                            this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                        }
                    })
                })
faisalhamdi's avatar
faisalhamdi committed
1736
            })
d.arizona's avatar
d.arizona committed
1737
        } else if (this.state.report.value === 5) {
rifkaki's avatar
rifkaki committed
1738
            api.create().getReportTP(payload).then(response => {
rifkaki's avatar
rifkaki committed
1739
                console.log(payload);
d.arizona's avatar
d.arizona committed
1740 1741 1742 1743 1744 1745 1746 1747 1748 1749
                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
1750 1751 1752 1753 1754 1755
                                    // 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
1756 1757 1758 1759 1760
                                    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
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772
                                    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
1773
                                    item.order,
rifkaki's avatar
rifkaki committed
1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785
                                    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
1786
                                    item.tax_planning_report.monthly_full_year,
d.arizona's avatar
d.arizona committed
1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799
                                ])
                            }
                            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
1800 1801 1802 1803 1804 1805
                                // 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
1806 1807 1808 1809 1810
                                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
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822
                                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
1823
                                item.order,
rifkaki's avatar
rifkaki committed
1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835
                                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
1836
                                item.tax_planning_report.monthly_full_year,
d.arizona's avatar
d.arizona committed
1837 1838 1839 1840 1841 1842 1843 1844 1845
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
rifkaki's avatar
rifkaki committed
1846
                        console.log(dataTable)
rifkaki's avatar
rifkaki committed
1847 1848 1849 1850
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                        // this.setState({ dataTable }, () => {
                        //     this.getTaxPlanMR(payload)
                        // })
d.arizona's avatar
d.arizona committed
1851
                    } else {
d.arizona's avatar
d.arizona committed
1852
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
1853
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
1854 1855 1856 1857 1858 1859
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
d.arizona's avatar
d.arizona committed
1860
                    }
d.arizona's avatar
d.arizona committed
1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877
                } 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
1878
                        OPID = null
d.arizona's avatar
d.arizona committed
1879
                    }
d.arizona's avatar
d.arizona committed
1880
                    this.setState({ OPID }, () => {
d.arizona's avatar
d.arizona committed
1881 1882 1883 1884
                        let payloadOI = {
                            "company_id": this.state.company.company_id,
                            "operating_indicator_id": this.state.OPID,
                            "periode": this.state.periode.periode,
Riri Novita's avatar
Riri Novita committed
1885 1886
                            "report_id": 21,
                            "currency_id": this.state.defaultCurrency.id
d.arizona's avatar
d.arizona committed
1887
                        }
d.arizona's avatar
d.arizona committed
1888

1889
                        api.create().getAllReportOI(payloadOI).then(response => {
d.arizona's avatar
d.arizona committed
1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907
                            // 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,
Riri Novita's avatar
Riri Novita committed
1908 1909
                                                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),
                                                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),
d.arizona's avatar
d.arizona committed
1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921
                                                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),
1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934
                                                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
1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953
                                            ])
                                        }
                                        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,
Riri Novita's avatar
Riri Novita committed
1954 1955
                                            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),
                                            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),
d.arizona's avatar
d.arizona committed
1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967
                                            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),
1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980
                                            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
1981 1982 1983 1984 1985 1986 1987 1988 1989
                                        ])
                                        if (item.children !== null) {
                                            if (item.children.length > 0) {
                                                item.children.map((items, indexs) => {
                                                    handlePushChild(items)
                                                })
                                            }
                                        }
                                    })
d.arizona's avatar
d.arizona committed
1990
                                    this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
1991 1992 1993 1994 1995

                                    // this.setState({ dataTable }, () => {
                                    //     console.log(this.state.dataTable)
                                    //     this.getOIMR(payloadOI)
                                    // })
d.arizona's avatar
d.arizona committed
1996
                                } else {
d.arizona's avatar
d.arizona committed
1997
                                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
1998
                                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
1999 2000 2001 2002 2003 2004
                                            setTimeout(() => {
                                                localStorage.removeItem(Constant.TOKEN)
                                                window.location.reload();
                                            }, 1000);
                                        }
                                    })
d.arizona's avatar
d.arizona committed
2005
                                }
d.arizona's avatar
d.arizona committed
2006 2007 2008 2009 2010
                            } else {
                                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                            }
                        })
                    })
d.arizona's avatar
d.arizona committed
2011 2012
                }
            })
d.arizona's avatar
d.arizona committed
2013
        } else if (this.state.report.value === 6) {
d.arizona's avatar
d.arizona committed
2014
            let dbSumaCF = []
d.arizona's avatar
d.arizona committed
2015
            let paylodCF = { ...payload, months: this.state.month.month_id }
2016
            console.log(paylodCF);
d.arizona's avatar
d.arizona committed
2017
            api.create().getReportCFSuma(paylodCF).then(response => {
d.arizona's avatar
d.arizona committed
2018
                console.log(response)
d.arizona's avatar
d.arizona committed
2019 2020 2021
                if (response.data) {
                    if (response.data.status === 'success') {
                        let res = response.data.data
d.arizona's avatar
d.arizona committed
2022
                        console.log(res)
d.arizona's avatar
d.arizona committed
2023
                        const handlePushChild = (item) => {
rifkaki's avatar
rifkaki committed
2024
                            let indexIDzz = dbSumaCF.findIndex((val) => val[0] === item.id)
d.arizona's avatar
d.arizona committed
2025
                            if (indexIDzz === -1) {
rifkaki's avatar
rifkaki committed
2026 2027
                                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)
Riri Novita's avatar
Riri Novita committed
2028
                                // console.log(mtd)
rifkaki's avatar
rifkaki committed
2029 2030 2031 2032
                                // let persenMtd = Number(mtd_actual / mtd)
                                let persenMtd = 0
                                if (mtd < 0) {
                                    if (mtd_actual >= mtd) {
2033 2034 2035
                                        persenMtd = ((mtd - mtd_actual) / mtd + 1)
                                    } else {
                                        persenMtd = ((mtd - mtd_actual) / mtd)
rifkaki's avatar
rifkaki committed
2036 2037 2038
                                    }
                                }
                                else {
2039
                                    persenMtd = Number(mtd_actual / mtd)
rifkaki's avatar
rifkaki committed
2040 2041 2042 2043 2044 2045 2046
                                }

                                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
2047
                                if (ytd < 0) {
rifkaki's avatar
rifkaki committed
2048
                                    if (ytd_actual >= ytd) {
2049 2050 2051
                                        persenYtd = ((ytd - ytd_actual) / ytd + 1)
                                    } else {
                                        persenYtd = ((ytd - ytd_actual) / ytd)
rifkaki's avatar
rifkaki committed
2052 2053 2054
                                    }
                                }
                                else {
2055
                                    persenYtd = Number(ytd_actual / ytd)
rifkaki's avatar
rifkaki committed
2056
                                }
d.arizona's avatar
d.arizona committed
2057

rifkaki's avatar
rifkaki committed
2058
                                let quarter_actual = item.cash_flow.quarter_actual == '' ? 0 : Number(item.cash_flow.quarter_actual)
d.arizona's avatar
d.arizona committed
2059
                                let quarter = item.cash_flow.quarter_mb == '' ? 0 : Number(item.cash_flow.quarter_mb)
rifkaki's avatar
rifkaki committed
2060 2061
                                // let persenQuarter = Number(quarter_actual / quarter)
                                let persenQuarter = 0
2062
                                if (quarter < 0) {
rifkaki's avatar
rifkaki committed
2063
                                    if (quarter_actual >= quarter) {
2064 2065 2066
                                        persenQuarter = (quarter - quarter_actual) / quarter + 1
                                    } else {
                                        persenQuarter = (quarter - quarter_actual) / quarter
rifkaki's avatar
rifkaki committed
2067 2068 2069 2070 2071
                                    }
                                }
                                else {
                                    persenQuarter = quarter_actual / quarter
                                }
d.arizona's avatar
d.arizona committed
2072

rifkaki's avatar
rifkaki committed
2073 2074
                                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
2075
                                // let persenFy = Number(fy_actual / fy)
2076
                                // console.log(fy_actual);
rifkaki's avatar
rifkaki committed
2077
                                let persenFy = 0
2078
                                if (fy < 0) {
rifkaki's avatar
rifkaki committed
2079
                                    if (fy_actual >= fy) {
2080 2081 2082
                                        persenFy = (fy - fy_actual) / fy + 1
                                    } else {
                                        persenFy = (fy - fy_actual) / fy
rifkaki's avatar
rifkaki committed
2083 2084 2085 2086 2087
                                    }
                                }
                                else {
                                    persenFy = fy_actual / fy
                                }
2088 2089
                                let ol = item.cash_flow.fy_ol == '' ? 0 : Number(item.cash_flow.fy_ol)
                                let persenOL = 0
2090
                                if (fy < 0) {
2091
                                    if (ol >= fy) {
2092 2093 2094
                                        persenOL = (fy - ol) / fy + 1
                                    } else {
                                        persenOL = (fy - ol) / fy
2095 2096 2097 2098 2099
                                    }
                                }
                                else {
                                    persenOL = ol / fy
                                }
d.arizona's avatar
d.arizona committed
2100 2101

                                dbSumaCF.push([
d.arizona's avatar
d.arizona committed
2102
                                    item.id,
d.arizona's avatar
d.arizona committed
2103 2104
                                    item.cash_flow.mtd_actual,
                                    item.cash_flow.mtd,
d.arizona's avatar
d.arizona committed
2105
                                    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
2106 2107 2108
                                    item.cash_flow.mtd_last_year,
                                    item.cash_flow.ytd_actual,
                                    item.cash_flow.ytd,
d.arizona's avatar
d.arizona committed
2109
                                    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
2110
                                    // isNaN(persenYtd)? 0 : persenYtd * 100,
d.arizona's avatar
d.arizona committed
2111 2112
                                    item.cash_flow.ytd_last_year,
                                    item.cash_flow.quarter_actual,
d.arizona's avatar
d.arizona committed
2113 2114
                                    item.cash_flow.quarter_mb,
                                    isNaN(persenQuarter) || persenQuarter == 'Infinity' || persenQuarter == '-Infinity' ? (item.cash_flow.quarter_mb == '' || item.cash_flow.quarter_mb == 0 ? -0 : 0) : (item.cash_flow.quarter_mb == '' || item.cash_flow.quarter_mb == 0 ? persenQuarter * -100 : persenQuarter * 100),
d.arizona's avatar
d.arizona committed
2115
                                    // isNaN(persenQuarter)? 0 : persenQuarter * 100,
d.arizona's avatar
d.arizona committed
2116 2117 2118
                                    item.cash_flow.quarter_last_year,
                                    item.cash_flow.fy_actual,
                                    item.cash_flow.fy,
d.arizona's avatar
d.arizona committed
2119
                                    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),
2120 2121
                                    item.cash_flow.fy_ol,
                                    isNaN(persenOL) || persenOL == 'Infinity' || persenOL == '-Infinity' ? (item.cash_flow.fy_ol == '' || item.cash_flow.fy_ol == 0 ? -0 : 0) : (item.cash_flow.fy_ol == '' || item.cash_flow.fy_ol == 0 ? persenOL * -100 : persenOL * 100),
d.arizona's avatar
d.arizona committed
2122
                                    // isNaN(persenFy)? 0 : persenFy * 100,
d.arizona's avatar
d.arizona committed
2123
                                    item.cash_flow.fy_last_year,
d.arizona's avatar
d.arizona committed
2124 2125 2126 2127 2128 2129 2130 2131 2132 2133
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
d.arizona's avatar
d.arizona committed
2134
                        res.map((item, index) => {
rifkaki's avatar
rifkaki committed
2135 2136
                            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)
2137
                            // console.log(mtd)
rifkaki's avatar
rifkaki committed
2138 2139 2140 2141
                            // let persenMtd = Number(mtd_actual / mtd)
                            let persenMtd = 0
                            if (mtd < 0) {
                                if (mtd_actual >= mtd) {
2142 2143 2144
                                    persenMtd = ((mtd - mtd_actual) / mtd + 1)
                                } else {
                                    persenMtd = ((mtd - mtd_actual) / mtd)
rifkaki's avatar
rifkaki committed
2145 2146 2147
                                }
                            }
                            else {
2148
                                persenMtd = Number(mtd_actual / mtd)
rifkaki's avatar
rifkaki committed
2149 2150 2151 2152 2153 2154
                            }

                            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
2155
                            if (ytd < 0) {
rifkaki's avatar
rifkaki committed
2156
                                if (ytd_actual >= ytd) {
2157 2158 2159
                                    persenYtd = ((ytd - ytd_actual) / ytd + 1)
                                } else {
                                    persenYtd = ((ytd - ytd_actual) / ytd)
rifkaki's avatar
rifkaki committed
2160 2161 2162
                                }
                            }
                            else {
2163
                                persenYtd = Number(ytd_actual / ytd)
rifkaki's avatar
rifkaki committed
2164
                            }
d.arizona's avatar
d.arizona committed
2165

rifkaki's avatar
rifkaki committed
2166
                            let quarter_actual = item.cash_flow.quarter_actual == '' ? 0 : Number(item.cash_flow.quarter_actual)
d.arizona's avatar
d.arizona committed
2167
                            let quarter = item.cash_flow.quarter_mb == '' ? 0 : Number(item.cash_flow.quarter_mb)
rifkaki's avatar
rifkaki committed
2168 2169
                            // let persenQuarter = Number(quarter_actual / quarter)
                            let persenQuarter = 0
2170
                            if (quarter < 0) {
rifkaki's avatar
rifkaki committed
2171
                                if (quarter_actual >= quarter) {
2172 2173 2174
                                    persenQuarter = (quarter - quarter_actual) / quarter + 1
                                } else {
                                    persenQuarter = (quarter - quarter_actual) / quarter
rifkaki's avatar
rifkaki committed
2175 2176 2177 2178 2179
                                }
                            }
                            else {
                                persenQuarter = quarter_actual / quarter
                            }
d.arizona's avatar
d.arizona committed
2180

rifkaki's avatar
rifkaki committed
2181 2182
                            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
2183 2184
                            // let persenFy = Number(fy_actual / fy)
                            let persenFy = 0
2185
                            if (fy < 0) {
rifkaki's avatar
rifkaki committed
2186
                                if (fy_actual >= fy) {
2187 2188 2189
                                    persenFy = (fy - fy_actual) / fy + 1
                                } else {
                                    persenFy = (fy - fy_actual) / fy
rifkaki's avatar
rifkaki committed
2190 2191 2192 2193 2194
                                }
                            }
                            else {
                                persenFy = fy_actual / fy
                            }
2195 2196
                            let ol = item.cash_flow.fy_ol == '' ? 0 : Number(item.cash_flow.fy_ol)
                            let persenOl = 0
2197
                            if (fy < 0) {
2198
                                if (ol >= fy) {
2199 2200 2201
                                    persenOl = (fy - ol) / fy + 1
                                } else {
                                    persenOl = (fy - ol) / fy
2202 2203 2204 2205 2206
                                }
                            }
                            else {
                                persenOl = ol / fy
                            }
d.arizona's avatar
d.arizona committed
2207 2208

                            dbSumaCF.push([
d.arizona's avatar
d.arizona committed
2209
                                item.id,
d.arizona's avatar
d.arizona committed
2210 2211
                                item.cash_flow.mtd_actual,
                                item.cash_flow.mtd,
d.arizona's avatar
d.arizona committed
2212
                                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
2213 2214 2215
                                item.cash_flow.mtd_last_year,
                                item.cash_flow.ytd_actual,
                                item.cash_flow.ytd,
d.arizona's avatar
d.arizona committed
2216
                                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
2217
                                // isNaN(persenYtd)? 0 : persenYtd * 100,
d.arizona's avatar
d.arizona committed
2218 2219
                                item.cash_flow.ytd_last_year,
                                item.cash_flow.quarter_actual,
d.arizona's avatar
d.arizona committed
2220 2221
                                item.cash_flow.quarter_mb,
                                isNaN(persenQuarter) || persenQuarter == 'Infinity' || persenQuarter == '-Infinity' ? (item.cash_flow.quarter_mb == '' || item.cash_flow.quarter_mb == 0 ? -0 : 0) : (item.cash_flow.quarter_mb == '' || item.cash_flow.quarter_mb == 0 ? persenQuarter * -100 : persenQuarter * 100),
d.arizona's avatar
d.arizona committed
2222
                                // isNaN(persenQuarter)? 0 : persenQuarter * 100,
d.arizona's avatar
d.arizona committed
2223 2224 2225
                                item.cash_flow.quarter_last_year,
                                item.cash_flow.fy_actual,
                                item.cash_flow.fy,
d.arizona's avatar
d.arizona committed
2226
                                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),
2227 2228
                                item.cash_flow.fy_ol,
                                isNaN(persenOl) || persenOl == 'Infinity' || persenOl == '-Infinity' ? (item.cash_flow.fy_ol == '' || item.cash_flow.fy_ol == 0 ? -0 : 0) : (item.cash_flow.fy_ol == '' || item.cash_flow.fy_ol == 0 ? persenOl * -100 : persenOl * 100),
d.arizona's avatar
d.arizona committed
2229
                                // isNaN(persenFy)? 0 : persenFy * 100,
d.arizona's avatar
d.arizona committed
2230
                                item.cash_flow.fy_last_year,
d.arizona's avatar
d.arizona committed
2231 2232 2233 2234 2235 2236 2237 2238 2239
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
d.arizona's avatar
d.arizona committed
2240
                        console.log(dbSumaCF)
d.arizona's avatar
d.arizona committed
2241
                        this.setState({ dbSumaCF }, () => {
d.arizona's avatar
d.arizona committed
2242 2243 2244 2245 2246 2247 2248
                            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
2249
                                        console.log(res)
d.arizona's avatar
d.arizona committed
2250 2251
                                        const handlePushChild = (item) => {
                                            let indexIDzz = dataTable.findIndex((val) => val[1] === item.id)
2252
                                            let indexIDSuma = dbSumaCF.findIndex((val) => val[0] === item.id)
d.arizona's avatar
d.arizona committed
2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279
                                            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
2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292
                                                    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,
Riri Novita's avatar
Riri Novita committed
2293
                                                    item.cash_flow.olpa_total_current_year,
2294 2295
                                                    ...dbSumaCF[indexIDSuma]

d.arizona's avatar
d.arizona committed
2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306
                                                ])
                                            }
                                            if (item.children !== null) {
                                                if (item.children.length > 0) {
                                                    item.children.map((items, indexs) => {
                                                        handlePushChild(items)
                                                    })
                                                }
                                            }
                                        }
                                        res.map((item, index) => {
2307
                                            let indexIDSuma = dbSumaCF.findIndex((val) => val[0] === item.id)
d.arizona's avatar
d.arizona committed
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
                                            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
2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346
                                                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,
Riri Novita's avatar
Riri Novita committed
2347
                                                item.cash_flow.olpa_total_current_year,
2348
                                                ...dbSumaCF[indexIDSuma]
d.arizona's avatar
d.arizona committed
2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359
                                            ])
                                            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
2360
                                            this.getCFSumaMR(paylodCF, dbSumaCF)
d.arizona's avatar
d.arizona committed
2361
                                        })
d.arizona's avatar
d.arizona committed
2362
                                    } else {
d.arizona's avatar
d.arizona committed
2363
                                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
2364
                                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
2365 2366 2367 2368 2369 2370
                                                setTimeout(() => {
                                                    localStorage.removeItem(Constant.TOKEN)
                                                    window.location.reload();
                                                }, 1000);
                                            }
                                        })
d.arizona's avatar
d.arizona committed
2371
                                    }
d.arizona's avatar
d.arizona committed
2372 2373 2374
                                } else {
                                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                                }
Riri Novita's avatar
Riri Novita committed
2375
                                console.log(dataTable);
d.arizona's avatar
d.arizona committed
2376
                            })
d.arizona's avatar
d.arizona committed
2377
                        })
d.arizona's avatar
d.arizona committed
2378
                    } else {
d.arizona's avatar
d.arizona committed
2379
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
2380
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
2381 2382 2383 2384 2385 2386
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
d.arizona's avatar
d.arizona committed
2387
                    }
d.arizona's avatar
d.arizona committed
2388 2389 2390 2391
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                }
            })
Riri Novita's avatar
Riri Novita committed
2392
        } else if (this.state.report.value === 7) {
faisalhamdi's avatar
faisalhamdi committed
2393
            let dbSumaBS = []
2394
            let payloadBS = { ...payload, report_id: 2, months: this.state.month.month_id, quarter: 0 }
faisalhamdi's avatar
faisalhamdi committed
2395 2396
            api.create().getReportBSSuma(payloadBS).then(response => {
                // console.log(payloadBS);
Riri Novita's avatar
Riri Novita committed
2397
                console.log(response);
faisalhamdi's avatar
faisalhamdi committed
2398
                if (response.data) {
faisalhamdi's avatar
faisalhamdi committed
2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410
                    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) {
2411
                                    if (parseFloat(mtd_actual) < parseFloat(mtd_mb)) {
2412
                                        persenMtd = Number((mtd_mb - mtd_actual) / mtd_mb)
faisalhamdi's avatar
faisalhamdi committed
2413
                                    } else {
2414
                                        persenMtd = Number((mtd_mb - mtd_actual) / mtd_mb) + 1
faisalhamdi's avatar
faisalhamdi committed
2415 2416
                                    }
                                } else {
2417
                                    persenMtd = Number(mtd_actual / mtd_mb)
faisalhamdi's avatar
faisalhamdi committed
2418 2419 2420
                                }

                                if (mtd_ol < 0) {
2421
                                    if (parseFloat(mtd_actual) < parseFloat(mtd_ol)) {
2422
                                        persenOL = Number((mtd_ol - mtd_actual) / mtd_ol)
faisalhamdi's avatar
faisalhamdi committed
2423
                                    } else {
2424
                                        persenOL = Number((mtd_ol - mtd_actual) / mtd_ol) + 1
faisalhamdi's avatar
faisalhamdi committed
2425 2426
                                    }
                                } else {
2427
                                    persenOL = Number(mtd_actual / mtd_ol)
faisalhamdi's avatar
faisalhamdi committed
2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464
                                }

                                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) {
2465
                                if (parseFloat(mtd_actual) < parseFloat(mtd_mb)) {
2466
                                    persenMtd = Number((mtd_mb - mtd_actual) / mtd_mb)
faisalhamdi's avatar
faisalhamdi committed
2467
                                } else {
2468
                                    persenMtd = Number((mtd_mb - mtd_actual) / mtd_mb) + 1
faisalhamdi's avatar
faisalhamdi committed
2469 2470
                                }
                            } else {
2471
                                persenMtd = Number(mtd_actual / mtd_mb)
faisalhamdi's avatar
faisalhamdi committed
2472 2473 2474
                            }

                            if (mtd_ol < 0) {
2475
                                if (parseFloat(mtd_actual) < parseFloat(mtd_ol)) {
2476
                                    persenOL = Number((mtd_ol - mtd_actual) / mtd_ol)
faisalhamdi's avatar
faisalhamdi committed
2477
                                } else {
2478
                                    persenOL = Number((mtd_ol - mtd_actual) / mtd_ol) + 1
faisalhamdi's avatar
faisalhamdi committed
2479 2480
                                }
                            } else {
2481
                                persenOL = Number(mtd_actual / mtd_ol)
faisalhamdi's avatar
faisalhamdi committed
2482 2483 2484
                            }

                            dbSumaBS.push([
faisalhamdi's avatar
faisalhamdi committed
2485 2486 2487 2488 2489 2490
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
faisalhamdi's avatar
faisalhamdi committed
2491
                                item.balance_sheet.mtd_last_month,
d.arizona's avatar
d.arizona committed
2492 2493
                                item.balance_sheet.mtd_actual,
                                item.balance_sheet.mtd_mb,
faisalhamdi's avatar
faisalhamdi committed
2494
                                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
2495
                                item.balance_sheet.mtd_ol,
faisalhamdi's avatar
faisalhamdi committed
2496
                                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
2497
                                item.balance_sheet.mtd_last_year,
faisalhamdi's avatar
faisalhamdi committed
2498
                                item.balance_sheet.forecast_next_year,
d.arizona's avatar
d.arizona committed
2499
                                item.balance_sheet.forecast_more_year,
faisalhamdi's avatar
faisalhamdi committed
2500 2501
                                item.order
                            ])
faisalhamdi's avatar
faisalhamdi committed
2502 2503 2504 2505 2506 2507
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
faisalhamdi's avatar
faisalhamdi committed
2508
                            }
faisalhamdi's avatar
faisalhamdi committed
2509 2510
                        })
                        this.setState({ dataTable: dbSumaBS, previewTable: true, loading: false, previewDownload: true })
d.arizona's avatar
d.arizona committed
2511
                        console.log(this.state.dataTable)
faisalhamdi's avatar
faisalhamdi committed
2512 2513
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
2514
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
faisalhamdi's avatar
faisalhamdi committed
2515 2516 2517 2518 2519 2520
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
2521
                    }
faisalhamdi's avatar
faisalhamdi committed
2522
                } else {
faisalhamdi's avatar
faisalhamdi committed
2523
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
faisalhamdi's avatar
faisalhamdi committed
2524
                }
Riri Novita's avatar
Riri Novita committed
2525 2526 2527
            })

        } else if (this.state.report.value === 8) {
Riri Novita's avatar
Riri Novita committed
2528
            let dbSumaPL = []
2529
            let payloadPL = { ...payload, report_id: 28, months: this.state.month.month_id }
Riri Novita's avatar
Riri Novita committed
2530
            api.create().getReportPLSuma(payloadPL).then(response => {
Riri Novita's avatar
Riri Novita committed
2531
                console.log(response);
Riri Novita's avatar
Riri Novita committed
2532 2533 2534
                if (response.data) {
                    if (response.data.status === 'success') {
                        let res = response.data.data
2535
                        console.log(res)
Riri Novita's avatar
Riri Novita committed
2536 2537 2538
                        const handlePushChild = (item) => {
                            let indexIDzz = dbSumaPL.findIndex((val) => val[1] === item.id)
                            if (indexIDzz === -1) {
faisalhamdi's avatar
faisalhamdi committed
2539
                                let month = this.state.month.month_value;
2540 2541 2542
                                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
2543
                                let persenMtd = 0
2544
                                if (mtd_mb < 0) {
Riri Novita's avatar
Riri Novita committed
2545
                                    if (mtd_actual >= mtd_mb) {
2546 2547 2548
                                        persenMtd = (mtd_mb - mtd_actual) / mtd_mb + 1
                                    } else {
                                        persenMtd = (mtd_mb - mtd_actual) / mtd_mb
Riri Novita's avatar
Riri Novita committed
2549 2550 2551
                                    }
                                }
                                else {
Riri Novita's avatar
Riri Novita committed
2552
                                    persenMtd = mtd_actual / mtd_mb
Riri Novita's avatar
Riri Novita committed
2553 2554
                                }

Riri Novita's avatar
Riri Novita committed
2555
                                let persenMtdLY = 0
2556
                                if (mtd_last_year < 0) {
Riri Novita's avatar
Riri Novita committed
2557
                                    if (mtd_actual >= mtd_last_year) {
2558 2559
                                        persenMtdLY = (mtd_last_year - mtd_actual) / mtd_last_year + 1
                                    } else {
Riri Novita's avatar
Riri Novita committed
2560 2561 2562 2563
                                        persenMtdLY = (mtd_last_year - mtd_actual) / mtd_last_year
                                    }
                                }
                                else {
2564
                                    persenMtdLY = mtd_actual / mtd_last_year
Riri Novita's avatar
Riri Novita committed
2565 2566 2567
                                }


2568 2569 2570
                                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)
Riri Novita's avatar
Riri Novita committed
2571
                                let persenYtdMB = 0
2572
                                if (ytd_mb < 0) {
Riri Novita's avatar
Riri Novita committed
2573
                                    if (ytd_actual >= ytd_mb) {
2574 2575 2576
                                        persenYtdMB = (ytd_mb - ytd_actual) / ytd_mb + 1
                                    } else {
                                        persenYtdMB = (ytd_mb - ytd_actual) / ytd_mb
Riri Novita's avatar
Riri Novita committed
2577 2578 2579
                                    }
                                }
                                else {
2580
                                    persenYtdMB = ytd_actual / ytd_mb
Riri Novita's avatar
Riri Novita committed
2581 2582 2583
                                }

                                let persenYtdLY = 0
2584
                                if (ytd_last_year < 0) {
Riri Novita's avatar
Riri Novita committed
2585
                                    if (ytd_actual >= ytd_last_year) {
2586 2587 2588
                                        persenYtdLY = (ytd_last_year - ytd_actual) / ytd_last_year + 1
                                    } else {
                                        persenYtdLY = (ytd_last_year - ytd_actual) / ytd_last_year
Riri Novita's avatar
Riri Novita committed
2589 2590 2591
                                    }
                                }
                                else {
2592
                                    persenYtdLY = ytd_actual / ytd_last_year
Riri Novita's avatar
Riri Novita committed
2593 2594
                                }

faisalhamdi's avatar
faisalhamdi committed
2595
                                // let q1_actual = item.profit_loss.q1_actual == ''? 0 : Number(item.profit_loss.q1_actual)
2596
                                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
faisalhamdi's avatar
faisalhamdi committed
2597
                                // let q1_mb = item.profit_loss.q1_mb == ''? 0 : Number(item.profit_loss.q1_mb)
2598
                                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
faisalhamdi's avatar
faisalhamdi committed
2599
                                // let q1_last_year = item.profit_loss.q1_last_year == ''? 0 : Number(item.profit_loss.q1_last_year)
2600
                                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
2601
                                let persenQuarterMB = 0
2602
                                if (q_mb < 0) {
faisalhamdi's avatar
faisalhamdi committed
2603
                                    if (q_actual >= q_mb) {
2604 2605 2606
                                        persenQuarterMB = (q_mb - q_actual) / q_mb + 1
                                    } else {
                                        persenQuarterMB = (q_mb - q_actual) / q_mb
Riri Novita's avatar
Riri Novita committed
2607 2608 2609
                                    }
                                }
                                else {
2610
                                    persenQuarterMB = q_actual / q_mb
Riri Novita's avatar
Riri Novita committed
2611
                                }
Riri Novita's avatar
Riri Novita committed
2612

Riri Novita's avatar
Riri Novita committed
2613
                                let persenQuarterLY = 0
2614
                                if (q_last_year < 0) {
faisalhamdi's avatar
faisalhamdi committed
2615
                                    if (q_actual >= q_last_year) {
2616 2617 2618
                                        persenQuarterLY = (q_last_year - q_actual) / q_last_year + 1
                                    } else {
                                        persenQuarterLY = (q_last_year - q_actual) / q_last_year
Riri Novita's avatar
Riri Novita committed
2619 2620 2621
                                    }
                                }
                                else {
2622
                                    persenQuarterLY = q_actual / q_last_year
Riri Novita's avatar
Riri Novita committed
2623 2624
                                }

2625 2626 2627 2628
                                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)
Riri Novita's avatar
Riri Novita committed
2629
                                let persenFyMB = 0
2630
                                if (fy_mb < 0) {
Riri Novita's avatar
Riri Novita committed
2631
                                    if (fy_actual >= fy_mb) {
2632 2633 2634
                                        persenFyMB = (fy_mb - fy_actual) / fy_mb + 1
                                    } else {
                                        persenFyMB = (fy_mb - fy_actual) / fy_mb
Riri Novita's avatar
Riri Novita committed
2635 2636 2637
                                    }
                                }
                                else {
2638
                                    persenFyMB = fy_actual / fy_mb
Riri Novita's avatar
Riri Novita committed
2639 2640 2641
                                }

                                let persenFyOL = 0
2642
                                if (fy_ol < 0) {
Riri Novita's avatar
Riri Novita committed
2643
                                    if (fy_actual >= fy_ol) {
2644 2645 2646
                                        persenFyOL = (fy_ol - fy_actual) / fy_ol + 1
                                    } else {
                                        persenFyOL = (fy_ol - fy_actual) / fy_ol
Riri Novita's avatar
Riri Novita committed
2647 2648 2649
                                    }
                                }
                                else {
2650
                                    persenFyOL = fy_actual / fy_ol
Riri Novita's avatar
Riri Novita committed
2651 2652 2653
                                }

                                let persenFyLY = 0
2654
                                if (fy_last_year < 0) {
Riri Novita's avatar
Riri Novita committed
2655
                                    if (fy_actual >= fy_last_year) {
2656 2657 2658
                                        persenFyLY = (fy_last_year - fy_actual) / fy_last_year + 1
                                    } else {
                                        persenFyLY = (fy_last_year - fy_actual) / fy_last_year
Riri Novita's avatar
Riri Novita committed
2659 2660 2661
                                    }
                                }
                                else {
2662
                                    persenFyLY = fy_actual / fy_last_year
Riri Novita's avatar
Riri Novita committed
2663
                                }
Riri Novita's avatar
Riri Novita committed
2664

Riri Novita's avatar
Riri Novita committed
2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683
                                // 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
2684
                                if (fy_mb < 0) {
Riri Novita's avatar
Riri Novita committed
2685
                                    if (fy_ol >= fy_mb) {
2686 2687 2688
                                        persenFyOLMB = (fy_mb - fy_ol) / fy_mb + 1
                                    } else {
                                        persenFyOLMB = (fy_mb - fy_ol) / fy_mb
Riri Novita's avatar
Riri Novita committed
2689 2690 2691
                                    }
                                }
                                else {
2692
                                    persenFyOLMB = fy_ol / fy_mb
Riri Novita's avatar
Riri Novita committed
2693
                                }
Riri Novita's avatar
Riri Novita committed
2694 2695

                                dbSumaPL.push([
Riri Novita's avatar
Riri Novita committed
2696
                                    item.type_report_id,
Riri Novita's avatar
Riri Novita committed
2697
                                    item.id,
Riri Novita's avatar
Riri Novita committed
2698 2699 2700 2701
                                    item.parent,
                                    item.formula,
                                    item.level,
                                    item.description,
Riri Novita's avatar
Riri Novita committed
2702
                                    item.profit_loss.mtd_actual,
Riri Novita's avatar
Riri Novita committed
2703
                                    item.profit_loss.mtd_mb,
2704
                                    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
2705
                                    item.profit_loss.mtd_last_year,
2706
                                    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
2707
                                    item.profit_loss.ytd_actual,
Riri Novita's avatar
Riri Novita committed
2708
                                    item.profit_loss.ytd_mb,
2709
                                    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
2710
                                    item.profit_loss.ytd_last_year,
2711 2712 2713 2714 2715 2716 2717 2718 2719 2720
                                    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),
                                    month == "Mar" ? item.profit_loss.q1_actual :
                                        month == "Jun" ? item.profit_loss.q2_actual :
                                            month == "Sep" ? item.profit_loss.q3_actual :
                                                month == "Dec" ? item.profit_loss.q4_actual : 0,
                                    month == "Mar" ? item.profit_loss.q1_mb :
                                        month == "Jun" ? item.profit_loss.q2_mb :
                                            month == "Sep" ? item.profit_loss.q3_mb :
                                                month == "Dec" ? item.profit_loss.q4_mb : 0,
                                    isNaN(persenQuarterMB) || persenQuarterMB == 'Infinity' || persenQuarterMB == '-Infinity' ? (q_mb == '' || q_mb == 0 ? -0 : 0) : (q_mb == '' || q_mb == 0 ? persenQuarterMB * -100 : persenQuarterMB * 100),
faisalhamdi's avatar
faisalhamdi committed
2721
                                    // 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),
2722 2723 2724 2725 2726
                                    month == "Mar" ? item.profit_loss.q1_last_year :
                                        month == "Jun" ? item.profit_loss.q2_last_year :
                                            month == "Sep" ? item.profit_loss.q3_last_year :
                                                month == "Dec" ? item.profit_loss.q4_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),
faisalhamdi's avatar
faisalhamdi committed
2727
                                    // 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
2728
                                    item.profit_loss.fy_actual,
Riri Novita's avatar
Riri Novita committed
2729
                                    item.profit_loss.fy_mb,
2730
                                    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),
Riri Novita's avatar
Riri Novita committed
2731
                                    item.profit_loss.fy_ol,
2732
                                    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
2733
                                    item.profit_loss.fy_last_year,
2734 2735
                                    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
2736
                                    item.profit_loss.forecast_next_year,
Riri Novita's avatar
Riri Novita committed
2737 2738
                                    item.profit_loss.forecast_more_year,
                                    item.profit_loss.notes,
Riri Novita's avatar
Riri Novita committed
2739 2740 2741 2742 2743 2744 2745 2746 2747 2748
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
2749
                        res.map((item, index) => {
faisalhamdi's avatar
faisalhamdi committed
2750
                            let month = this.state.month.month_value;
2751 2752 2753
                            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
2754
                            let persenMtd = 0
2755
                            if (mtd_mb < 0) {
Riri Novita's avatar
Riri Novita committed
2756
                                if (mtd_actual >= mtd_mb) {
2757 2758 2759
                                    persenMtd = (mtd_mb - mtd_actual) / mtd_mb + 1
                                } else {
                                    persenMtd = (mtd_mb - mtd_actual) / mtd_mb
Riri Novita's avatar
Riri Novita committed
2760 2761
                                }
                            }
Riri Novita's avatar
Riri Novita committed
2762 2763
                            else {
                                persenMtd = mtd_actual / mtd_mb
Riri Novita's avatar
Riri Novita committed
2764
                            }
Riri Novita's avatar
Riri Novita committed
2765

Riri Novita's avatar
Riri Novita committed
2766
                            let persenMtdLY = 0
2767
                            if (mtd_last_year < 0) {
Riri Novita's avatar
Riri Novita committed
2768
                                if (mtd_actual >= mtd_last_year) {
2769 2770
                                    persenMtdLY = (mtd_last_year - mtd_actual) / mtd_last_year + 1
                                } else {
Riri Novita's avatar
Riri Novita committed
2771 2772 2773 2774
                                    persenMtdLY = (mtd_last_year - mtd_actual) / mtd_last_year
                                }
                            }
                            else {
2775
                                persenMtdLY = mtd_actual / mtd_last_year
Riri Novita's avatar
Riri Novita committed
2776 2777 2778
                            }


2779 2780 2781
                            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)
Riri Novita's avatar
Riri Novita committed
2782
                            let persenYtdMB = 0
2783
                            if (ytd_mb < 0) {
Riri Novita's avatar
Riri Novita committed
2784
                                if (ytd_actual >= ytd_mb) {
2785 2786 2787
                                    persenYtdMB = (ytd_mb - ytd_actual) / ytd_mb + 1
                                } else {
                                    persenYtdMB = (ytd_mb - ytd_actual) / ytd_mb
Riri Novita's avatar
Riri Novita committed
2788 2789 2790
                                }
                            }
                            else {
2791
                                persenYtdMB = ytd_actual / ytd_mb
Riri Novita's avatar
Riri Novita committed
2792 2793 2794
                            }

                            let persenYtdLY = 0
2795
                            if (ytd_last_year < 0) {
Riri Novita's avatar
Riri Novita committed
2796
                                if (ytd_actual >= ytd_last_year) {
2797 2798 2799
                                    persenYtdLY = (ytd_last_year - ytd_actual) / ytd_last_year + 1
                                } else {
                                    persenYtdLY = (ytd_last_year - ytd_actual) / ytd_last_year
Riri Novita's avatar
Riri Novita committed
2800 2801 2802
                                }
                            }
                            else {
2803
                                persenYtdLY = ytd_actual / ytd_last_year
Riri Novita's avatar
Riri Novita committed
2804
                            }
Riri Novita's avatar
Riri Novita committed
2805

faisalhamdi's avatar
faisalhamdi committed
2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832
                            // 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 
                            // }

2833 2834 2835
                            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
2836
                            let persenQuarterMB = 0
2837
                            if (q_mb < 0) {
faisalhamdi's avatar
faisalhamdi committed
2838
                                if (q_actual >= q_mb) {
2839 2840 2841
                                    persenQuarterMB = (q_mb - q_actual) / q_mb + 1
                                } else {
                                    persenQuarterMB = (q_mb - q_actual) / q_mb
Riri Novita's avatar
Riri Novita committed
2842 2843 2844
                                }
                            }
                            else {
2845
                                persenQuarterMB = q_actual / q_mb
Riri Novita's avatar
Riri Novita committed
2846 2847 2848
                            }

                            let persenQuarterLY = 0
2849
                            if (q_last_year < 0) {
faisalhamdi's avatar
faisalhamdi committed
2850
                                if (q_actual >= q_last_year) {
2851 2852 2853
                                    persenQuarterLY = (q_last_year - q_actual) / q_last_year + 1
                                } else {
                                    persenQuarterLY = (q_last_year - q_actual) / q_last_year
Riri Novita's avatar
Riri Novita committed
2854 2855 2856
                                }
                            }
                            else {
2857
                                persenQuarterLY = q_actual / q_last_year
Riri Novita's avatar
Riri Novita committed
2858 2859
                            }

2860 2861 2862 2863
                            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)
Riri Novita's avatar
Riri Novita committed
2864
                            let persenFyMB = 0
2865
                            if (fy_mb < 0) {
Riri Novita's avatar
Riri Novita committed
2866
                                if (fy_actual >= fy_mb) {
2867 2868 2869
                                    persenFyMB = (fy_mb - fy_actual) / fy_mb + 1
                                } else {
                                    persenFyMB = (fy_mb - fy_actual) / fy_mb
Riri Novita's avatar
Riri Novita committed
2870 2871 2872
                                }
                            }
                            else {
2873
                                persenFyMB = fy_actual / fy_mb
Riri Novita's avatar
Riri Novita committed
2874 2875 2876
                            }

                            let persenFyOL = 0
2877
                            if (fy_ol < 0) {
Riri Novita's avatar
Riri Novita committed
2878
                                if (fy_actual >= fy_ol) {
2879 2880 2881
                                    persenFyOL = (fy_ol - fy_actual) / fy_ol + 1
                                } else {
                                    persenFyOL = (fy_ol - fy_actual) / fy_ol
Riri Novita's avatar
Riri Novita committed
2882 2883 2884
                                }
                            }
                            else {
2885
                                persenFyOL = fy_actual / fy_ol
Riri Novita's avatar
Riri Novita committed
2886 2887 2888
                            }

                            let persenFyLY = 0
2889
                            if (fy_last_year < 0) {
Riri Novita's avatar
Riri Novita committed
2890
                                if (fy_actual >= fy_last_year) {
2891 2892 2893
                                    persenFyLY = (fy_last_year - fy_actual) / fy_last_year + 1
                                } else {
                                    persenFyLY = (fy_last_year - fy_actual) / fy_last_year
Riri Novita's avatar
Riri Novita committed
2894 2895 2896
                                }
                            }
                            else {
2897
                                persenFyLY = fy_actual / fy_last_year
Riri Novita's avatar
Riri Novita committed
2898
                            }
Riri Novita's avatar
Riri Novita committed
2899

Riri Novita's avatar
Riri Novita committed
2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912
                            // 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
2913 2914 2915 2916 2917
                            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
Riri Novita's avatar
Riri Novita committed
2918
                                }
2919 2920 2921 2922
                            }
                            else {
                                persenFyOLMB = fy_ol / fy_mb
                            }
Riri Novita's avatar
Riri Novita committed
2923 2924

                            dbSumaPL.push([
Riri Novita's avatar
Riri Novita committed
2925
                                item.type_report_id,
Riri Novita's avatar
Riri Novita committed
2926
                                item.id,
Riri Novita's avatar
Riri Novita committed
2927 2928 2929 2930
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
Riri Novita's avatar
Riri Novita committed
2931
                                item.profit_loss.mtd_actual,
Riri Novita's avatar
Riri Novita committed
2932
                                item.profit_loss.mtd_mb,
2933
                                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
2934
                                item.profit_loss.mtd_last_year,
2935
                                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
2936
                                item.profit_loss.ytd_actual,
Riri Novita's avatar
Riri Novita committed
2937
                                item.profit_loss.ytd_mb,
2938
                                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
2939
                                item.profit_loss.ytd_last_year,
2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954
                                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),
                                month == "Mar" ? item.profit_loss.q1_actual :
                                    month == "Jun" ? item.profit_loss.q2_actual :
                                        month == "Sep" ? item.profit_loss.q3_actual :
                                            month == "Dec" ? item.profit_loss.q4_actual : 0,
                                month == "Mar" ? item.profit_loss.q1_mb :
                                    month == "Jun" ? item.profit_loss.q2_mb :
                                        month == "Sep" ? item.profit_loss.q3_mb :
                                            month == "Dec" ? item.profit_loss.q4_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 :
                                            month == "Dec" ? item.profit_loss.q4_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
2955
                                item.profit_loss.fy_actual,
Riri Novita's avatar
Riri Novita committed
2956
                                item.profit_loss.fy_mb,
2957
                                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),
Riri Novita's avatar
Riri Novita committed
2958
                                item.profit_loss.fy_ol,
2959
                                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
2960
                                item.profit_loss.fy_last_year,
2961 2962
                                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
2963 2964 2965
                                item.profit_loss.forecast_next_year,
                                item.profit_loss.forecast_more_year,
                                item.profit_loss.notes,
Riri Novita's avatar
Riri Novita committed
2966 2967 2968 2969 2970 2971 2972
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
2973
                            }
Riri Novita's avatar
Riri Novita committed
2974
                        })
Riri Novita's avatar
Riri Novita committed
2975
                        console.log(dbSumaPL);
Riri Novita's avatar
Riri Novita committed
2976
                        this.setState({ dataTable: dbSumaPL, loading: false, previewTable: true, previewDownload: true })
2977
                    } else {
Riri Novita's avatar
Riri Novita committed
2978
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
2979
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
2980 2981 2982 2983 2984 2985
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
2986
                    }
Riri Novita's avatar
Riri Novita committed
2987 2988 2989
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                }
2990

Riri Novita's avatar
Riri Novita committed
2991 2992
            })
        } else if (this.state.report.value === 9) {
rifkaki's avatar
rifkaki committed
2993 2994 2995 2996 2997 2998
            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
2999
                console.log(response);
rifkaki's avatar
rifkaki committed
3000
                if (response) {
3001
                    FRID = response.data.data == null ? null : response.data.data.ratio_id
rifkaki's avatar
rifkaki committed
3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022
                } 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) {
3023 3024 3025
                                                mtdPersenMB = ((mtd_mb - mtd_actual) / mtd_mb + 1)
                                            } else {
                                                mtdPersenMB = ((mtd_mb - mtd_actual) / mtd_mb)
rifkaki's avatar
rifkaki committed
3026 3027 3028
                                            }
                                        }
                                        else {
3029
                                            mtdPersenMB = Number(mtd_actual / mtd_mb)
rifkaki's avatar
rifkaki committed
3030 3031 3032 3033 3034 3035 3036
                                        }

                                        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) {
3037 3038 3039
                                                fyPersenMB = ((fy_mb - fy_actual) / fy_mb + 1)
                                            } else {
                                                fyPersenMB = ((fy_mb - fy_actual) / fy_mb)
rifkaki's avatar
rifkaki committed
3040 3041 3042
                                            }
                                        }
                                        else {
3043
                                            fyPersenMB = Number(fy_actual / fy_mb)
rifkaki's avatar
rifkaki committed
3044 3045 3046 3047 3048 3049 3050
                                        }

                                        // 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) {
3051 3052 3053
                                                fyPersenOL = ((fy_ol - fy_actual) / fy_ol + 1)
                                            } else {
                                                fyPersenOL = ((fy_ol - fy_actual) / fy_ol)
rifkaki's avatar
rifkaki committed
3054 3055 3056
                                            }
                                        }
                                        else {
3057
                                            fyPersenOL = Number(fy_actual / fy_ol)
rifkaki's avatar
rifkaki committed
3058 3059 3060 3061 3062 3063 3064
                                        }

                                        // 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) {
3065 3066 3067
                                                fyPersenLY = ((fy_last_year - fy_actual) / fy_last_year + 1)
                                            } else {
                                                fyPersenLY = ((fy_last_year - fy_actual) / fy_last_year)
rifkaki's avatar
rifkaki committed
3068 3069 3070
                                            }
                                        }
                                        else {
3071
                                            fyPersenLY = Number(fy_actual / fy_last_year)
rifkaki's avatar
rifkaki committed
3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110
                                        }

                                        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) {
3111 3112 3113
                                            mtdPersenMB = ((mtd_mb - mtd_actual) / mtd_mb + 1)
                                        } else {
                                            mtdPersenMB = ((mtd_mb - mtd_actual) / mtd_mb)
rifkaki's avatar
rifkaki committed
3114 3115 3116
                                        }
                                    }
                                    else {
3117
                                        mtdPersenMB = Number(mtd_actual / mtd_mb)
rifkaki's avatar
rifkaki committed
3118 3119 3120 3121 3122 3123 3124
                                    }

                                    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) {
3125 3126 3127
                                            fyPersenMB = ((fy_mb - fy_actual) / fy_mb + 1)
                                        } else {
                                            fyPersenMB = ((fy_mb - fy_actual) / fy_mb)
rifkaki's avatar
rifkaki committed
3128 3129 3130
                                        }
                                    }
                                    else {
3131
                                        fyPersenMB = Number(fy_actual / fy_mb)
rifkaki's avatar
rifkaki committed
3132 3133 3134 3135 3136 3137 3138
                                    }

                                    // 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) {
3139 3140 3141
                                            fyPersenOL = ((fy_ol - fy_actual) / fy_ol + 1)
                                        } else {
                                            fyPersenOL = ((fy_ol - fy_actual) / fy_ol)
rifkaki's avatar
rifkaki committed
3142 3143 3144
                                        }
                                    }
                                    else {
3145
                                        fyPersenOL = Number(fy_actual / fy_ol)
rifkaki's avatar
rifkaki committed
3146 3147 3148 3149 3150 3151 3152
                                    }

                                    // 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) {
3153 3154 3155
                                            fyPersenLY = ((fy_last_year - fy_actual) / fy_last_year + 1)
                                        } else {
                                            fyPersenLY = ((fy_last_year - fy_actual) / fy_last_year)
rifkaki's avatar
rifkaki committed
3156 3157 3158
                                        }
                                    }
                                    else {
3159
                                        fyPersenLY = Number(fy_actual / fy_last_year)
rifkaki's avatar
rifkaki committed
3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199
                                    }

                                    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
3200
                                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
rifkaki's avatar
rifkaki committed
3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213
                                        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
3214
            })
faisalhamdi's avatar
faisalhamdi committed
3215
        } else if (this.state.report.value === 11) {
faisalhamdi's avatar
faisalhamdi committed
3216
            let dbCATPQ = [];
3217
            let payloadCATPQ = { ...payload, report_id: 10, quarter: this.state.quarter.name }
faisalhamdi's avatar
faisalhamdi committed
3218 3219 3220 3221 3222 3223
            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
3224 3225 3226 3227
                        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'
3228 3229
                                let weight = String(item.corporate_annual_target.weight).substr(0, String(item.corporate_annual_target.weight).length - 1)
                                let percentVar = Number(item.corporate_annual_target.thisYearOlFy) / Number(item.corporate_annual_target.thisYearBudgetFy)
faisalhamdi's avatar
faisalhamdi committed
3230
                                percentVar = String(percentVar) == 'NaN' || String(percentVar) == 'Infinity' || String(percentVar) == '-Infinity' ? 0 : percentVar
faisalhamdi's avatar
faisalhamdi committed
3231 3232 3233 3234 3235 3236 3237 3238
                                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
3239
                                    parentTrue ? item.corporate_annual_target.uom : item.uom,
3240
                                    parentTrue ? item.corporate_annual_target.kpiType : item.typeKpi,
faisalhamdi's avatar
faisalhamdi committed
3241
                                    parentTrue ? titleCase(item.corporate_annual_target.maxAch) : titleCase(item.maxAch),
3242
                                    parentTrue ? item.corporate_annual_target.formulaYtd : item.formulaYtd,
faisalhamdi's avatar
faisalhamdi committed
3243 3244 3245

                                    item.corporate_annual_target.lastYearActualQx,
                                    item.corporate_annual_target.lastYearActualFy,
3246

faisalhamdi's avatar
faisalhamdi committed
3247 3248 3249
                                    item.corporate_annual_target.thisYearbudgetQx,
                                    item.corporate_annual_target.thisYearActualQx,
                                    item.corporate_annual_target.thisYearPercentAch,
faisalhamdi's avatar
faisalhamdi committed
3250
                                    item.corporate_annual_target.thisYearPercentGrowthYoy,
faisalhamdi's avatar
faisalhamdi committed
3251
                                    item.corporate_annual_target.thisYearScore === null ? "0" : item.corporate_annual_target.thisYearScore,
faisalhamdi's avatar
faisalhamdi committed
3252 3253 3254 3255 3256 3257 3258 3259
                                    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
3260
                                    item.corporate_annual_target.thisYearPercentAchFy,
faisalhamdi's avatar
faisalhamdi committed
3261
                                    item.corporate_annual_target.thisYearScoreFy === null ? "0" : item.corporate_annual_target.thisYearScoreFy,
faisalhamdi's avatar
faisalhamdi committed
3262 3263
                                    item.corporate_annual_target.thisYearScoreXWeightFy,

faisalhamdi's avatar
faisalhamdi committed
3264
                                    item.orders
faisalhamdi's avatar
faisalhamdi committed
3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284
                                ])
                            }
                            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
3285 3286 3287
                                item.typeKpi,
                                item.maxAch,
                                item.formulaYtd,
faisalhamdi's avatar
faisalhamdi committed
3288 3289 3290

                                item.corporate_annual_target.lastYearActualQx,
                                item.corporate_annual_target.lastYearActualFy,
3291

faisalhamdi's avatar
faisalhamdi committed
3292 3293 3294
                                item.corporate_annual_target.thisYearbudgetQx,
                                item.corporate_annual_target.thisYearActualQx,
                                item.corporate_annual_target.thisYearPercentAch,
faisalhamdi's avatar
faisalhamdi committed
3295
                                item.corporate_annual_target.thisYearPercentGrowthYoy,
faisalhamdi's avatar
faisalhamdi committed
3296 3297 3298 3299 3300 3301 3302 3303 3304
                                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
3305 3306 3307
                                item.corporate_annual_target.thisYearPercentAchFy,
                                item.corporate_annual_target.thisYearScoreFy,
                                item.corporate_annual_target.thisYearScoreXWeightFy,
3308

faisalhamdi's avatar
faisalhamdi committed
3309
                                item.orders
faisalhamdi's avatar
faisalhamdi committed
3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320
                            ])
                            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
3321 3322 3323 3324 3325 3326 3327 3328 3329
                    } 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);
                            }
                        })
3330
                    }
faisalhamdi's avatar
faisalhamdi committed
3331 3332 3333
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                }
3334
            })
faisalhamdi's avatar
faisalhamdi committed
3335
        } else if (this.state.report.value === 10) {
faisalhamdi's avatar
faisalhamdi committed
3336
            let dbCATPA = []
3337
            let payloadCATPA = { ...payload, months: this.state.month.month_id, get_for: "view" }
faisalhamdi's avatar
faisalhamdi committed
3338 3339 3340 3341 3342 3343 3344 3345
            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
3346 3347
                            if (indexIDzz === -1) {
                                let parentTrue = item.parent_name == 'INTERNAL BUSINESS PROCESS PERSPECTIVE' || item.parent_name == 'CUSTOMER PERSPECTIVE'
3348
                                let weight = String(item.corporate_annual_target.weight).substr(0, String(item.corporate_annual_target.weight).length - 1)
faisalhamdi's avatar
faisalhamdi committed
3349

faisalhamdi's avatar
faisalhamdi committed
3350 3351 3352 3353 3354 3355 3356
                                dbCATPA.push([
                                    item.type_report_id,
                                    item.id,
                                    item.parent,
                                    item.formula,
                                    item.level,
                                    item.description,
faisalhamdi's avatar
faisalhamdi committed
3357
                                    item.corporate_annual_target.weight == "" ? Number(0).toFixed(1) : Number(weight).toFixed(1),
faisalhamdi's avatar
faisalhamdi committed
3358 3359 3360
                                    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),
3361
                                    item.corporate_annual_target.formula_ytd == "" ? null : item.corporate_annual_target.formula_ytd,
faisalhamdi's avatar
faisalhamdi committed
3362 3363
                                    item.corporate_annual_target.actual_ytd,
                                    item.corporate_annual_target.target_ytd,
faisalhamdi's avatar
faisalhamdi committed
3364
                                    item.corporate_annual_target.achivement_ytd,
faisalhamdi's avatar
faisalhamdi committed
3365 3366
                                    item.corporate_annual_target.score,
                                    item.corporate_annual_target.score_x_weight,
faisalhamdi's avatar
faisalhamdi committed
3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380
                                    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
3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396
                                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
3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409
                            ])
                            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
3410
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
faisalhamdi's avatar
faisalhamdi committed
3411 3412 3413 3414 3415 3416
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
3417
                    }
faisalhamdi's avatar
faisalhamdi committed
3418 3419 3420 3421
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
                }
            })
d.arizona's avatar
d.arizona committed
3422
        }
Riri Novita's avatar
Riri Novita committed
3423

d.arizona's avatar
d.arizona committed
3424 3425
    }

d.arizona's avatar
d.arizona committed
3426
    getCFSumaMR(payload, dbSumaCF) {
d.arizona's avatar
d.arizona committed
3427
        let payloadLast = { ...payload, "periode": Number(this.state.periode.periode) - 1 }
d.arizona's avatar
d.arizona committed
3428 3429 3430 3431 3432 3433 3434 3435
        // 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
3436 3437 3438 3439 3440 3441 3442
        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
3443
                res.map((item, index) => {
d.arizona's avatar
d.arizona committed
3444 3445 3446 3447 3448 3449 3450
                    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],
qorri_di's avatar
qorri_di committed
3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512
                                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,
                                items.cash_flow.total_current_year,
                                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.q1_total_current_year,
                                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.q2_total_current_year,
                                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,
                                items.cash_flow.q3_total_current_year,
                                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
3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524
                                ])
                            }
                            if (items.children !== null) {
                                if (items.children.length > 0) {
                                    items.children.map((itemss, indexss) => {
                                        handlePushChild(itemss)
                                    })
                                }
                            }
                        }

                        dataTable2.push([...dataTable[indexID],
qorri_di's avatar
qorri_di committed
3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586
                        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.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.q1_total_current_year,
                        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.q2_total_current_year,
                        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,
                        item.cash_flow.q3_total_current_year,
                        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
3587 3588 3589 3590 3591 3592 3593 3594 3595
                        ])

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

d.arizona's avatar
d.arizona committed
3597
                    }
d.arizona's avatar
d.arizona committed
3598

d.arizona's avatar
d.arizona committed
3599 3600 3601
                })
                this.setState({ dataTable2 }, () => {
                    // console.log(this.state.dataTable2)
d.arizona's avatar
d.arizona committed
3602
                    this.getCFSumaLastMR(payloadLast, dbSumaCF)
d.arizona's avatar
d.arizona committed
3603 3604 3605 3606 3607 3608 3609 3610 3611
                })
                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
3612
    getCFSumaLastMR(payload, dbSumaCF) {
rifkaki's avatar
rifkaki committed
3613 3614
        console.log(dbSumaCF)
        console.log(this.state.dbSumaCF)
d.arizona's avatar
d.arizona committed
3615 3616 3617 3618 3619 3620 3621
        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
3622
                res.map((item, index) => {
d.arizona's avatar
d.arizona committed
3623
                    let indexID = dataTable2.findIndex((val) => val[1] == item.id)
d.arizona's avatar
d.arizona committed
3624
                    let indexIDSuma = dbSumaCF.findIndex((val) => val[0] == item.id)
d.arizona's avatar
d.arizona committed
3625 3626 3627
                    if (indexID != -1) {
                        const handlePushChild = (items) => {
                            let indexIDzz = dataTable2.findIndex((val) => val[1] === items.id)
rifkaki's avatar
rifkaki committed
3628
                            let indexIDSumaChild = dbSumaCF.findIndex((val) => val[0] == items.id)
d.arizona's avatar
d.arizona committed
3629 3630
                            if (indexIDzz != -1) {
                                dataTable3.push([...dataTable2[indexIDzz],
qorri_di's avatar
qorri_di committed
3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643
                                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,
                                items.cash_flow.total_current_year
d.arizona's avatar
d.arizona committed
3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655
                                ])
                            }
                            if (items.children !== null) {
                                if (items.children.length > 0) {
                                    items.children.map((itemss, indexss) => {
                                        handlePushChild(itemss)
                                    })
                                }
                            }
                        }

                        dataTable3.push([...dataTable2[indexID],
qorri_di's avatar
qorri_di committed
3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668
                        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
d.arizona's avatar
d.arizona committed
3669 3670 3671 3672 3673 3674 3675 3676 3677
                        ])

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

d.arizona's avatar
d.arizona committed
3679
                    }
d.arizona's avatar
d.arizona committed
3680

d.arizona's avatar
d.arizona committed
3681
                })
3682 3683 3684

                console.log(dataTable3);

d.arizona's avatar
d.arizona committed
3685 3686 3687 3688 3689 3690 3691
                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
3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706
    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
3707
                res.map((item, index) => {
Riri Novita's avatar
Riri Novita committed
3708 3709 3710 3711 3712 3713 3714
                    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],
qorri_di's avatar
qorri_di committed
3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727
                                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
3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739
                                ])
                            }
                            if (items.children !== null) {
                                if (items.children.length > 0) {
                                    items.children.map((itemss, indexss) => {
                                        handlePushChild(itemss)
                                    })
                                }
                            }
                        }

                        dataTable2.push([...dataTable[indexID],
qorri_di's avatar
qorri_di committed
3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752
                        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
3753 3754 3755 3756 3757 3758 3759 3760 3761
                        ])

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

Riri Novita's avatar
Riri Novita committed
3763
                    }
d.arizona's avatar
d.arizona committed
3764

Riri Novita's avatar
Riri Novita committed
3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785
                })
                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
3786
                res.map((item, index) => {
Riri Novita's avatar
Riri Novita committed
3787 3788 3789 3790 3791 3792 3793
                    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],
qorri_di's avatar
qorri_di committed
3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805
                                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
3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817
                                ])
                            }
                            if (items.children !== null) {
                                if (items.children.length > 0) {
                                    items.children.map((itemss, indexss) => {
                                        handlePushChild(itemss)
                                    })
                                }
                            }
                        }

                        dataTable3.push([...dataTable2[indexID],
qorri_di's avatar
qorri_di committed
3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829
                        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
3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841
                        ])

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

                    }

d.arizona's avatar
d.arizona committed
3842 3843 3844 3845 3846 3847 3848 3849 3850
                })
                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
3851
    getRatioMR(payload) {
rifkaki's avatar
rifkaki committed
3852 3853 3854 3855 3856 3857 3858
        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
3859 3860 3861 3862 3863 3864 3865 3866
        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
3867
                    res.map((item, index) => {
d.arizona's avatar
d.arizona committed
3868 3869 3870 3871 3872 3873 3874
                        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],
qorri_di's avatar
qorri_di committed
3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898
                                    // 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
3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910
                                    ])
                                }
                                if (items.children !== null) {
                                    if (items.children.length > 0) {
                                        items.children.map((itemss, indexss) => {
                                            handlePushChild(itemss)
                                        })
                                    }
                                }
                            }

                            dataTable2.push([...dataTable[indexID],
qorri_di's avatar
qorri_di committed
3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934
                            // 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
3935 3936 3937 3938 3939 3940 3941 3942 3943
                            ])

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

d.arizona's avatar
d.arizona committed
3945
                        }
d.arizona's avatar
d.arizona committed
3946

d.arizona's avatar
d.arizona committed
3947 3948
                    })
                    console.log(dataTable2)
rifkaki's avatar
rifkaki committed
3949 3950 3951 3952 3953
                    // 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
3954
                } else {
rifkaki's avatar
rifkaki committed
3955
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
3956
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
rifkaki's avatar
rifkaki committed
3957 3958 3959 3960 3961 3962
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
d.arizona's avatar
d.arizona committed
3963
                }
rifkaki's avatar
rifkaki committed
3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978
            } 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
3979
                    res.map((item, index) => {
rifkaki's avatar
rifkaki committed
3980 3981 3982 3983 3984 3985 3986
                        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],
qorri_di's avatar
qorri_di committed
3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010
                                    // 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
4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022
                                    ])
                                }
                                if (items.children !== null) {
                                    if (items.children.length > 0) {
                                        items.children.map((itemss, indexss) => {
                                            handlePushChild(itemss)
                                        })
                                    }
                                }
                            }

                            dataTable3.push([...dataTable2[indexID],
qorri_di's avatar
qorri_di committed
4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046
                            // 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
4047 4048 4049 4050 4051 4052 4053 4054 4055
                            ])

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

rifkaki's avatar
rifkaki committed
4057
                        }
d.arizona's avatar
d.arizona committed
4058

rifkaki's avatar
rifkaki committed
4059 4060 4061
                    })
                    console.log(dataTable3)
                    this.setState({ dataTable: dataTable3, previewTable: true, loading: false, previewDownload: true })
d.arizona's avatar
d.arizona committed
4062
                } else {
d.arizona's avatar
d.arizona committed
4063
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
4064
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
4065 4066 4067 4068 4069 4070
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
d.arizona's avatar
d.arizona committed
4071
                }
d.arizona's avatar
d.arizona committed
4072 4073 4074 4075 4076 4077
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
4078
    async downloadAllData() {
4079
        let { company, periode, month, quarter } = this.state
faisalhamdi's avatar
faisalhamdi committed
4080
        if (this.state.report.value === 1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
4081
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
4082
                `${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}&&currency_id=${this.state.defaultCurrency.id}`
Deni Rinaldi's avatar
Deni Rinaldi committed
4083 4084 4085 4086 4087 4088 4089
            )
            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;
4090
                a.download = `Report DB Profit & Loss Detail ${company.company_name} ${periode.periode}.xlsx`;
Deni Rinaldi's avatar
Deni Rinaldi committed
4091 4092
                a.click();
            }
faisalhamdi's avatar
faisalhamdi committed
4093
        } else if (this.state.report.value === 2) {
Deni Rinaldi's avatar
Deni Rinaldi committed
4094
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
4095
                `${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}&&currency_id=${this.state.defaultCurrency.id}`
Deni Rinaldi's avatar
Deni Rinaldi committed
4096
            )
Riri Novita's avatar
Riri Novita committed
4097
            console.log(res);
Deni Rinaldi's avatar
Deni Rinaldi committed
4098
            res = await res.blob()
Riri Novita's avatar
Riri Novita committed
4099
            console.log(res);
Deni Rinaldi's avatar
Deni Rinaldi committed
4100 4101 4102 4103 4104
            this.setState({ loading: false })
            if (res.size > 0) {
                let url = window.URL.createObjectURL(res);
                let a = document.createElement('a');
                a.href = url;
4105
                a.download = `Report DB Balance Sheet ${company.company_name} ${periode.periode}.xlsx`;
Deni Rinaldi's avatar
Deni Rinaldi committed
4106 4107 4108 4109
                a.click();
            }
        } else if (this.state.report.value === 3) {
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
4110
                `${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}&&currency_id=${this.state.defaultCurrency.id}`
Deni Rinaldi's avatar
Deni Rinaldi committed
4111 4112 4113 4114 4115 4116 4117
            )
            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;
4118
                a.download = `Report DB Profit & Loss ${company.company_name} ${periode.periode}.xlsx`;
Deni Rinaldi's avatar
Deni Rinaldi committed
4119 4120
                a.click();
            }
faisalhamdi's avatar
faisalhamdi committed
4121
        } else if (this.state.report.value === 4) {
Riri Novita's avatar
Riri Novita committed
4122
            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}&&currency_id=${this.state.defaultCurrency.id}`
Deni Rinaldi's avatar
Deni Rinaldi committed
4123
            console.log(url);
faisalhamdi's avatar
faisalhamdi committed
4124
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
4125
                `${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}&&currency_id=${this.state.defaultCurrency.id}`
faisalhamdi's avatar
faisalhamdi committed
4126 4127 4128 4129 4130 4131 4132
            )
            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;
4133
                a.download = `Report DB Financial Ratio ${company.company_name} ${periode.periode}.xlsx`;
faisalhamdi's avatar
faisalhamdi committed
4134 4135
                a.click();
            }
rifkaki's avatar
rifkaki committed
4136 4137
        } else if (this.state.report.value === 5) {
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
4138
                `${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}&&currency_id=${this.state.defaultCurrency.id}`
rifkaki's avatar
rifkaki committed
4139 4140 4141 4142 4143 4144 4145
            )
            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;
4146
                a.download = `Report DB Tax Planning ${company.company_name} ${periode.periode}.xlsx`;
rifkaki's avatar
rifkaki committed
4147 4148
                a.click();
            }
d.arizona's avatar
d.arizona committed
4149
        } else if (this.state.report.value === 21) {
Riri Novita's avatar
Riri Novita committed
4150
            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}&&currency_id=${this.state.defaultCurrency.id}`
d.arizona's avatar
d.arizona committed
4151 4152
            console.log(url);
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
4153
                `${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}&&currency_id=${this.state.defaultCurrency.id}`
d.arizona's avatar
d.arizona committed
4154 4155 4156 4157 4158 4159 4160
            )
            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;
4161
                a.download = `Report DB Operating Indicator ${company.company_name} ${periode.periode}.xlsx`;
d.arizona's avatar
d.arizona committed
4162 4163 4164
                a.click();
            }
        } else if (this.state.report.value === 6) {
Riri Novita's avatar
Riri Novita committed
4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182
            try {
                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&&currency_id=${this.state.defaultCurrency.id}`
                console.log(url);
                let res = await fetch(
                    `${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&&currency_id=${this.state.defaultCurrency.id}`
                )
                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 ${company.company_name} ${month.month_value} ${periode.periode}.xlsx`;
                    a.click();
                }
            } catch (error) {
                alert(error)
                this.setState({ loading: false })
d.arizona's avatar
d.arizona committed
4183
            }
Riri Novita's avatar
Riri Novita committed
4184

d.arizona's avatar
d.arizona committed
4185 4186
        } else if (this.state.report.value === 7) {
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
4187
                `${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&&currency_id=${this.state.defaultCurrency.id}`
d.arizona's avatar
d.arizona committed
4188 4189 4190 4191 4192 4193 4194
            )
            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;
4195
                a.download = `Report Balance Sheet - Summary ${company.company_name} ${month.month_value} ${periode.periode}.xlsx`;
d.arizona's avatar
d.arizona committed
4196 4197 4198
                a.click();
            }
        } else if (this.state.report.value === 8) {
Riri Novita's avatar
Riri Novita committed
4199
            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&&currency_id=${this.state.defaultCurrency.id}`
Riri Novita's avatar
Riri Novita committed
4200
            console.log(url);
d.arizona's avatar
d.arizona committed
4201
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
4202
                `${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&&currency_id=${this.state.defaultCurrency.id}`
d.arizona's avatar
d.arizona committed
4203 4204 4205 4206 4207 4208 4209
            )
            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;
4210
                a.download = `Report Profit & Loss - Summary ${company.company_name} ${month.month_value} ${periode.periode}.xlsx`;
d.arizona's avatar
d.arizona committed
4211 4212
                a.click();
            }
rifkaki's avatar
rifkaki committed
4213 4214
        } else if (this.state.report.value === 9) {
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
4215
                `${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&&currency_id=${this.state.defaultCurrency.id}`
rifkaki's avatar
rifkaki committed
4216 4217 4218 4219 4220 4221 4222
            )
            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;
4223
                a.download = `Report Financial Ratio - Summary ${company.company_name} ${month.month_value} ${periode.periode}.xlsx`;
rifkaki's avatar
rifkaki committed
4224 4225
                a.click();
            }
faisalhamdi's avatar
faisalhamdi committed
4226
        } else if (this.state.report.value === 11) {
faisalhamdi's avatar
faisalhamdi committed
4227
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
4228
                `${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}&&currency_id=${this.state.defaultCurrency.id}`
faisalhamdi's avatar
faisalhamdi committed
4229
            )
faisalhamdi's avatar
faisalhamdi committed
4230
            console.log(res);
faisalhamdi's avatar
faisalhamdi committed
4231 4232 4233 4234 4235 4236
            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;
4237
                a.download = `Report CAT Performance Quarterly ${company.company_name} ${quarter.name} ${periode.periode}.xlsx`;
faisalhamdi's avatar
faisalhamdi committed
4238 4239
                a.click();
            }
faisalhamdi's avatar
faisalhamdi committed
4240
        } else if (this.state.report.value === 10) {
faisalhamdi's avatar
faisalhamdi committed
4241
            let res = await fetch(
Riri Novita's avatar
Riri Novita committed
4242
                `${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}&&currency_id=${this.state.defaultCurrency.id}`
faisalhamdi's avatar
faisalhamdi committed
4243 4244 4245 4246 4247 4248 4249
            )
            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;
4250
                a.download = `Report CAT Performance Appraisal ${company.company_name} ${periode.periode}.xlsx`;
faisalhamdi's avatar
faisalhamdi committed
4251 4252
                a.click();
            }
4253
        } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
4254 4255 4256
            setTimeout(() => {
                this.setState({ loading: false })
            }, 1000);
Deni Rinaldi's avatar
Deni Rinaldi committed
4257 4258 4259
        }
    }

faisalhamdi's avatar
faisalhamdi committed
4260 4261 4262 4263
    closeAlert() {
        this.setState({ alert: false })
    }

faisalhamdi's avatar
faisalhamdi committed
4264
    render() {
Riri Novita's avatar
Riri Novita committed
4265
        let { defaultCurrencyID, report } = this.state
Deni Rinaldi's avatar
Deni Rinaldi committed
4266
        const loadingComponent = (
Deni Rinaldi's avatar
Deni Rinaldi committed
4267
            <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
4268 4269 4270 4271 4272 4273 4274 4275
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
            </div>
        );
faisalhamdi's avatar
faisalhamdi committed
4276 4277 4278 4279 4280 4281
        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
4282 4283 4284 4285 4286
                    <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
4287 4288 4289 4290 4291
                    <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
4292
                            <div style={{ minWidth: 'max-content', padding: '20px 20px 0px 20px' }}>
d.arizona's avatar
d.arizona committed
4293
                                <div style={{ marginTop: 15, display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
4294 4295
                                    <Autocomplete
                                        options={this.state.reportType}
Deni Rinaldi's avatar
Deni Rinaldi committed
4296
                                        getOptionLabel={(option) => titleCase(option.label)}
Deni Rinaldi's avatar
Deni Rinaldi committed
4297
                                        id="typereport"
idlanirined's avatar
idlanirined committed
4298
                                        onChange={(event, newInputValue) => this.setState({ report: newInputValue, loading: true, previewTable: false }, () => {
d.arizona's avatar
d.arizona committed
4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309
                                            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')) {
qorri_di's avatar
qorri_di committed
4310
                                                let index = data.sort((a, b) => a - b).findIndex((val) => val.periode == yearNow - 1)
d.arizona's avatar
d.arizona committed
4311
                                                // console.log(index)
4312
                                                this.setState({ periode: data[index] }, () => {
d.arizona's avatar
d.arizona committed
4313 4314 4315 4316 4317
                                                    this.getReportType()
                                                })
                                            } else {
                                                this.getReportType()
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
4318
                                        })}
Deni Rinaldi's avatar
Deni Rinaldi committed
4319
                                        disableClearable
faisalhamdi's avatar
faisalhamdi committed
4320
                                        style={{ width: 250 }}
Deni Rinaldi's avatar
Deni Rinaldi committed
4321 4322 4323
                                        renderInput={(params) => <TextField {...params} label="Report Type" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.report}
                                    />
d.arizona's avatar
d.arizona committed
4324 4325 4326 4327 4328 4329 4330 4331
                                    <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
4332
                                        style={{ width: 250, marginLeft: 20 }}
d.arizona's avatar
d.arizona committed
4333 4334 4335 4336 4337
                                        renderInput={(params) =>
                                            <TextField {...params} label="Period" margin="normal" style={{ marginTop: 7 }}
                                            />}
                                        value={this.state.periode}
                                    />
faisalhamdi's avatar
faisalhamdi committed
4338
                                </div>
d.arizona's avatar
d.arizona committed
4339
                                <div style={{ marginTop: 15, display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
4340 4341 4342 4343
                                    <Autocomplete
                                        {...this.state.listCompany}
                                        id="company"
                                        disabled={this.state.intent === 'Home' ? true : false}
idlanirined's avatar
idlanirined committed
4344
                                        onChange={(event, newInputValue) => this.setState({ company: newInputValue, loading: true, previewTable: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
4345
                                            this.getReportType()
Riri Novita's avatar
Riri Novita committed
4346
                                            this.getCurrency(newInputValue.company_id)
Deni Rinaldi's avatar
Deni Rinaldi committed
4347
                                        })}
Deni Rinaldi's avatar
Deni Rinaldi committed
4348 4349 4350 4351 4352
                                        disableClearable
                                        style={{ width: 250 }}
                                        renderInput={(params) => <TextField {...params} label="Company" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.company}
                                    />
4353
                                    {this.state.report != null ? String(this.state.report.label).toLocaleLowerCase().includes('summary') ?
d.arizona's avatar
d.arizona committed
4354 4355 4356 4357 4358 4359 4360 4361
                                        <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
4362
                                            style={{ width: 250, marginLeft: 20 }}
d.arizona's avatar
d.arizona committed
4363 4364 4365
                                            renderInput={(params) => <TextField {...params} label="Months" margin="normal" style={{ marginTop: 7 }} />}
                                            value={this.state.month}
                                        /> : null : null}
Riri Novita's avatar
Riri Novita committed
4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394

                                    <Autocomplete
                                        id="tipe"
                                        disabled={this.state.intent === 'Home' ? true : false}
                                        options={this.state.currency}
                                        getOptionLabel={(option) => option.value}
                                        onChange={(event, newInputValue) => this.setState({ defaultCurrency: newInputValue, loading: true, previewTable: false }, () => {
                                            // console.log(defaultCurrencyID);
                                            // console.log(newInputValue.id);
                                            // if (defaultCurrencyID == 2 && newInputValue.id == 1) {
                                            //     this.setState({ report: this.state.reportType2[0], reportType: this.state.reportType2 })
                                            //     console.log("report 1");
                                            // } else if (defaultCurrencyID == 2 && newInputValue.id == 2) {
                                            //     console.log(this.state.reportType)
                                            //     this.setState({ report: defaultReport[0], reportType: defaultReport }, () => {
                                            //         console.log(this.state.reportType)
                                            //     })
                                            //     console.log("report 2");
                                            // }
                                            let bizpar = defaultCurrencyID == 2 && newInputValue.id == 1 ? defaultReport.filter(e => e.report === 2) : defaultReport
                                            this.setState({ report: bizpar[0], reportType: bizpar })
                                            this.getReportType()

                                        })}
                                        disableClearable
                                        style={{ width: 250, marginLeft: 20 }}
                                        renderInput={(params) => <TextField {...params} label="Currency" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.defaultCurrency}
                                    />
d.arizona's avatar
d.arizona committed
4395
                                    {/* {this.state.report != null ? String(this.state.report.label).toLocaleLowerCase().includes('summary') ? <Autocomplete
d.arizona's avatar
d.arizona committed
4396
                                        {...this.state.listUom}
d.arizona's avatar
d.arizona committed
4397
                                        // getOptionLabel={(option) => titleCase(option.label)}
d.arizona's avatar
d.arizona committed
4398 4399
                                        id="uom"
                                        onChange={(event, newInputValue) => this.setState({ uom: newInputValue, loading: true, previewTable: false }, () => {
d.arizona's avatar
d.arizona committed
4400 4401 4402 4403
                                            this.getReportType()
                                        })}
                                        disableClearable
                                        style={{ width: 250, marginLeft: 10 }}
d.arizona's avatar
d.arizona committed
4404 4405
                                        renderInput={(params) => <TextField {...params} label="Uom" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.uom}
d.arizona's avatar
d.arizona committed
4406
                                    /> : null : null} */}
faisalhamdi's avatar
faisalhamdi committed
4407
                                </div>
d.arizona's avatar
d.arizona committed
4408
                                {/* <div style={{ marginTop: 15, display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
4409 4410
                                    <Autocomplete
                                        {...this.state.listPeriode}
faisalhamdi's avatar
faisalhamdi committed
4411
                                        id="periode"
idlanirined's avatar
idlanirined committed
4412
                                        onChange={(event, newInputValue) => this.setState({ periode: newInputValue, loading: true, previewTable: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
4413
                                            this.getReportType()
Deni Rinaldi's avatar
Deni Rinaldi committed
4414 4415 4416 4417 4418 4419 4420
                                        })}
                                        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
4421
                                        value={this.state.periode}
Deni Rinaldi's avatar
Deni Rinaldi committed
4422
                                    />
d.arizona's avatar
d.arizona committed
4423
                                </div> */}
rifkaki's avatar
rifkaki committed
4424 4425
                                {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
4426 4427 4428 4429 4430 4431 4432
                                        {...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
4433
                                        style={{ width: 250 }}
d.arizona's avatar
d.arizona committed
4434 4435
                                        renderInput={(params) => <TextField {...params} label="Quarter" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.quarter}
4436
                                    />
rifkaki's avatar
rifkaki committed
4437
                                </div> : null : null}
d.arizona's avatar
d.arizona committed
4438
                                {/* {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
4439 4440 4441 4442 4443 4444 4445 4446
                                    <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
4447
                                        style={{ width: 250 }}
d.arizona's avatar
d.arizona committed
4448 4449 4450
                                        renderInput={(params) => <TextField {...params} label="Months" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.month}
                                    />
d.arizona's avatar
d.arizona committed
4451
                                </div> : null : null} */}
Deni Rinaldi's avatar
Deni Rinaldi committed
4452
                            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
4453
                            <div>
Deni Rinaldi's avatar
Deni Rinaldi committed
4454
                                <div style={{ display: 'flex', justifyContent: 'space-between', padding: '0px 20px 10px 20px' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479
                                    <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
4480
                                {this.state.loading && loadingComponent}
Deni Rinaldi's avatar
Deni Rinaldi committed
4481
                                {this.state.previewTable && (
Deni Rinaldi's avatar
Deni Rinaldi committed
4482 4483 4484 4485
                                    <TableSubHolding
                                        width={this.props.width}
                                        height={this.props.height}
                                        open={this.props.open}
Riri Novita's avatar
Riri Novita committed
4486
                                        month={this.state.month.month_value}
Riri Novita's avatar
Riri Novita committed
4487 4488
                                        approvedMB={this.state.approveMB}
                                        approveMonthly={this.state.approveMonthly}
Deni Rinaldi's avatar
Deni Rinaldi committed
4489
                                        type={this.state.report ? this.state.report.value : 1}
Deni Rinaldi's avatar
Deni Rinaldi committed
4490 4491
                                        dataTable={this.state.dataTable}
                                        periode={this.state.periode ? this.state.periode.periode : null}
faisalhamdi's avatar
faisalhamdi committed
4492
                                        quarter={this.state.quarter.name}
faisalhamdi's avatar
faisalhamdi committed
4493
                                        company={this.state.company}
Deni Rinaldi's avatar
Deni Rinaldi committed
4494 4495
                                    />
                                )}
faisalhamdi's avatar
faisalhamdi committed
4496 4497 4498 4499 4500 4501 4502 4503
                            </div>
                        </Paper>
                    </div>
                </div>
            </div>
        )
    }
}