SummaryOfTriputra.js 42.7 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 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
import { PropagateLoader } from 'react-spinners'
import ReactTooltip from 'react-tooltip'
import Images from '../../assets/Images'

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: [
                { value: 1, label: 'MTD Report' },
                { value: 2, label: 'YTD Report' },
                { value: 3, label: 'CPSM Report' },
Riri Novita's avatar
Riri Novita committed
28 29
                { value: 4, label: 'Historical' },
                { value: 5, label: 'Dashboard Financial' },
Riri Novita's avatar
Riri Novita committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 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
            ],
            report: null,
            loading: false,
            previewTable: false
        }
    }

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

    componentDidMount() {
        this.getDetailUser()
        this.setState({ report: this.state.reportType[0], loading: true })
    }

    getDetailUser() {
        let userId = localStorage.getItem(Constant.USER)
        api.create().getDetailUser(userId).then((response) => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        this.setState({ userCompany: response.data.data.company }, () => {
                            this.getCompanyActive()
                        })
                    }
                }
            }
        })
    }

    getCompanyActive() {
        api.create().getPerusahaanActive().then((response) => {
            // console.log(response);
            if (response.data) {
                if (response.data.status === 'success') {
                    let data = response.data.data
                    let comID = this.state.rawData ? this.state.rawData.company_id : 0
                    let companyData = data.map((item) => {
                        return {
                            company_id: item.company_id,
                            company_name: item.company_name,
                        }
                    })

                    let arrayBaru = []
                    this.state.userCompany.map((item, index) => {
                        let indexID = companyData.findIndex((val) => val.company_id == item)
                        if (indexID !== -1) {
                            arrayBaru.push(companyData[indexID])
                        }
                    })

                    let defaultProps = {
                        options: arrayBaru,
                        getOptionLabel: (option) => titleCase(option.company_name),
                    };
                    let index = arrayBaru.findIndex((val) => val.company_id == comID)
                    this.setState({ listCompany: defaultProps, company: arrayBaru.length < 1 ? companyData[0] : (index == -1 ? arrayBaru[0] : arrayBaru[index]) }, () => {
                        this.getLastPeriod()
                    })
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                        if (response.data.message.includes("Someone Logged In")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listCompany: null, company: null })
            }
        })
    }

    getLastPeriod() {
        api.create().getLastPeriod(this.state.company.company_id).then(response => {
            // console.log(response);
            if (response.data.status === "success") {
                this.setState({ lastPeriod: response.data.data.last_periode, latestPeriode: response.data.data.latest_periode }, () => {
                    this.getPeriode()
                })
            }
        })
    }

    getPeriode() {
        api.create().getPeriodeTransaction().then(response => {
            let currentYear = new Date().getFullYear()
            // console.log(currentYear)
            if (response.data) {
                if (response.data.status === "success") {
                    let data = []
                    response.data.data.map((item) => {
                        if (this.state.isApprover) {
                            if (item >= 2000 && item <= (Number(currentYear) + 1)) {
                                data.push(item)
                            }
                        } else {
                            if ((item >= 2000) && (item == this.state.lastPeriod || item < this.state.lastPeriod)) {
                                data.push(item)
                            }
                        }
                    })
                    let periodeData = data.map((item) => {
                        return {
                            periode: item,
                        }
                    })
                    let defaultProps = {
                        options: periodeData,
                        getOptionLabel: (option) => option.periode,
                    };
                    let periode = (this.state.lastPeriod == "" ? String(Number(currentYear) + 1) : this.state.lastPeriod)
                    let index = data.sort((a, b) => a - b).findIndex((val) => val === periode)
                    // console.log(data)
                    // console.log(this.state.latestPeriode)
                    // console.log(periodeData)
                    // console.log(index)
                    this.setState({ listPeriode: defaultProps, periode: index === -1 ? periodeData[0] : periodeData[index] }, () => {
                        // this.getDataTable()
                        this.getSubmission()
                        // if (this.state.isApprover === true) {
                        //     this.getCompanySubmitted()
                        // } else {
                        //     this.getRevision()
                        // }
                    })
                }
            }
        })
    }

Riri Novita's avatar
Riri Novita committed
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 194 195 196 197 198 199 200
    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
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 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 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 293 294 295 296 297 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 332 333
    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 })
                }
            }
        })
    }

    getDataTable() {
        let payload = {
            "report_id": this.state.report.value,
            "revision": this.state.lastRevision,
            "periode": this.state.periode.periode,
            "company_id": this.state.company.company_id,
            "submission_id": this.state.submissionID
        }
        if (this.state.report.value === 1) {
            api.create().getDetailReportMB(payload).then(response => {
                // console.log(response);
                let dataTable = []
                if (response.data) {
                    let res = response.data.data
                    const handlePushChild = (item) => {
                        let indexIDzz = dataTable.findIndex((val) => val[1] === item.id)
                        if (indexIDzz === -1) {
                            dataTable.push([
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
                                item.profit_loss.total_actual_before === null ? "0" : item.profit_loss.total_actual_before === "" ? "0" : item.profit_loss.total_actual_before,
                                item.profit_loss.january,
                                item.profit_loss.february,
                                item.profit_loss.march,
                                item.profit_loss.april,
                                item.profit_loss.may,
                                item.profit_loss.june,
                                item.profit_loss.july,
                                item.profit_loss.august,
                                item.profit_loss.september,
                                item.profit_loss.october,
                                item.profit_loss.november,
                                item.profit_loss.december,
                                item.profit_loss.total_current_year,
                                item.profit_loss.total_next_year,
                                item.profit_loss.total_more_year,
                                item.order
                            ])
                        }
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    }
                    res.map((item, index) => {
                        dataTable.push([
                            item.type_report_id,
                            item.id,
                            item.parent,
                            item.formula,
                            item.level,
                            item.description,
                            item.profit_loss.total_actual_before === null ? "0" : item.profit_loss.total_actual_before === "" ? "0" : item.profit_loss.total_actual_before,
                            item.profit_loss.january,
                            item.profit_loss.february,
                            item.profit_loss.march,
                            item.profit_loss.april,
                            item.profit_loss.may,
                            item.profit_loss.june,
                            item.profit_loss.july,
                            item.profit_loss.august,
                            item.profit_loss.september,
                            item.profit_loss.october,
                            item.profit_loss.november,
                            item.profit_loss.december,
                            item.profit_loss.total_current_year,
                            item.profit_loss.total_next_year,
                            item.profit_loss.total_more_year,
                            item.order
                        ])
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    })
                    // console.log(dataTable)
                    this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
            })
        } else if (this.state.report.value === 2) {
            api.create().getDetailReportMB(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[1] === item.id)
                        if (indexIDzz === -1) {
                            dataTable.push([
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
                                item.balance_sheet.total_actual_before === null ? "0.0" : item.balance_sheet.total_actual_before === "" ? "0.0" : item.balance_sheet.total_actual_before,
Deni Rinaldi's avatar
Deni Rinaldi committed
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
                                Number(item.balance_sheet.january).toFixed(1),
                                Number(item.balance_sheet.february).toFixed(1),
                                Number(item.balance_sheet.march).toFixed(1),
                                Number(item.balance_sheet.april).toFixed(1),
                                Number(item.balance_sheet.may).toFixed(1),
                                Number(item.balance_sheet.june).toFixed(1),
                                Number(item.balance_sheet.july).toFixed(1),
                                Number(item.balance_sheet.august).toFixed(1),
                                Number(item.balance_sheet.september).toFixed(1),
                                Number(item.balance_sheet.october).toFixed(1),
                                Number(item.balance_sheet.november).toFixed(1),
                                Number(item.balance_sheet.december).toFixed(1),
                                Number(item.balance_sheet.total_current_year).toFixed(1),
                                Number(item.balance_sheet.total_next_year).toFixed(1),
                                Number(item.balance_sheet.total_more_year).toFixed(1),
Riri Novita's avatar
Riri Novita committed
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
                                item.order,
                                item.condition_it_should_be,
                                item.condition_if_wrong
                            ])
                        }
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    }
                    res.map((item, index) => {
                        dataTable.push([
                            item.type_report_id,
                            item.id,
                            item.parent,
                            item.formula,
                            item.level,
                            item.description,
                            item.balance_sheet.total_actual_before === null ? "0.0" : item.balance_sheet.total_actual_before === "" ? "0.0" : item.balance_sheet.total_actual_before,
Deni Rinaldi's avatar
Deni Rinaldi committed
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
                            Number(item.balance_sheet.january).toFixed(1),
                            Number(item.balance_sheet.february).toFixed(1),
                            Number(item.balance_sheet.march).toFixed(1),
                            Number(item.balance_sheet.april).toFixed(1),
                            Number(item.balance_sheet.may).toFixed(1),
                            Number(item.balance_sheet.june).toFixed(1),
                            Number(item.balance_sheet.july).toFixed(1),
                            Number(item.balance_sheet.august).toFixed(1),
                            Number(item.balance_sheet.september).toFixed(1),
                            Number(item.balance_sheet.october).toFixed(1),
                            Number(item.balance_sheet.november).toFixed(1),
                            Number(item.balance_sheet.december).toFixed(1),
                            Number(item.balance_sheet.total_current_year).toFixed(1),
                            Number(item.balance_sheet.total_next_year).toFixed(1),
                            Number(item.balance_sheet.total_more_year).toFixed(1),
Riri Novita's avatar
Riri Novita committed
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 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 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
                            item.order,
                            item.condition_it_should_be,
                            item.condition_if_wrong
                        ])
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    })
                    this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
            })
        } else if (this.state.report.value === 3) {
            api.create().getReportHierarkiPL(payload).then(response => {
                // console.log(response);
                if (response.data) {
                    let dataTable = []
                    console.log(response)
                    let res = response.data.data
                    const handlePushChild = (item) => {
                        dataTable.push([
                            item.type_report_id,
                            item.id,
                            item.parent,
                            item.formula,
                            item.level,
                            item.description,
                            item.profit_detail.total_actual_before === null ? "0" : item.profit_detail.total_actual_before === "" ? "0" : item.profit_detail.total_actual_before,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.january, formula: item.profit_detail.january_formula } : item.profit_detail.january,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.february, formula: item.profit_detail.february_formula } : item.profit_detail.february,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.march, formula: item.profit_detail.march_formula } : item.profit_detail.march,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.april, formula: item.profit_detail.april_formula } : item.profit_detail.april,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.may, formula: item.profit_detail.may_formula } : item.profit_detail.may,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.june, formula: item.profit_detail.june_formula } : item.profit_detail.june,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.july, formula: item.profit_detail.july_formula } : item.profit_detail.july,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.august, formula: item.profit_detail.august_formula } : item.profit_detail.august,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.september, formula: item.profit_detail.september_formula } : item.profit_detail.september,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.october, formula: item.profit_detail.october_formula } : item.profit_detail.october,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.november, formula: item.profit_detail.november_formula } : item.profit_detail.november,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.december, formula: item.profit_detail.december_formula } : item.profit_detail.december,
                            item.profit_detail.total_current_year,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.profit_detail.total_next_year,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.profit_detail.total_more_year,
                            item.order,
                            item.condition_it_should_be,
                            item.condition_if_wrong,
                            item.profit_detail.forecast_formula == null ? [] : item.profit_detail.forecast_formula
                        ])

                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    }
                    res.map((item, index) => {
                        dataTable.push([
                            item.type_report_id,
                            item.id,
                            item.parent,
                            item.formula,
                            item.level,
                            item.description,
                            item.profit_detail.total_actual_before === null ? "0" : item.profit_detail.total_actual_before === "" ? "0" : item.profit_detail.total_actual_before,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.january, formula: item.profit_detail.january_formula } : item.profit_detail.january,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.february, formula: item.profit_detail.february_formula } : item.profit_detail.february,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.march, formula: item.profit_detail.march_formula } : item.profit_detail.march,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.april, formula: item.profit_detail.april_formula } : item.profit_detail.april,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.may, formula: item.profit_detail.may_formula } : item.profit_detail.may,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.june, formula: item.profit_detail.june_formula } : item.profit_detail.june,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.july, formula: item.profit_detail.july_formula } : item.profit_detail.july,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.august, formula: item.profit_detail.august_formula } : item.profit_detail.august,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.september, formula: item.profit_detail.september_formula } : item.profit_detail.september,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.october, formula: item.profit_detail.october_formula } : item.profit_detail.october,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.november, formula: item.profit_detail.november_formula } : item.profit_detail.november,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.december, formula: item.profit_detail.december_formula } : item.profit_detail.december,
                            item.profit_detail.total_current_year,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.profit_detail.total_next_year,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.profit_detail.total_more_year,
                            item.order,
                            item.condition_it_should_be,
                            item.condition_if_wrong,
                            item.profit_detail.forecast_formula == null ? [] : item.profit_detail.forecast_formula
                        ])
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    })
                    this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
            })
        } else if (this.state.report.value === 4) {
            api.create().getReportHierarkiFR(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[1] === item.id)
                        if (indexIDzz === -1) {
                            dataTable.push([
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
                                item.ratio.total_actual_before === null ? "0.0" : item.ratio.total_actual_before === "" ? "0.0" : item.ratio.total_actual_before,
Deni Rinaldi's avatar
Deni Rinaldi committed
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
                                Number(item.ratio.january).toFixed(1),
                                Number(item.ratio.february).toFixed(1),
                                Number(item.ratio.march).toFixed(1),
                                Number(item.ratio.april).toFixed(1),
                                Number(item.ratio.may).toFixed(1),
                                Number(item.ratio.june).toFixed(1),
                                Number(item.ratio.july).toFixed(1),
                                Number(item.ratio.august).toFixed(1),
                                Number(item.ratio.september).toFixed(1),
                                Number(item.ratio.october).toFixed(1),
                                Number(item.ratio.november).toFixed(1),
                                Number(item.ratio.december).toFixed(1),
                                Number(item.ratio.total_current_year).toFixed(1),
                                Number(item.ratio.total_next_year).toFixed(1),
                                Number(item.ratio.total_more_year).toFixed(1),
Riri Novita's avatar
Riri Novita committed
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
                                item.order,
                                item.condition_it_should_be,
                                item.condition_if_wrong
                            ])
                        }
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    }
                    res.map((item, index) => {
                        dataTable.push([
                            item.type_report_id,
                            item.id,
                            item.parent,
                            item.formula,
                            item.level,
                            item.description,
                            item.ratio.total_actual_before === null ? "0.0" : item.ratio.total_actual_before === "" ? "0.0" : item.ratio.total_actual_before,
Deni Rinaldi's avatar
Deni Rinaldi committed
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
                            Number(item.ratio.january).toFixed(1),
                            Number(item.ratio.february).toFixed(1),
                            Number(item.ratio.march).toFixed(1),
                            Number(item.ratio.april).toFixed(1),
                            Number(item.ratio.may).toFixed(1),
                            Number(item.ratio.june).toFixed(1),
                            Number(item.ratio.july).toFixed(1),
                            Number(item.ratio.august).toFixed(1),
                            Number(item.ratio.september).toFixed(1),
                            Number(item.ratio.october).toFixed(1),
                            Number(item.ratio.november).toFixed(1),
                            Number(item.ratio.december).toFixed(1),
                            Number(item.ratio.total_current_year).toFixed(1),
                            Number(item.ratio.total_next_year).toFixed(1),
                            Number(item.ratio.total_more_year).toFixed(1),
Riri Novita's avatar
Riri Novita committed
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
                            item.order,
                            item.condition_it_should_be,
                            item.condition_if_wrong
                        ])
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    })
                    this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
                } else {
                    this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
                }
            })
        }    
    }

    async downloadAllData() {
        if (this.state.report.value === 1) {
            alert("Download MTD Report Coming Soon")
            // let res = await fetch(
faisalhamdi's avatar
faisalhamdi committed
584
            //     `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/db_report/export_master_budget?submission_id=${this.state.submissionID === null ? "" : this.state.submissionID}&&report_id=${this.state.report.value}&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.lastRevision}`
Riri Novita's avatar
Riri Novita committed
585 586 587 588 589 590 591 592 593 594 595 596
            // )
            // res = await res.blob()
            // this.setState({ loading: false })
            // if (res.size > 0) {
            //     let url = window.URL.createObjectURL(res);
            //     let a = document.createElement('a');
            //     a.href = url;
            //     a.download = 'Report DB Profit & Loss Detail.xlsx';
            //     a.click();
            // }
        } else if (this.state.report.value === 2) {
            alert("Download YTD Report Coming Soon")
faisalhamdi's avatar
faisalhamdi committed
597 598
            // let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/db_report/export_master_budget?submission_id=${this.state.submissionID}&&report_id=${this.state.report.value}&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.lastRevision}`
            // let sub_null = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/db_report/export_master_budget?submission_id=&&report_id=${this.state.report.value}&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.lastRevision}`
Riri Novita's avatar
Riri Novita committed
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
            // // 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 DB Balance Sheet.xlsx';
            //     a.click();
            // }
        } else if (this.state.report.value === 3) {
            alert("Download CPSM Report Coming Soon")
            // let res = await fetch(
faisalhamdi's avatar
faisalhamdi committed
615
            //     `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/db_report_detail/export_master_budget?submission_id=${this.state.submissionID === null ? "" : this.state.submissionID}&&report_id=${this.state.report.value}&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.lastRevision}`
Riri Novita's avatar
Riri Novita committed
616 617 618 619 620 621 622 623 624 625 626 627 628
            // )
            // res = await res.blob()
            // this.setState({ loading: false })
            // if (res.size > 0) {
            //     let url = window.URL.createObjectURL(res);
            //     let a = document.createElement('a');
            //     a.href = url;
            //     a.download = 'Report DB Profit & Loss.xlsx';
            //     a.click();
            // }
        } else if (this.state.report.value === 4) {
            alert("Download Historical Report Coming Soon")
            // let res = await fetch(
faisalhamdi's avatar
faisalhamdi committed
629
            //     `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/db_report_detail/export_master_budget?submission_id=${this.state.submissionID === null ? "" : this.state.submissionID}&&report_id=${this.state.report.value}&&company_id=${this.state.company.company_id}&&year=${this.state.periode.periode}&&revision=${this.state.lastRevision}`
Riri Novita's avatar
Riri Novita committed
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
            // )
            // res = await res.blob()
            // this.setState({ loading: false })
            // if (res.size > 0) {
            //     let url = window.URL.createObjectURL(res);
            //     let a = document.createElement('a');
            //     a.href = url;
            //     a.download = 'Report DB Financial Ratio.xlsx';
            //     a.click();
            // }
        } else {
            
            // setTimeout(() => {
            //     this.setState({ loading: false })
            // }, 1000);
        }
    }

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

Riri Novita's avatar
Riri Novita committed
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
        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 }, () => {
                                            this.getSubmission()
                                        })}
                                        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 }, () => {
                                            this.getSubmission()
                                        })}
                                        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>
                            </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'
                                                    }}
                                                    onClick={() => this.setState({ loading: false }, () => {
                                                        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
731 732
                                {this.state.previewTable && (
                                    <TableSummaryTriputra
Riri Novita's avatar
Riri Novita committed
733 734 735 736 737 738 739
                                        width={this.props.width}
                                        height={this.props.height}
                                        open={this.props.open}
                                        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
740
                                )}
Riri Novita's avatar
Riri Novita committed
741 742 743 744 745 746 747 748
                            </div>
                        </Paper>
                    </div>
                </div>
            </div>
        )
    }
}