SummaryOfTriputra.js 59.4 KB
Newer Older
Riri Novita's avatar
Riri Novita committed
1
import React, { Component } from 'react'
syadziy's avatar
syadziy committed
2
import { Typography, TextField, Paper } from '@material-ui/core'
Riri Novita's avatar
Riri Novita committed
3 4 5 6
import Constant from '../../library/Constant'
import api from '../../api'
import { titleCase } from '../../library/Utils'
import { Autocomplete } from '@material-ui/lab'
Riri Novita's avatar
Riri Novita committed
7
import TableSummaryTriputra from './TableSummaryTriputra'
Riri Novita's avatar
Riri Novita committed
8 9 10
import { PropagateLoader } from 'react-spinners'
import ReactTooltip from 'react-tooltip'
import Images from '../../assets/Images'
rifkaki's avatar
rifkaki committed
11
import { format } from 'date-fns';
Riri Novita's avatar
Riri Novita committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25

export default class SummaryOfTriputra extends Component {
    constructor(props) {
        super(props)
        this.state = {
            periode: '2020',
            perusahaan: 'TAP Group',
            laporan: 'Balance Sheet - Montly',
            tab: 0,
            listCompany: null,
            company: null,
            listPeriode: null,
            periode: null,
            reportType: [
Riri Novita's avatar
Riri Novita committed
26 27 28 29
                { value: 1, label: 'MTD Report', key: "MTD" },
                { value: 2, label: 'YTD Report', key: "YTD" },
                { value: 3, label: 'CPSM Report', key: "CPSM" },
                { value: 4, label: 'Historical', key: "historical" },
Riri Novita's avatar
Riri Novita committed
30 31 32
            ],
            report: null,
            loading: false,
rifkaki's avatar
rifkaki committed
33 34
            previewTable: false,
            listMonths: null,
Riri Novita's avatar
Riri Novita committed
35
            month: null
Riri Novita's avatar
Riri Novita committed
36 37 38 39 40 41 42 43
        }
    }

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

    componentDidMount() {
rifkaki's avatar
rifkaki committed
44
        // this.getDetailUser()
rifkaki's avatar
rifkaki committed
45
        this.setState({ report: this.state.reportType[0], loading: false }, () => {
Riri Novita's avatar
Riri Novita committed
46 47
            console.log(this.state.report);
            this.getPeriode()
Riri Novita's avatar
Riri Novita committed
48
        })
qorri_di's avatar
qorri_di committed
49
        
Riri Novita's avatar
Riri Novita committed
50
        // this.getMonth()
Riri Novita's avatar
Riri Novita committed
51 52 53 54 55
    }

    getPeriode() {
        api.create().getPeriodeTransaction().then(response => {
            let currentYear = new Date().getFullYear()
rifkaki's avatar
rifkaki committed
56 57
            console.log(currentYear)
            console.log(response)
Riri Novita's avatar
Riri Novita committed
58 59 60 61
            if (response.data) {
                if (response.data.status === "success") {
                    let data = []
                    response.data.data.map((item) => {
rifkaki's avatar
rifkaki committed
62
                        // if (this.state.isApprover) {
qorri_di's avatar
qorri_di committed
63 64 65
                            if (item >= 2000 && item <= (Number(currentYear) + 1)) {
                                data.push(item)
                            }
rifkaki's avatar
rifkaki committed
66 67 68 69 70
                        // } else {
                        //     if ((item >= 2000) && (item == this.state.lastPeriod || item < this.state.lastPeriod)) {
                        //         data.push(item)
                        //     }
                        // }
Riri Novita's avatar
Riri Novita committed
71 72 73 74 75 76 77 78 79 80
                    })
                    let periodeData = data.map((item) => {
                        return {
                            periode: item,
                        }
                    })
                    let defaultProps = {
                        options: periodeData,
                        getOptionLabel: (option) => option.periode,
                    };
rifkaki's avatar
rifkaki committed
81 82
                    // let periode = (this.state.lastPeriod == "" ? String(Number(currentYear) + 1) : this.state.lastPeriod)
                    let periode = String(Number(currentYear))
Riri Novita's avatar
Riri Novita committed
83 84 85 86
                    let index = data.sort((a, b) => a - b).findIndex((val) => val === periode)
                    // console.log(data)
                    // console.log(this.state.latestPeriode)
                    // console.log(periodeData)
rifkaki's avatar
rifkaki committed
87 88
                    console.log(index)
                    this.setState({ listPeriode: defaultProps, periode: index === -1 ? periodeData[0] : periodeData[index], loading: false }, () => {
Riri Novita's avatar
Riri Novita committed
89
                        // this.getDataTable()
rifkaki's avatar
rifkaki committed
90 91
                        this.getMonth()
                        // this.getSubmission()
Riri Novita's avatar
Riri Novita committed
92 93 94 95 96 97
                        // if (this.state.isApprover === true) {
                        //     this.getCompanySubmitted()
                        // } else {
                        //     this.getRevision()
                        // }
                    })
Riri Novita's avatar
Riri Novita committed
98 99 100 101 102 103 104 105 106
                } 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);
                        }
                    })
Riri Novita's avatar
Riri Novita committed
107
                }
Riri Novita's avatar
Riri Novita committed
108 109
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
Riri Novita's avatar
Riri Novita committed
110 111 112 113
            }
        })
    }

rifkaki's avatar
rifkaki committed
114 115 116 117 118 119 120 121 122 123 124
    getMonth() {
        api.create().getMonthTransaction().then(response => {
            let dateNow = new Date
            let month = format(dateNow, 'MMMM')
            console.log(month)
            console.log(response)
            if (response.data) {
                if (response.data.status === "success") {
                    let data = response.data.data
                    let monthData = data.map((item) => {
                        return {
Riri Novita's avatar
Riri Novita committed
125
                            month_id: item.id,
rifkaki's avatar
rifkaki committed
126 127 128 129 130 131 132 133 134 135 136 137 138
                            month_name: item.month_name
                        }
                    })
                    let defaultProps = {
                        options: monthData,
                        getOptionLabel: (option) => option.month_name,
                    };
                    // let index = data.sort((a, b) => a - b).findIndex((val) => val == bulan)
                    // this.setState({ listMonth: defaultProps, month: index == -1 ? monthData[0] : monthData[index] })

                    let index = data.findIndex((val) => val.month_name == month)
                    console.log(index)
                    console.log(monthData)
Riri Novita's avatar
Riri Novita committed
139
                    this.setState({ listMonths: defaultProps, month: index == -1 ? monthData[0] : monthData[index] }, () => {
rifkaki's avatar
rifkaki committed
140 141 142
                        this.getDataTable()
                    })
                    console.log(this.state.month)
Riri Novita's avatar
Riri Novita committed
143 144 145 146 147 148 149 150 151
                } 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);
                        }
                    })
rifkaki's avatar
rifkaki committed
152
                }
Riri Novita's avatar
Riri Novita committed
153 154
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
rifkaki's avatar
rifkaki committed
155 156 157 158
            }
        })
    }

Riri Novita's avatar
Riri Novita committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    // getReportType() {
    //     let payload = {
    //         "company_id": this.state.company.company_id,
    //         "periode": this.state.periode.periode,
    //         "report_type": "Master Budget",
    //     }
    //     api.create().getReportTypeBody(payload).then(response => {
    //         console.log(response);
    //         if (response.data) {
    //             if (response.data.status === "success") {
    //                 if (this.state.report.value === 1) {
    //                     response.data.data.map((item, index) => {
    //                         if (item.report_name === 'MTD Report') {
    //                             this.setState({ revisionType: item.revision }, ()=> {
    //                                 this.getSubmission()
    //                             })
    //                         }
    //                     })
    //                 } else if (this.state.report.value === 1) {
    //                     response.data.data.map((item, index) => {
    //                         if (item.report_name === 'YTD Report') {
    //                             this.setState({ revisionType: item.revision }, ()=> {
    //                                 this.getSubmission()
    //                             })
    //                         }
    //                     })
    //                 } else {
    //                     this.setState({ revisionType: 0 }, ()=> {
    //                         this.getSubmission()
    //                     })
    //                 }
    //             }
    //         }
    //     })
    // }
Riri Novita's avatar
Riri Novita committed
194

Riri Novita's avatar
Riri Novita committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
    // getSubmission() {
    //     this.setState({ loading: true })
    //     let payload = {
    //         "company_id": this.state.company.company_id,
    //         "periode": this.state.periode.periode,
    //         "is_approver": true
    //     }
    //     api.create().getSubmission(payload).then(response => {
    //         // console.log(response)
    //         if (response.data) {
    //             if (response.data.status === "success") {
    //                 this.setState({
    //                     submissionID: response.data.data.submission_id,
    //                     lastRevision: response.data.data.last_revision,
    //                 }, () => {
    //                     this.getDataTable()
    //                 })
    //             } else {
    //                 this.setState({ submissionID: null, loading: false })
    //             }
    //         }
    //     })
    // }
Riri Novita's avatar
Riri Novita committed
218 219

    getDataTable() {
rifkaki's avatar
rifkaki committed
220
        this.setState({ loading: true })
rifkaki's avatar
rifkaki committed
221
        let payload = {
Riri Novita's avatar
Riri Novita committed
222
            "report_type": this.state.report.key,
Riri Novita's avatar
Riri Novita committed
223 224
            "periode": this.state.periode.periode,
            "months" : this.state.month.month_id
rifkaki's avatar
rifkaki committed
225
        }
rifkaki's avatar
rifkaki committed
226
        let newPayload = {
Riri Novita's avatar
Riri Novita committed
227
            "periode": this.state.periode.periode,
rifkaki's avatar
rifkaki committed
228
            "report_type":"historical"
Riri Novita's avatar
Riri Novita committed
229 230
        }
        if (this.state.report.value === 1) {
Riri Novita's avatar
Riri Novita committed
231
            api.create().getHierarkiReportMTD(payload).then(response => {
Riri Novita's avatar
Riri Novita committed
232 233 234
                console.log(payload);
                console.log(response);
                let dataTable = []
Riri Novita's avatar
Riri Novita committed
235
                if (response.data) {
Riri Novita's avatar
Riri Novita committed
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 280 281 282 283 284 285 286 287 288 289 290 291 292
                    if (response.data.status === 'success') {
                        let res = [response.data.data]
                        const handlePushChild = (item) => {
                            let indexIDzz = dataTable.findIndex((val) => val[0] === item.company_id)
                            if (indexIDzz === -1) {
                                dataTable.push([
                                    // item.company_id,
                                    0,
                                    item.parent,
                                    item.level,
                                    item.item_name,
                                    item.revenue_act,
                                    item.revenue_mb,
                                    item.revenue_percent_of_mb,
                                    item.ebitda_act,
                                    item.ebitda_mb,
                                    item.ebitda_percent_of_mb,
                                    item.tpat_act,
                                    item.tpat_mb,
                                    item.tpat_percent_of_mb,
                                    item.npat_act,
                                    item.npat_mb,
                                    item.npat_percent_of_mb,
                                    item.cash_flow_cfo,
                                    item.cash_flow_cfi,
                                    item.cash_flow_cff,
                                    item.cash_flow_cf,
                                    item.os_bank_loan_ki,
                                    item.os_bank_loan_wc,
                                    item.os_bank_loan_other,
                                    item.os_bank_loan_total,
                                    item.os_shl,
                                    item.balance_sheet_cash_bank,
                                    item.balance_sheet_ca,
                                    item.balance_sheet_cl,
                                    item.balance_sheet_equity,
                                    item.ratio_cr,
                                    item.ratio_der,
                                    item.ratio_debt_to_ebitda,
                                    item.ratio_to_interest,
                                    item.ratio_ar_days,
                                    item.ratio_inv_days,
                                    item.ratio_ap_days,
                                    item.ratio_ccc,
                                    item.is_approved == undefined ? true : item.is_approved,
                                    // item.order,
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
                        res.map((item, index) => {
Riri Novita's avatar
Riri Novita committed
293 294 295
                            dataTable.push([
                                // item.company_id,
                                0,
Riri Novita's avatar
Riri Novita committed
296 297
                                item.parent,
                                item.level,
Riri Novita's avatar
Riri Novita committed
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
                                item.item_name,
                                item.revenue_act,
                                item.revenue_mb,
                                item.revenue_percent_of_mb,
                                item.ebitda_act,
                                item.ebitda_mb,
                                item.ebitda_percent_of_mb,
                                item.tpat_act,
                                item.tpat_mb,
                                item.tpat_percent_of_mb,
                                item.npat_act,
                                item.npat_mb,
                                item.npat_percent_of_mb,
                                item.cash_flow_cfo,
                                item.cash_flow_cfi,
                                item.cash_flow_cff,
                                item.cash_flow_cf,
                                item.os_bank_loan_ki,
                                item.os_bank_loan_wc,
                                item.os_bank_loan_other,
                                item.os_bank_loan_total,
                                item.os_shl,
                                item.balance_sheet_cash_bank,
                                item.balance_sheet_ca,
                                item.balance_sheet_cl,
                                item.balance_sheet_equity,
                                item.ratio_cr,
                                item.ratio_der,
                                item.ratio_debt_to_ebitda,
                                item.ratio_to_interest,
                                item.ratio_ar_days,
                                item.ratio_inv_days,
                                item.ratio_ap_days,
                                item.ratio_ccc,
Riri Novita's avatar
Riri Novita committed
332
                                item.is_approved == undefined ? true : item.is_approved,
Riri Novita's avatar
Riri Novita committed
333
                                // item.order,
Riri Novita's avatar
Riri Novita committed
334
                            ])
Riri Novita's avatar
Riri Novita committed
335 336 337 338 339 340
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
Riri Novita's avatar
Riri Novita committed
341
                            }
Riri Novita's avatar
Riri Novita committed
342 343 344 345 346 347 348 349 350 351
                        })
                        console.log(dataTable)
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                    } 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);
Riri Novita's avatar
Riri Novita committed
352
                            }
Riri Novita's avatar
Riri Novita committed
353 354
                        })
                    }
Riri Novita's avatar
Riri Novita committed
355 356 357
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
Riri Novita's avatar
Riri Novita committed
358
            })
Riri Novita's avatar
Riri Novita committed
359
        } else if (this.state.report.value === 2) {
rifkaki's avatar
rifkaki committed
360 361 362
            api.create().getHierarkiReportYtd(payload).then(response => {
                console.log(payload);
                console.log(response);
Riri Novita's avatar
Riri Novita committed
363
                let dataTable = []
rifkaki's avatar
rifkaki committed
364
                if (response.data) {
Riri Novita's avatar
Riri Novita committed
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
                    if (response.data.status === 'success') {
                        let res = [response.data.data]
                        const handlePushChild = (item) => {
                            let indexIDzz = dataTable.findIndex((val) => val[0] === item.company_id)
                            if (indexIDzz === -1) {
                                dataTable.push([
                                    0,
                                    item.parent,
                                    item.level,
                                    item.item_name,
                                    item.revenue_ytd_act,
                                    item.revenue_ytd_mb,
                                    item.revenue_ytd_percent_of_mb,
                                    item.revenue_ytd_last_year,
                                    item.revenue_ytd_percent_of_last_year,
                                    item.revenue_fy_ol,
                                    item.revenue_fy_mb,
                                    item.revenue_fy_percent_of_mb,
                                    item.revenue_fy_last_year,
                                    item.revenue_fy_percent_of_last_year,
                                    item.ebitda_ytd_act,
                                    item.ebitda_ytd_mb,
                                    item.ebitda_ytd_percent_of_mb,
                                    item.ebitda_ytd_last_year,
                                    item.ebitda_ytd_percent_of_last_year,
                                    item.ebitda_fy_ol,
                                    item.ebitda_fy_mb,
                                    item.ebitda_fy_percent_of_mb,
                                    item.ebitda_fy_last_year,
                                    item.ebitda_fy_percent_of_last_year,
                                    item.tpat_ytd_act,
                                    item.tpat_ytd_mb,
                                    item.tpat_ytd_percent_of_mb,
                                    item.tpat_ytd_last_year,
                                    item.tpat_ytd_percent_of_last_year,
                                    item.tpat_fy_ol,
                                    item.tpat_fy_mb,
                                    item.tpat_fy_percent_of_mb,
                                    item.tpat_fy_last_year,
                                    item.tpat_fy_percent_of_last_year,
                                    item.npat_ytd_act,
                                    item.npat_ytd_mb,
                                    item.npat_ytd_percent_of_mb,
                                    item.npat_ytd_last_year,
                                    item.npat_ytd_percent_of_last_year,
                                    item.npat_fy_ol,
                                    item.npat_fy_mb,
                                    item.npat_fy_percent_of_mb,
                                    item.npat_fy_last_year,
                                    item.npat_fy_percent_of_last_year,
                                    item.order,
                                    item.is_approved == undefined ? true : item.is_approved,
qorri_di's avatar
qorri_di committed
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
                                    item.ytd_optional_cashflow_cfo,
                                    item.ytd_optional_cashflow_cfi,
                                    item.ytd_optional_cashflow_cff,
                                    item.ytd_optional_cashflow_netcf,
                                    item.ytd_optional_osbankloan_ki,
                                    item.ytd_optional_osbankloan_wc,
                                    item.ytd_optional_osbankloan_others,
                                    item.ytd_optional_osbankloan_total,
                                    item.ytd_optional_os_shl,
                                    item.ytd_optional_balancesheet_cashbank,
                                    item.ytd_optional_balancesheet_ca,
                                    item.ytd_optional_balancesheet_cl,
                                    item.ytd_optional_balancesheet_equity,
                                    item.ytd_optional_financialratio_cr,
                                    item.ytd_optional_financialratio_der,
                                    item.ytd_optional_financialratio_debttoebitda,
                                    item.ytd_optional_financialratio_tointerest,
                                    item.ytd_optional_financialratio_ardays,
                                    item.ytd_optional_financialratio_invdays,
                                    item.ytd_optional_financialratio_apdays,
                                    item.ytd_optional_financialratio_ccc,
Riri Novita's avatar
Riri Novita committed
438 439 440 441 442 443 444 445 446 447 448
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
                        res.map((item, index) => {
rifkaki's avatar
rifkaki committed
449
                            dataTable.push([
rifkaki's avatar
rifkaki committed
450
                                0,
rifkaki's avatar
rifkaki committed
451 452
                                item.parent,
                                item.level,
rifkaki's avatar
rifkaki committed
453
                                item.item_name,
rifkaki's avatar
rifkaki committed
454 455
                                item.revenue_ytd_act,
                                item.revenue_ytd_mb,
rifkaki's avatar
rifkaki committed
456
                                item.revenue_ytd_percent_of_mb,
rifkaki's avatar
rifkaki committed
457
                                item.revenue_ytd_last_year,
rifkaki's avatar
rifkaki committed
458
                                item.revenue_ytd_percent_of_last_year,
rifkaki's avatar
rifkaki committed
459 460
                                item.revenue_fy_ol,
                                item.revenue_fy_mb,
rifkaki's avatar
rifkaki committed
461
                                item.revenue_fy_percent_of_mb,
rifkaki's avatar
rifkaki committed
462
                                item.revenue_fy_last_year,
rifkaki's avatar
rifkaki committed
463
                                item.revenue_fy_percent_of_last_year,
rifkaki's avatar
rifkaki committed
464 465
                                item.ebitda_ytd_act,
                                item.ebitda_ytd_mb,
rifkaki's avatar
rifkaki committed
466
                                item.ebitda_ytd_percent_of_mb,
rifkaki's avatar
rifkaki committed
467
                                item.ebitda_ytd_last_year,
rifkaki's avatar
rifkaki committed
468
                                item.ebitda_ytd_percent_of_last_year,
rifkaki's avatar
rifkaki committed
469 470
                                item.ebitda_fy_ol,
                                item.ebitda_fy_mb,
rifkaki's avatar
rifkaki committed
471
                                item.ebitda_fy_percent_of_mb,
rifkaki's avatar
rifkaki committed
472
                                item.ebitda_fy_last_year,
rifkaki's avatar
rifkaki committed
473
                                item.ebitda_fy_percent_of_last_year,
rifkaki's avatar
rifkaki committed
474 475
                                item.tpat_ytd_act,
                                item.tpat_ytd_mb,
rifkaki's avatar
rifkaki committed
476
                                item.tpat_ytd_percent_of_mb,
rifkaki's avatar
rifkaki committed
477
                                item.tpat_ytd_last_year,
rifkaki's avatar
rifkaki committed
478
                                item.tpat_ytd_percent_of_last_year,
rifkaki's avatar
rifkaki committed
479 480
                                item.tpat_fy_ol,
                                item.tpat_fy_mb,
rifkaki's avatar
rifkaki committed
481
                                item.tpat_fy_percent_of_mb,
rifkaki's avatar
rifkaki committed
482
                                item.tpat_fy_last_year,
rifkaki's avatar
rifkaki committed
483
                                item.tpat_fy_percent_of_last_year,
rifkaki's avatar
rifkaki committed
484 485
                                item.npat_ytd_act,
                                item.npat_ytd_mb,
rifkaki's avatar
rifkaki committed
486
                                item.npat_ytd_percent_of_mb,
rifkaki's avatar
rifkaki committed
487
                                item.npat_ytd_last_year,
rifkaki's avatar
rifkaki committed
488
                                item.npat_ytd_percent_of_last_year,
rifkaki's avatar
rifkaki committed
489 490
                                item.npat_fy_ol,
                                item.npat_fy_mb,
rifkaki's avatar
rifkaki committed
491
                                item.npat_fy_percent_of_mb,
rifkaki's avatar
rifkaki committed
492
                                item.npat_fy_last_year,
rifkaki's avatar
rifkaki committed
493
                                item.npat_fy_percent_of_last_year,
rifkaki's avatar
rifkaki committed
494
                                item.order,
rifkaki's avatar
rifkaki committed
495
                                item.is_approved == undefined ? true : item.is_approved,
qorri_di's avatar
qorri_di committed
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
                                item.ytd_optional_cashflow_cfo,
                                item.ytd_optional_cashflow_cfi,
                                item.ytd_optional_cashflow_cff,
                                item.ytd_optional_cashflow_netcf,
                                item.ytd_optional_osbankloan_ki,
                                item.ytd_optional_osbankloan_wc,
                                item.ytd_optional_osbankloan_others,
                                item.ytd_optional_osbankloan_total,
                                item.ytd_optional_os_shl,
                                item.ytd_optional_balancesheet_cashbank,
                                item.ytd_optional_balancesheet_ca,
                                item.ytd_optional_balancesheet_cl,
                                item.ytd_optional_balancesheet_equity,
                                item.ytd_optional_financialratio_cr,
                                item.ytd_optional_financialratio_der,
                                item.ytd_optional_financialratio_debttoebitda,
                                item.ytd_optional_financialratio_tointerest,
                                item.ytd_optional_financialratio_ardays,
                                item.ytd_optional_financialratio_invdays,
                                item.ytd_optional_financialratio_apdays,
                                item.ytd_optional_financialratio_ccc,
rifkaki's avatar
rifkaki committed
517
                            ])
Riri Novita's avatar
Riri Novita committed
518 519 520 521 522 523
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
rifkaki's avatar
rifkaki committed
524
                            }
Riri Novita's avatar
Riri Novita committed
525 526 527 528 529 530 531 532 533 534
                        })
                        console.log(dataTable)
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                    } 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);
rifkaki's avatar
rifkaki committed
535
                            }
Riri Novita's avatar
Riri Novita committed
536 537
                        })
                    }
rifkaki's avatar
rifkaki committed
538 539 540 541
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
            })
Riri Novita's avatar
Riri Novita committed
542
        } else if (this.state.report.value === 3) {
Riri Novita's avatar
Riri Novita committed
543 544 545 546 547
            api.create().getHierarkiReportCPSM(payload).then(response => {
                console.log(payload);
                console.log(response);
                let dataTable = []
                if (response.data) {
Riri Novita's avatar
Riri Novita committed
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 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
                    if (response.data.status === 'success') {
                        let res = [response.data.data]
                        const handlePushChild = (item) => {
                            let indexIDzz = dataTable.findIndex((val) => val[0] === item.company_id)
                            if (indexIDzz === -1) {
                                dataTable.push([
                                    0,
                                    item.parent,
                                    item.level,
                                    item.item_name,
                                    item.revenue_last_year,
                                    item.revenue_ol,
                                    item.revenue_mb,
                                    item.revenue_percent_of_mb,
                                    item.revenue_next_year,
                                    item.revenue_next_two_year,
                                    item.ebitda_last_year,
                                    item.ebitda_ol,
                                    item.ebitda_mb,
                                    item.ebitda_percent_of_mb,
                                    item.ebitda_next_year,
                                    item.ebitda_next_two_year,
                                    item.tpat_last_year,
                                    item.tpat_ol,
                                    item.tpat_mb,
                                    item.tpat_percent_of_mb,
                                    item.tpat_next_year,
                                    item.tpat_next_two_year,
                                    item.npat_last_year,
                                    item.npat_ol,
                                    item.npat_mb,
                                    item.npat_percent_of_mb,
                                    item.npat_next_year,
                                    item.npat_next_two_year,
                                    item.roic_ol,
                                    item.roic_next_year,
                                    item.roic_next_two_year,
                                    item.ebitda_margin_ol,
                                    item.ebitda_margin_next_year,
                                    item.ebitda_margin_next_two_year,
                                    item.tpat_margin_ol,
                                    item.tpat_margin_next_year,
                                    item.tpat_margin_next_two_year,
                                    item.percent_revenue_yoy_ol,
                                    item.percent_revenue_yoy_next_year,
                                    item.percent_revenue_yoy_next_two_year,
                                    item.percent_ebitda_yoy_ol,
                                    item.percent_ebitda_yoy_next_year,
                                    item.percent_ebitda_yoy_next_two_year,
                                    item.percent_tpat_yoy_ol,
                                    item.percent_tpat_yoy_next_year,
                                    item.percent_tpat_yoy_next_two_year,
                                    item.percent_npat_yoy_ol,
                                    item.percent_npat_yoy_next_year,
                                    item.percent_npat_yoy_next_two_year,
                                    item.is_approved == undefined ? true : item.is_approved,
                                    // item.order,
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
                        res.map((item, index) => {
Riri Novita's avatar
Riri Novita committed
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
                            dataTable.push([
                                0,
                                item.parent,
                                item.level,
                                item.item_name,
                                item.revenue_last_year,
                                item.revenue_ol,
                                item.revenue_mb,
                                item.revenue_percent_of_mb,
                                item.revenue_next_year,
                                item.revenue_next_two_year,
                                item.ebitda_last_year,
                                item.ebitda_ol,
                                item.ebitda_mb,
                                item.ebitda_percent_of_mb,
                                item.ebitda_next_year,
                                item.ebitda_next_two_year,
                                item.tpat_last_year,
                                item.tpat_ol,
                                item.tpat_mb,
                                item.tpat_percent_of_mb,
                                item.tpat_next_year,
                                item.tpat_next_two_year,
                                item.npat_last_year,
                                item.npat_ol,
                                item.npat_mb,
                                item.npat_percent_of_mb,
                                item.npat_next_year,
                                item.npat_next_two_year,
                                item.roic_ol,
                                item.roic_next_year,
                                item.roic_next_two_year,
                                item.ebitda_margin_ol,
                                item.ebitda_margin_next_year,
                                item.ebitda_margin_next_two_year,
                                item.tpat_margin_ol,
                                item.tpat_margin_next_year,
                                item.tpat_margin_next_two_year,
                                item.percent_revenue_yoy_ol,
                                item.percent_revenue_yoy_next_year,
                                item.percent_revenue_yoy_next_two_year,
                                item.percent_ebitda_yoy_ol,
                                item.percent_ebitda_yoy_next_year,
                                item.percent_ebitda_yoy_next_two_year,
                                item.percent_tpat_yoy_ol,
                                item.percent_tpat_yoy_next_year,
                                item.percent_tpat_yoy_next_two_year,
                                item.percent_npat_yoy_ol,
                                item.percent_npat_yoy_next_year,
                                item.percent_npat_yoy_next_two_year,
Riri Novita's avatar
Riri Novita committed
666
                                item.is_approved == undefined ? true : item.is_approved,
Riri Novita's avatar
Riri Novita committed
667
                                // item.order,
Riri Novita's avatar
Riri Novita committed
668
                            ])
Riri Novita's avatar
Riri Novita committed
669 670 671 672 673 674
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
Riri Novita's avatar
Riri Novita committed
675
                            }
Riri Novita's avatar
Riri Novita committed
676 677 678 679 680 681 682 683 684 685
                        })
                        console.log(dataTable);
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                    } 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);
Riri Novita's avatar
Riri Novita committed
686
                            }
Riri Novita's avatar
Riri Novita committed
687 688
                        })
                    }
Riri Novita's avatar
Riri Novita committed
689 690 691 692
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
            })
Riri Novita's avatar
Riri Novita committed
693
        } else if (this.state.report.value === 4) {
rifkaki's avatar
rifkaki committed
694 695 696
            api.create().getHierarkiReportHistorical(newPayload).then(response => {
                console.log(newPayload);
                console.log(response);
Riri Novita's avatar
Riri Novita committed
697
                let dataTable = []
rifkaki's avatar
rifkaki committed
698
                if (response.data) {
Riri Novita's avatar
Riri Novita committed
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
                    if (response.data.status === 'success') {
                        let res = [response.data.data]
                        console.log(res)
                        const handlePushChild = (item) => {
                            let indexIDzz = dataTable.findIndex((val) => val[0] === item.company_id)
                            if (indexIDzz === -1) {
                                dataTable.push([
                                    0,
                                    item.parent,
                                    item.level,
                                    item.item_name,
                                    item.revenue_last_ten_year,
                                    item.revenue_last_nine_year,
                                    item.revenue_last_eight_year,
                                    item.revenue_last_seven_year,
                                    item.revenue_last_six_year,
                                    item.revenue_last_five_year,
                                    item.revenue_last_four_year,
                                    item.revenue_last_three_year,
                                    item.revenue_last_two_year,
                                    item.revenue_last_year,
                                    // item.revenue,
                                    0,
                                    item.ebitda_last_ten_year,
                                    item.ebitda_last_nine_year,
                                    item.ebitda_last_eight_year,
                                    item.ebitda_last_seven_year,
                                    item.ebitda_last_six_year,
                                    item.ebitda_last_five_year,
                                    item.ebitda_last_four_year,
                                    item.ebitda_last_three_year,
                                    item.ebitda_last_two_year,
                                    item.ebitda_last_year,
                                    // item.ebitda,
                                    0,
                                    item.tpat_last_ten_year,
                                    item.tpat_last_nine_year,
                                    item.tpat_last_eight_year,
                                    item.tpat_last_seven_year,
                                    item.tpat_last_six_year,
                                    item.tpat_last_five_year,
                                    item.tpat_last_four_year,
                                    item.tpat_last_three_year,
                                    item.tpat_last_two_year,
                                    item.tpat_last_year,
                                    // item.tpat,
                                    0,
                                    item.npat_last_ten_year,
                                    item.npat_last_nine_year,
                                    item.npat_last_eight_year,
                                    item.npat_last_seven_year,
                                    item.npat_last_six_year,
                                    item.npat_last_five_year,
                                    item.npat_last_four_year,
                                    item.npat_last_three_year,
                                    item.npat_last_two_year,
                                    item.npat_last_year,
                                    // item.npat,
                                    0,
                                    item.total_asset_last_ten_year,
                                    item.total_asset_last_nine_year,
                                    item.total_asset_last_eight_year,
                                    item.total_asset_last_seven_year,
                                    item.total_asset_last_six_year,
                                    item.total_asset_last_five_year,
                                    item.total_asset_last_four_year,
                                    item.total_asset_last_three_year,
                                    item.total_asset_last_two_year,
                                    item.total_asset_last_year,
                                    // item.total_asset,
                                    0,
                                    item.total_equity_last_ten_year,
                                    item.total_equity_last_nine_year,
                                    item.total_equity_last_eight_year,
                                    item.total_equity_last_seven_year,
                                    item.total_equity_last_six_year,
                                    item.total_equity_last_five_year,
                                    item.total_equity_last_four_year,
                                    item.total_equity_last_three_year,
                                    item.total_equity_last_two_year,
                                    item.total_equity_last_year,
                                    // item.total_equity,
                                    0,
                                    item.order,
                                ])
                            }
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
                        res.map((item, index) => {
rifkaki's avatar
rifkaki committed
794
                            dataTable.push([
rifkaki's avatar
rifkaki committed
795
                                0,
rifkaki's avatar
rifkaki committed
796 797
                                item.parent,
                                item.level,
rifkaki's avatar
rifkaki committed
798 799 800 801 802 803 804 805 806 807 808
                                item.item_name,
                                item.revenue_last_ten_year,
                                item.revenue_last_nine_year,
                                item.revenue_last_eight_year,
                                item.revenue_last_seven_year,
                                item.revenue_last_six_year,
                                item.revenue_last_five_year,
                                item.revenue_last_four_year,
                                item.revenue_last_three_year,
                                item.revenue_last_two_year,
                                item.revenue_last_year,
Riri Novita's avatar
Riri Novita committed
809
                                item.revenue,
rifkaki's avatar
rifkaki committed
810 811 812 813 814 815 816 817 818 819
                                item.ebitda_last_ten_year,
                                item.ebitda_last_nine_year,
                                item.ebitda_last_eight_year,
                                item.ebitda_last_seven_year,
                                item.ebitda_last_six_year,
                                item.ebitda_last_five_year,
                                item.ebitda_last_four_year,
                                item.ebitda_last_three_year,
                                item.ebitda_last_two_year,
                                item.ebitda_last_year,
Riri Novita's avatar
Riri Novita committed
820
                                item.ebitda,
rifkaki's avatar
rifkaki committed
821 822 823 824 825 826 827 828 829 830
                                item.tpat_last_ten_year,
                                item.tpat_last_nine_year,
                                item.tpat_last_eight_year,
                                item.tpat_last_seven_year,
                                item.tpat_last_six_year,
                                item.tpat_last_five_year,
                                item.tpat_last_four_year,
                                item.tpat_last_three_year,
                                item.tpat_last_two_year,
                                item.tpat_last_year,
Riri Novita's avatar
Riri Novita committed
831
                                item.tpat,
rifkaki's avatar
rifkaki committed
832 833 834 835 836 837 838 839 840 841
                                item.npat_last_ten_year,
                                item.npat_last_nine_year,
                                item.npat_last_eight_year,
                                item.npat_last_seven_year,
                                item.npat_last_six_year,
                                item.npat_last_five_year,
                                item.npat_last_four_year,
                                item.npat_last_three_year,
                                item.npat_last_two_year,
                                item.npat_last_year,
Riri Novita's avatar
Riri Novita committed
842
                                item.npat,
rifkaki's avatar
rifkaki committed
843 844 845 846 847 848 849 850 851 852
                                item.total_asset_last_ten_year,
                                item.total_asset_last_nine_year,
                                item.total_asset_last_eight_year,
                                item.total_asset_last_seven_year,
                                item.total_asset_last_six_year,
                                item.total_asset_last_five_year,
                                item.total_asset_last_four_year,
                                item.total_asset_last_three_year,
                                item.total_asset_last_two_year,
                                item.total_asset_last_year,
Riri Novita's avatar
Riri Novita committed
853
                                item.total_asset,
rifkaki's avatar
rifkaki committed
854 855 856 857 858 859 860 861 862 863
                                item.total_equity_last_ten_year,
                                item.total_equity_last_nine_year,
                                item.total_equity_last_eight_year,
                                item.total_equity_last_seven_year,
                                item.total_equity_last_six_year,
                                item.total_equity_last_five_year,
                                item.total_equity_last_four_year,
                                item.total_equity_last_three_year,
                                item.total_equity_last_two_year,
                                item.total_equity_last_year,
Riri Novita's avatar
Riri Novita committed
864
                                item.total_equity,
rifkaki's avatar
rifkaki committed
865 866
                                item.order,
                            ])
Riri Novita's avatar
Riri Novita committed
867 868 869 870 871 872
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
rifkaki's avatar
rifkaki committed
873
                            }
Riri Novita's avatar
Riri Novita committed
874 875 876 877 878 879 880 881 882 883
                        })
                        console.log()
                        this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                    } 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);
rifkaki's avatar
rifkaki committed
884
                            }
Riri Novita's avatar
Riri Novita committed
885 886
                        })
                    }
rifkaki's avatar
rifkaki committed
887 888 889
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
rifkaki's avatar
rifkaki committed
890
            })
qorri_di's avatar
qorri_di committed
891
        }    
Riri Novita's avatar
Riri Novita committed
892 893 894
    }

    async downloadAllData() {
Riri Novita's avatar
Riri Novita committed
895 896
        let {month, periode} = this.state
        console.log(month, periode);
Riri Novita's avatar
Riri Novita committed
897
        if (this.state.report.value === 1) {
d.arizona's avatar
d.arizona committed
898 899 900 901 902 903 904 905 906 907 908 909 910
            // alert("Download MTD Report Coming Soon")
            let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_mtd/export_report?year=${this.state.periode.periode}&&months=${this.state.month.month_id}`
            let sub_null = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_mtd/export_report?year=${this.state.periode.periode}&&months=${this.state.month.month_id}`
            console.log(url);
            let res = await fetch(
                this.state.submissionID == null ? sub_null : url
            )
            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;
Riri Novita's avatar
Riri Novita committed
911
                a.download = `Report MTD ${month.month_name} ${periode.periode}.xlsx`;
d.arizona's avatar
d.arizona committed
912 913
                a.click();
            }
Riri Novita's avatar
Riri Novita committed
914
        } else if (this.state.report.value === 2) {
rifkaki's avatar
rifkaki committed
915 916 917 918 919 920 921 922 923 924 925 926 927
            // alert("Download YTD Report Coming Soon")
            let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_ytd/export_report?year=${this.state.periode.periode}&&months=${this.state.month.month_id}`
            let sub_null = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_ytd/export_report?year=${this.state.periode.periode}&&months=${this.state.month.month_id}`
            console.log(url);
            let res = await fetch(
                this.state.submissionID == null ? sub_null : url
            )
            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;
Riri Novita's avatar
Riri Novita committed
928
                a.download = `Report YTD ${month.month_name} ${periode.periode}.xlsx`;
rifkaki's avatar
rifkaki committed
929 930
                a.click();
            }
Riri Novita's avatar
Riri Novita committed
931
        } else if (this.state.report.value === 3) {
rifkaki's avatar
rifkaki committed
932 933 934 935 936 937 938 939 940 941 942 943 944
            // alert("Download CPSM Report Coming Soon")
            let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_cpsm/export_report?year=${this.state.periode.periode}&&months=${this.state.month.month_id}`
            let sub_null = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_cpsm/export_report?year=${this.state.periode.periode}&&months=${this.state.month.month_id}`
            console.log(url);
            let res = await fetch(
                this.state.submissionID == null ? sub_null : url
            )
            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;
Riri Novita's avatar
Riri Novita committed
945
                a.download = `Report CPSM ${month.month_name} ${periode.periode}.xlsx`;
rifkaki's avatar
rifkaki committed
946 947
                a.click();
            }
Riri Novita's avatar
Riri Novita committed
948
        } else if (this.state.report.value === 4) {
rifkaki's avatar
rifkaki committed
949 950 951 952 953 954 955 956 957 958 959 960 961
            // alert("Download Historical Report Coming Soon")
            let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_historical/export_report?year=${this.state.periode.periode}`
            let sub_null = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/summary_historical/export_report?year=${this.state.periode.periode}`
            console.log(url);
            let res = await fetch(
                this.state.submissionID == null ? sub_null : url
            )
            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;
Riri Novita's avatar
Riri Novita committed
962
                a.download = `Report Historical ${periode.periode}.xlsx`;
rifkaki's avatar
rifkaki committed
963 964
                a.click();
            }
Riri Novita's avatar
Riri Novita committed
965
        } else {
qorri_di's avatar
qorri_di committed
966
            
Riri Novita's avatar
Riri Novita committed
967 968 969 970 971 972 973
            // setTimeout(() => {
            //     this.setState({ loading: false })
            // }, 1000);
        }
    }

    render() {
Riri Novita's avatar
Riri Novita committed
974

Riri Novita's avatar
Riri Novita committed
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
        const loadingComponent = (
            <div style={{ position: 'absolute', zIndex: 110, top: 0, left: 0, width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', background: 'rgba(255,255,255,0.8)' }}>
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
            </div>
        );
        return (
            <div style={{ 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' }}>Summary Triputra Group Report</Typography>
                    </div>
                    <div style={{ padding: 20, width: '100%' }}>
                        <Paper style={{ paddingTop: 10 }}>
                            <div style={{ borderBottom: 'solid 1px #c4c4c4' }} >
                                <Typography style={{ fontSize: '12px', color: '#4b4b4b', margin: 10 }}>Financial Summary of Triputra Group</Typography>
                            </div>
                            <div style={{ minWidth: 'max-content', padding: '20px 20px 0px 20px' }}>
                                <div style={{ marginTop: 15 }}>
                                    <Autocomplete
                                        options={this.state.reportType}
                                        getOptionLabel={(option) => titleCase(option.label)}
                                        id="typereport"
                                        onChange={(event, newInputValue) => this.setState({ report: newInputValue, loading: true, previewTable: false }, () => {
Riri Novita's avatar
Riri Novita committed
1003 1004 1005 1006 1007 1008
                                            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()
rifkaki's avatar
rifkaki committed
1009
                                            // this.getSubmission()
Riri Novita's avatar
Riri Novita committed
1010 1011 1012 1013 1014 1015 1016 1017 1018
                                            if (!String(this.state.report.label).toLocaleLowerCase().includes('historical')) {
                                                let index = data.sort((a, b) => a - b).findIndex((val) => val.periode == yearNow)
                                                // console.log(index)
                                                this.setState({periode: data[index]}, () => {
                                                    this.getDataTable()
                                                })
                                            } else {
                                                this.getDataTable()
                                            }
qorri_di's avatar
qorri_di committed
1019
                                            
Riri Novita's avatar
Riri Novita committed
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
                                        })}
                                        disableClearable
                                        style={{ width: 250 }}
                                        renderInput={(params) => <TextField {...params} label="Report Type" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.report}
                                    />
                                </div>
                                <div style={{ marginTop: 15 }}>
                                    <Autocomplete
                                        {...this.state.listPeriode}
                                        id="periode"
                                        onChange={(event, newInputValue) => this.setState({ periode: newInputValue, loading: true, previewTable: false }, () => {
rifkaki's avatar
rifkaki committed
1032 1033
                                            // this.getSubmission()
                                            this.getDataTable()
Riri Novita's avatar
Riri Novita committed
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
                                        })}
                                        disabled={this.state.intent === 'Home' ? true : false}
                                        disableClearable
                                        style={{ width: 250 }}
                                        renderInput={(params) =>
                                            <TextField {...params} label="Period" margin="normal" style={{ marginTop: 7 }}
                                            />}
                                        value={this.state.periode}
                                    />
                                </div>
qorri_di's avatar
qorri_di committed
1044
                                
Riri Novita's avatar
Riri Novita committed
1045
                                {(this.state.report != null && !String(this.state.report.label).toLocaleLowerCase().includes('historical')) && <div style={{ marginTop: 15 }}>
rifkaki's avatar
rifkaki committed
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
                                    <Autocomplete
                                        {...this.state.listMonths}
                                        // getOptionLabel={(option) => titleCase(option.label)}
                                        id="months"
                                        onChange={(event, newInputValue) => this.setState({ month: newInputValue, loading: true, previewTable: false }, () => {
                                            this.getDataTable()
                                        })}
                                        disableClearable
                                        style={{ width: 250 }}
                                        renderInput={(params) => <TextField {...params} label="Months" margin="normal" style={{ marginTop: 7 }} />}
                                        value={this.state.month}
                                    />
Riri Novita's avatar
Riri Novita committed
1058
                                </div>}
Riri Novita's avatar
Riri Novita committed
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
                            </div>
                            <div>
                                <div style={{ display: 'flex', justifyContent: 'space-between', padding: '0px 20px 10px 20px' }}>
                                    <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'
                                                    }}
rifkaki's avatar
rifkaki committed
1074
                                                    onClick={() => this.setState({ loading: true }, () => {
Riri Novita's avatar
Riri Novita committed
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
                                                        setTimeout(() => {
                                                            this.downloadAllData()
                                                        }, 100);
                                                    })}
                                                >
                                                    <img src={Images.download} />
                                                </button>
                                            </a>
                                            <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
                                        </div>
                                    )}
                                </div>
                                {this.state.loading && loadingComponent}
Riri Novita's avatar
Riri Novita committed
1088 1089
                                {this.state.previewTable && (
                                    <TableSummaryTriputra
Riri Novita's avatar
Riri Novita committed
1090 1091 1092
                                        width={this.props.width}
                                        height={this.props.height}
                                        open={this.props.open}
Riri Novita's avatar
Riri Novita committed
1093
                                        month={this.state.month}
Riri Novita's avatar
Riri Novita committed
1094 1095 1096 1097
                                        type={this.state.report ? this.state.report.value : 1}
                                        dataTable={this.state.dataTable}
                                        periode={this.state.periode ? this.state.periode.periode : null}
                                    />
Riri Novita's avatar
Riri Novita committed
1098
                                )}
Riri Novita's avatar
Riri Novita committed
1099 1100 1101 1102 1103 1104 1105 1106
                            </div>
                        </Paper>
                    </div>
                </div>
            </div>
        )
    }
}