SummaryOfTriputra.js 50.3 KB
Newer Older
Riri Novita's avatar
Riri Novita committed
1 2 3 4 5 6
import React, { Component } from 'react'
import { Typography, MenuItem, TextField, AppBar, Paper, Tabs, Tab } from '@material-ui/core'
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
        })
Riri Novita's avatar
Riri Novita committed
49 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) {
Riri Novita's avatar
Riri Novita committed
63
                            if (item >= 2000 && item <= (Number(currentYear) + 1)) {
Riri Novita's avatar
Riri Novita committed
64 65
                                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 98 99 100 101 102
                        // if (this.state.isApprover === true) {
                        //     this.getCompanySubmitted()
                        // } else {
                        //     this.getRevision()
                        // }
                    })
                }
            }
        })
    }

rifkaki's avatar
rifkaki committed
103 104 105 106 107 108 109 110 111 112 113
    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
114
                            month_id: item.id,
rifkaki's avatar
rifkaki committed
115 116 117 118 119 120 121 122 123 124 125 126 127
                            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
128
                    this.setState({ listMonths: defaultProps, month: index == -1 ? monthData[0] : monthData[index] }, () => {
rifkaki's avatar
rifkaki committed
129 130 131 132 133 134 135 136
                        this.getDataTable()
                    })
                    console.log(this.state.month)
                }
            }
        })
    }

Riri Novita's avatar
Riri Novita committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
    // 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
172

Riri Novita's avatar
Riri Novita committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
    // 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
196 197

    getDataTable() {
rifkaki's avatar
rifkaki committed
198
        this.setState({ loading: true })
rifkaki's avatar
rifkaki committed
199
        let payload = {
Riri Novita's avatar
Riri Novita committed
200
            "report_type": this.state.report.key,
Riri Novita's avatar
Riri Novita committed
201 202
            "periode": this.state.periode.periode,
            "months" : this.state.month.month_id
rifkaki's avatar
rifkaki committed
203
        }
rifkaki's avatar
rifkaki committed
204
        let newPayload = {
Riri Novita's avatar
Riri Novita committed
205
            "periode": this.state.periode.periode,
rifkaki's avatar
rifkaki committed
206
            "report_type":"historical"
Riri Novita's avatar
Riri Novita committed
207 208
        }
        if (this.state.report.value === 1) {
Riri Novita's avatar
Riri Novita committed
209
            api.create().getHierarkiReportMTD(payload).then(response => {
Riri Novita's avatar
Riri Novita committed
210 211 212
                console.log(payload);
                console.log(response);
                let dataTable = []
Riri Novita's avatar
Riri Novita committed
213
                if (response.data) {
Riri Novita's avatar
Riri Novita committed
214
                    let res = [response.data.data]
Riri Novita's avatar
Riri Novita committed
215
                    const handlePushChild = (item) => {
Riri Novita's avatar
Riri Novita committed
216
                        let indexIDzz = dataTable.findIndex((val) => val[0] === item.company_id)
Riri Novita's avatar
Riri Novita committed
217
                        if (indexIDzz === -1) {
Riri Novita's avatar
Riri Novita committed
218 219 220
                            dataTable.push([
                                // item.company_id,
                                0,
Riri Novita's avatar
Riri Novita committed
221 222
                                item.parent,
                                item.level,
Riri Novita's avatar
Riri Novita committed
223 224 225 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
                                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
257
                                item.is_approved == undefined ? true : item.is_approved,
Riri Novita's avatar
Riri Novita committed
258
                                // item.order,
Riri Novita's avatar
Riri Novita committed
259 260 261 262 263 264 265 266 267 268 269
                            ])
                        }
                        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
270 271 272
                        dataTable.push([
                            // item.company_id,
                            0,
Riri Novita's avatar
Riri Novita committed
273 274
                            item.parent,
                            item.level,
Riri Novita's avatar
Riri Novita committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
                            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
309
                            item.is_approved == undefined ? true : item.is_approved,
Riri Novita's avatar
Riri Novita committed
310
                            // item.order,
Riri Novita's avatar
Riri Novita committed
311 312 313 314 315 316 317 318 319
                        ])
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    })
Riri Novita's avatar
Riri Novita committed
320 321
                    console.log(dataTable)
                    this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
Riri Novita's avatar
Riri Novita committed
322 323 324
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
Riri Novita's avatar
Riri Novita committed
325
            })
Riri Novita's avatar
Riri Novita committed
326
        } else if (this.state.report.value === 2) {
rifkaki's avatar
rifkaki committed
327 328 329
            api.create().getHierarkiReportYtd(payload).then(response => {
                console.log(payload);
                console.log(response);
Riri Novita's avatar
Riri Novita committed
330
                let dataTable = []
rifkaki's avatar
rifkaki committed
331
                if (response.data) {
rifkaki's avatar
rifkaki committed
332
                    let res = [response.data.data]
rifkaki's avatar
rifkaki committed
333 334 335 336
                    const handlePushChild = (item) => {
                        let indexIDzz = dataTable.findIndex((val) => val[0] === item.company_id)
                        if (indexIDzz === -1) {
                            dataTable.push([
rifkaki's avatar
rifkaki committed
337
                                0,
rifkaki's avatar
rifkaki committed
338 339
                                item.parent,
                                item.level,
rifkaki's avatar
rifkaki committed
340
                                item.item_name,
rifkaki's avatar
rifkaki committed
341 342
                                item.revenue_ytd_act,
                                item.revenue_ytd_mb,
rifkaki's avatar
rifkaki committed
343
                                item.revenue_ytd_percent_of_mb,
rifkaki's avatar
rifkaki committed
344
                                item.revenue_ytd_last_year,
rifkaki's avatar
rifkaki committed
345
                                item.revenue_ytd_percent_of_last_year,
rifkaki's avatar
rifkaki committed
346 347
                                item.revenue_fy_ol,
                                item.revenue_fy_mb,
rifkaki's avatar
rifkaki committed
348
                                item.revenue_fy_percent_of_mb,
rifkaki's avatar
rifkaki committed
349
                                item.revenue_fy_last_year,
rifkaki's avatar
rifkaki committed
350
                                item.revenue_fy_percent_of_last_year,
rifkaki's avatar
rifkaki committed
351 352
                                item.ebitda_ytd_act,
                                item.ebitda_ytd_mb,
rifkaki's avatar
rifkaki committed
353
                                item.ebitda_ytd_percent_of_mb,
rifkaki's avatar
rifkaki committed
354
                                item.ebitda_ytd_last_year,
rifkaki's avatar
rifkaki committed
355
                                item.ebitda_ytd_percent_of_last_year,
rifkaki's avatar
rifkaki committed
356 357
                                item.ebitda_fy_ol,
                                item.ebitda_fy_mb,
rifkaki's avatar
rifkaki committed
358
                                item.ebitda_fy_percent_of_mb,
rifkaki's avatar
rifkaki committed
359
                                item.ebitda_fy_last_year,
rifkaki's avatar
rifkaki committed
360
                                item.ebitda_fy_percent_of_last_year,
rifkaki's avatar
rifkaki committed
361 362
                                item.tpat_ytd_act,
                                item.tpat_ytd_mb,
rifkaki's avatar
rifkaki committed
363
                                item.tpat_ytd_percent_of_mb,
rifkaki's avatar
rifkaki committed
364
                                item.tpat_ytd_last_year,
rifkaki's avatar
rifkaki committed
365
                                item.tpat_ytd_percent_of_last_year,
rifkaki's avatar
rifkaki committed
366 367
                                item.tpat_fy_ol,
                                item.tpat_fy_mb,
rifkaki's avatar
rifkaki committed
368
                                item.tpat_fy_percent_of_mb,
rifkaki's avatar
rifkaki committed
369
                                item.tpat_fy_last_year,
rifkaki's avatar
rifkaki committed
370
                                item.tpat_fy_percent_of_last_year,
rifkaki's avatar
rifkaki committed
371 372
                                item.npat_ytd_act,
                                item.npat_ytd_mb,
rifkaki's avatar
rifkaki committed
373
                                item.npat_ytd_percent_of_mb,
rifkaki's avatar
rifkaki committed
374
                                item.npat_ytd_last_year,
rifkaki's avatar
rifkaki committed
375
                                item.npat_ytd_percent_of_last_year,
rifkaki's avatar
rifkaki committed
376 377
                                item.npat_fy_ol,
                                item.npat_fy_mb,
rifkaki's avatar
rifkaki committed
378
                                item.npat_fy_percent_of_mb,
rifkaki's avatar
rifkaki committed
379
                                item.npat_fy_last_year,
rifkaki's avatar
rifkaki committed
380
                                item.npat_fy_percent_of_last_year,
rifkaki's avatar
rifkaki committed
381
                                item.order,
rifkaki's avatar
rifkaki committed
382
                                item.is_approved == undefined ? true : item.is_approved,
rifkaki's avatar
rifkaki committed
383 384 385 386 387 388 389 390 391 392 393 394
                            ])
                        }
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    }
                    res.map((item, index) => {
                        dataTable.push([
rifkaki's avatar
rifkaki committed
395
                            0,
rifkaki's avatar
rifkaki committed
396 397
                            item.parent,
                            item.level,
rifkaki's avatar
rifkaki committed
398
                            item.item_name,
rifkaki's avatar
rifkaki committed
399 400
                            item.revenue_ytd_act,
                            item.revenue_ytd_mb,
rifkaki's avatar
rifkaki committed
401
                            item.revenue_ytd_percent_of_mb,
rifkaki's avatar
rifkaki committed
402
                            item.revenue_ytd_last_year,
rifkaki's avatar
rifkaki committed
403
                            item.revenue_ytd_percent_of_last_year,
rifkaki's avatar
rifkaki committed
404 405
                            item.revenue_fy_ol,
                            item.revenue_fy_mb,
rifkaki's avatar
rifkaki committed
406
                            item.revenue_fy_percent_of_mb,
rifkaki's avatar
rifkaki committed
407
                            item.revenue_fy_last_year,
rifkaki's avatar
rifkaki committed
408
                            item.revenue_fy_percent_of_last_year,
rifkaki's avatar
rifkaki committed
409 410
                            item.ebitda_ytd_act,
                            item.ebitda_ytd_mb,
rifkaki's avatar
rifkaki committed
411
                            item.ebitda_ytd_percent_of_mb,
rifkaki's avatar
rifkaki committed
412
                            item.ebitda_ytd_last_year,
rifkaki's avatar
rifkaki committed
413
                            item.ebitda_ytd_percent_of_last_year,
rifkaki's avatar
rifkaki committed
414 415
                            item.ebitda_fy_ol,
                            item.ebitda_fy_mb,
rifkaki's avatar
rifkaki committed
416
                            item.ebitda_fy_percent_of_mb,
rifkaki's avatar
rifkaki committed
417
                            item.ebitda_fy_last_year,
rifkaki's avatar
rifkaki committed
418
                            item.ebitda_fy_percent_of_last_year,
rifkaki's avatar
rifkaki committed
419 420
                            item.tpat_ytd_act,
                            item.tpat_ytd_mb,
rifkaki's avatar
rifkaki committed
421
                            item.tpat_ytd_percent_of_mb,
rifkaki's avatar
rifkaki committed
422
                            item.tpat_ytd_last_year,
rifkaki's avatar
rifkaki committed
423
                            item.tpat_ytd_percent_of_last_year,
rifkaki's avatar
rifkaki committed
424 425
                            item.tpat_fy_ol,
                            item.tpat_fy_mb,
rifkaki's avatar
rifkaki committed
426
                            item.tpat_fy_percent_of_mb,
rifkaki's avatar
rifkaki committed
427
                            item.tpat_fy_last_year,
rifkaki's avatar
rifkaki committed
428
                            item.tpat_fy_percent_of_last_year,
rifkaki's avatar
rifkaki committed
429 430
                            item.npat_ytd_act,
                            item.npat_ytd_mb,
rifkaki's avatar
rifkaki committed
431
                            item.npat_ytd_percent_of_mb,
rifkaki's avatar
rifkaki committed
432
                            item.npat_ytd_last_year,
rifkaki's avatar
rifkaki committed
433
                            item.npat_ytd_percent_of_last_year,
rifkaki's avatar
rifkaki committed
434 435
                            item.npat_fy_ol,
                            item.npat_fy_mb,
rifkaki's avatar
rifkaki committed
436
                            item.npat_fy_percent_of_mb,
rifkaki's avatar
rifkaki committed
437
                            item.npat_fy_last_year,
rifkaki's avatar
rifkaki committed
438
                            item.npat_fy_percent_of_last_year,
rifkaki's avatar
rifkaki committed
439
                            item.order,
rifkaki's avatar
rifkaki committed
440
                            item.is_approved == undefined ? true : item.is_approved,
rifkaki's avatar
rifkaki committed
441 442 443 444 445 446 447 448 449 450
                        ])
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    })
                    console.log(dataTable)
Riri Novita's avatar
Riri Novita committed
451
                    this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
rifkaki's avatar
rifkaki committed
452 453 454 455
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
            })
Riri Novita's avatar
Riri Novita committed
456
        } else if (this.state.report.value === 3) {
Riri Novita's avatar
Riri Novita committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
            api.create().getHierarkiReportCPSM(payload).then(response => {
                console.log(payload);
                console.log(response);
                let dataTable = []
                if (response.data) {
                    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,
Riri Novita's avatar
Riri Novita committed
516
                                item.is_approved == undefined ? true : item.is_approved,
Riri Novita's avatar
Riri Novita committed
517
                                // item.order,
Riri Novita's avatar
Riri Novita committed
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
                            ])
                        }
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    }
                    res.map((item, index) => {
                        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
579
                            item.is_approved == undefined ? true : item.is_approved,
Riri Novita's avatar
Riri Novita committed
580
                            // item.order,
Riri Novita's avatar
Riri Novita committed
581 582 583 584 585 586 587 588 589 590
                        ])
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    })
                    console.log(dataTable);
Riri Novita's avatar
Riri Novita committed
591
                    this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
Riri Novita's avatar
Riri Novita committed
592 593 594 595
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
            })
Riri Novita's avatar
Riri Novita committed
596
        } else if (this.state.report.value === 4) {
rifkaki's avatar
rifkaki committed
597 598 599
            api.create().getHierarkiReportHistorical(newPayload).then(response => {
                console.log(newPayload);
                console.log(response);
Riri Novita's avatar
Riri Novita committed
600
                let dataTable = []
rifkaki's avatar
rifkaki committed
601
                if (response.data) {
rifkaki's avatar
rifkaki committed
602 603
                    let res = [response.data.data]
                    console.log(res)
rifkaki's avatar
rifkaki committed
604 605 606 607
                    const handlePushChild = (item) => {
                        let indexIDzz = dataTable.findIndex((val) => val[0] === item.company_id)
                        if (indexIDzz === -1) {
                            dataTable.push([
rifkaki's avatar
rifkaki committed
608
                                0,
rifkaki's avatar
rifkaki committed
609 610
                                item.parent,
                                item.level,
rifkaki's avatar
rifkaki committed
611 612 613 614 615 616 617 618 619 620 621
                                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,
rifkaki's avatar
rifkaki committed
622 623
                                // item.revenue,
                                0,
rifkaki's avatar
rifkaki committed
624 625 626 627 628 629 630 631 632 633
                                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,
rifkaki's avatar
rifkaki committed
634 635
                                // item.ebitda,
                                0,
rifkaki's avatar
rifkaki committed
636 637 638 639 640 641 642 643 644 645
                                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,
rifkaki's avatar
rifkaki committed
646 647
                                // item.tpat,
                                0,
rifkaki's avatar
rifkaki committed
648 649 650 651 652 653 654 655 656 657
                                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,
rifkaki's avatar
rifkaki committed
658 659
                                // item.npat,
                                0,
rifkaki's avatar
rifkaki committed
660 661 662 663 664 665 666 667 668 669
                                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,
rifkaki's avatar
rifkaki committed
670 671
                                // item.total_asset,
                                0,
rifkaki's avatar
rifkaki committed
672 673 674 675 676 677 678 679 680 681
                                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,
rifkaki's avatar
rifkaki committed
682 683
                                // item.total_equity,
                                0,
rifkaki's avatar
rifkaki committed
684 685 686 687 688 689 690 691 692 693 694 695 696
                                item.order,
                            ])
                        }
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    }
                    res.map((item, index) => {
                        dataTable.push([
rifkaki's avatar
rifkaki committed
697
                            0,
rifkaki's avatar
rifkaki committed
698 699
                            item.parent,
                            item.level,
rifkaki's avatar
rifkaki committed
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
                            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,
                            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,
                            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,
                            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,
                            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,
                            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,
rifkaki's avatar
rifkaki committed
767 768 769 770 771 772 773 774 775 776
                            item.order,
                        ])
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    })
rifkaki's avatar
rifkaki committed
777
                    console.log()
Riri Novita's avatar
Riri Novita committed
778
                    this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
rifkaki's avatar
rifkaki committed
779 780 781
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
rifkaki's avatar
rifkaki committed
782
            })
Riri Novita's avatar
Riri Novita committed
783 784 785 786 787
        }    
    }

    async downloadAllData() {
        if (this.state.report.value === 1) {
d.arizona's avatar
d.arizona committed
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
            // 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;
                a.download = 'Report MTD.xlsx';
                a.click();
            }
Riri Novita's avatar
Riri Novita committed
804
        } else if (this.state.report.value === 2) {
rifkaki's avatar
rifkaki committed
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
            // 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;
                a.download = 'Report YTD.xlsx';
                a.click();
            }
Riri Novita's avatar
Riri Novita committed
821
        } else if (this.state.report.value === 3) {
rifkaki's avatar
rifkaki committed
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
            // 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;
                a.download = 'Report CPSM.xlsx';
                a.click();
            }
Riri Novita's avatar
Riri Novita committed
838
        } else if (this.state.report.value === 4) {
rifkaki's avatar
rifkaki committed
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854
            // 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;
                a.download = 'Report Historical.xlsx';
                a.click();
            }
Riri Novita's avatar
Riri Novita committed
855 856 857 858 859 860 861 862 863
        } else {
            
            // setTimeout(() => {
            //     this.setState({ loading: false })
            // }, 1000);
        }
    }

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

Riri Novita's avatar
Riri Novita committed
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
        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
893 894 895 896 897 898
                                            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
899
                                            // this.getSubmission()
Riri Novita's avatar
Riri Novita committed
900 901 902 903 904 905 906 907 908 909
                                            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()
                                            }
                                            
Riri Novita's avatar
Riri Novita committed
910 911 912 913 914 915 916 917 918 919 920 921
                                        })}
                                        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
922 923
                                            // this.getSubmission()
                                            this.getDataTable()
Riri Novita's avatar
Riri Novita committed
924 925 926 927 928 929 930 931 932 933
                                        })}
                                        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>
Riri Novita's avatar
Riri Novita committed
934 935
                                
                                {(this.state.report != null && !String(this.state.report.label).toLocaleLowerCase().includes('historical')) && <div style={{ marginTop: 15 }}>
rifkaki's avatar
rifkaki committed
936 937 938 939 940 941 942 943 944 945 946 947
                                    <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
948
                                </div>}
Riri Novita's avatar
Riri Novita committed
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
                            </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
964
                                                    onClick={() => this.setState({ loading: true }, () => {
Riri Novita's avatar
Riri Novita committed
965 966 967 968 969 970 971 972 973 974 975 976 977
                                                        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
978 979
                                {this.state.previewTable && (
                                    <TableSummaryTriputra
Riri Novita's avatar
Riri Novita committed
980 981 982
                                        width={this.props.width}
                                        height={this.props.height}
                                        open={this.props.open}
Riri Novita's avatar
Riri Novita committed
983
                                        month={this.state.month}
Riri Novita's avatar
Riri Novita committed
984 985 986 987
                                        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
988
                                )}
Riri Novita's avatar
Riri Novita committed
989 990 991 992 993 994 995 996
                            </div>
                        </Paper>
                    </div>
                </div>
            </div>
        )
    }
}