OutlookPA.js 151 KB
Newer Older
EKSAD's avatar
EKSAD committed
1 2 3
import React, { Component } from 'react';
import { Typography, Paper, TextField, MenuItem, Select, FormControlLabel, Snackbar, withStyles, createMuiTheme, MuiThemeProvider, Checkbox, Input } from '@material-ui/core';
import MUIDataTable from 'mui-datatables';
syadziy's avatar
syadziy committed
4 5
import Images from '../../assets/Images';
import api from '../../api';
EKSAD's avatar
EKSAD committed
6 7
import Autocomplete from '@material-ui/lab/Autocomplete';
import MuiAlert from '@material-ui/lab/Alert';
syadziy's avatar
syadziy committed
8 9 10 11
import { titleCase } from '../../library/Utils';
import ProfitLossOLPA from './ProfitLossOLPA';
import TaxPlanning from './TaxPlanningOLPA';
import CashFlow from './CashFlowOLPA';
EKSAD's avatar
EKSAD committed
12
import { ExcelRenderer } from 'react-excel-renderer';
syadziy's avatar
syadziy committed
13 14
import UploadFile from "../../library/Upload";
import Constant from '../../library/Constant';
EKSAD's avatar
EKSAD committed
15 16
import PropagateLoader from "react-spinners/PropagateLoader"
import { DatePicker } from '@material-ui/pickers';
syadziy's avatar
syadziy committed
17
import BalanceSheetOLPA from './BalanceSheetOLPA';
EKSAD's avatar
EKSAD committed
18
import moment from 'moment';
syadziy's avatar
syadziy committed
19
import CorporateAnnualTargetOLPA from './CorporateAnnualTargetOLPA';
d.arizona's avatar
d.arizona committed
20
import * as R from 'ramda'
qorri_di's avatar
qorri_di committed
21 22
import { PhotoSizeSelectLargeTwoTone, ThreeSixty } from '@material-ui/icons';
import { startTransition } from 'react';
EKSAD's avatar
EKSAD committed
23

syadziy's avatar
syadziy committed
24
var ct = require("../../library/CustomTable");
EKSAD's avatar
EKSAD committed
25 26 27 28 29
const getMuiTheme = () => createMuiTheme(ct.customTable());

const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);

qorri_di's avatar
qorri_di committed
30 31 32 33 34 35 36 37 38 39
const CustomCheckbox = withStyles({
    root: {
        color: '#5198ea',
        '&$checked': {
            color: '#5198ea',
        },
    },
    checked: {},
})((props) => <Checkbox color="default" {...props} />);

EKSAD's avatar
EKSAD committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
export default class OutlookPA extends Component {
    constructor(props) {
        super(props)
        this.state = {
            perusahaan: 'TAP Group',
            listRevision: null,
            revision: null,
            visibleOutlookPA: true,
            listPeriode: null,
            periode: null,
            listCompany: null,
            company: null,
            report_id: null,
            visibleBS: false,
            visiblePL: false,
d.arizona's avatar
d.arizona committed
55
            visibleCF: false,
faisalhamdi's avatar
faisalhamdi committed
56
            visibleCAT: false,
EKSAD's avatar
EKSAD committed
57 58 59 60 61 62
            listAttachment: [],
            visibleUpload: false,
            revisionTable: null,
            alert: false,
            tipeAlert: '',
            messageAlert: '',
Deni Rinaldi's avatar
Deni Rinaldi committed
63
            outlook_pa_id: null,
EKSAD's avatar
EKSAD committed
64 65 66 67 68 69 70 71 72 73 74 75
            isSubmit: false,
            visibleTableHistory: false,
            isApprover: false,
            lastStatus: "",
            intent: "",
            approverID: null,
            pic: '',
            submitter: false,
            detailRevisiCheck: [],
            lastRevision: "",
            checkApprover: false,
            lastPeriod: '',
Deni Rinaldi's avatar
Deni Rinaldi committed
76
            latestPeriode: '',
EKSAD's avatar
EKSAD committed
77 78
            minDateRevision: new Date(),
            maxDateRevision: new Date(),
d.arizona's avatar
d.arizona committed
79 80 81
            btnApprove: false,
            listStatus: [],
            selectedStatus: [],
d.arizona's avatar
d.arizona committed
82
            prevRevision: false,
83 84
            dbPL: [],
            listApprover: null,
d.arizona's avatar
d.arizona committed
85
            approver: null,
qorri_di's avatar
qorri_di committed
86 87 88 89 90
            isAdmin: false,
            selectReport: [],
            isCheckAll: false,
            downloadedFileReportId: null,
            arrayReport: [],
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
            popupDownload: false,
            defaultCurrency: null,
            dataCurrency: [],
            currency: [],
            visibleAlertSave: false,
            dataCurrency: [
                {
                    "id": 1,
                    "value": "IDR"
                },
                {
                    "id": 2,
                    "value": "USD",
                }
            ]
EKSAD's avatar
EKSAD committed
106
        }
EKSAD's avatar
EKSAD committed
107
        this.myRef = React.createRef()
EKSAD's avatar
EKSAD committed
108 109 110
        this.fileHandler = this.fileHandler.bind(this);
    }

EKSAD's avatar
EKSAD committed
111 112
    scrollToMyRef = () => window.scrollTo(0, this.myRef.current.offsetTop)

EKSAD's avatar
EKSAD committed
113 114 115 116
    componentDidMount() {
        this.setState({ loading: true })
        this.props.selectIndex('Outlook Performance Appraisal')
        if (this.props.location.state !== undefined) {
r.kurnia's avatar
r.kurnia committed
117 118
            console.log(this.props);
            this.setState({ userType: this.props.location.state.userType, intent: 'Home', lastPeriodProps: this.props.location.state.rawData.periode, rawData: this.props.location.state.rawData }, () => {
EKSAD's avatar
EKSAD committed
119 120 121 122 123 124 125 126
                this.checkApprover()
            })
        } else {
            this.checkApprover()
        }
    }

    checkApprover() {
d.arizona's avatar
d.arizona committed
127 128 129 130 131 132 133 134 135 136 137 138
        let listStatus1 = [
            { name: 'Open', value: 'not-yet' },
            { name: 'Submitted', value: 'approval_review' },
            { name: 'Waiting for Review / Approval', value: 'approval_proccess' },
            { name: 'Approved', value: 'approved' },
        ]

        let listStatus2 = [
            { name: 'Open', value: 'not-yet' },
            { name: 'Submitted', value: 'approval_review' },
            { name: 'Approved', value: 'approved' },
        ]
Deni Rinaldi's avatar
Deni Rinaldi committed
139
        api.create().checkApproverOLPA().then(response => {
qorri_di's avatar
qorri_di committed
140 141 142 143 144 145 146 147
            if (response.data.status === 'success') {
                if (response.data.data.is_approver === true) {
                    this.setState({ isApprover: true, checkApprover: true, listStatus: listStatus1, selectedStatus: listStatus1 }, () =>
                        this.getPeriode())
                } else {
                    this.setState({ isApprover: false, checkApprover: false, listStatus: listStatus2, selectedStatus: listStatus2 }, () =>
                        this.getPeriode())
                }
EKSAD's avatar
EKSAD committed
148
            } else {
qorri_di's avatar
qorri_di committed
149 150 151 152 153 154 155 156
                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                        setTimeout(() => {
                            localStorage.removeItem(Constant.TOKEN)
                            window.location.reload();
                        }, 1000);
                    }
                })
EKSAD's avatar
EKSAD committed
157 158 159 160
            }
        })
    }

161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
    getCurrency(companyID) {
        // console.log(companyID);
        api.create().getDetailPerusahaan(companyID).then(response => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === "success") {
                        let data = response.data.data
                        let datas = []
                        if (response.data.data.currency.length > 0) {
                            response.data.data.currency.map((item) => {
                                // console.log(item);
                                datas.push({
                                    id: item.currencyId,
                                    value: item.currencyName
                                })

                            })
                        }
                        let index = datas.findIndex((val) => val.id == response.data.data.default_currency)
                        this.setState({
                            defaultCurrencyID: response.data.data.default_currency,
                            currency: datas,
                            defaultCurrency: index == -1 ? null : datas[index]
                        })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
            }

        })
    }

EKSAD's avatar
EKSAD committed
205
    getCompanySubmitted() {
d.arizona's avatar
d.arizona committed
206 207 208
        let selectedStatus = this.state.selectedStatus.map((item) => {
            return item.value
        })
EKSAD's avatar
EKSAD committed
209
        let body = {
d.arizona's avatar
d.arizona committed
210 211
            "periode": this.state.periode.periode,
            "status": selectedStatus
EKSAD's avatar
EKSAD committed
212
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
213
        api.create().getCompanySubmittedOLPA(body).then(response => {
d.arizona's avatar
d.arizona committed
214
            console.log(response);
EKSAD's avatar
EKSAD committed
215 216
            if (response.data) {
                if (response.data.status === 'success') {
d.arizona's avatar
d.arizona committed
217 218 219 220 221 222 223 224
                    if (response.data.data.length > 0) {
                        let data = response.data.data
                        let companyData = data.map((item) => {
                            return {
                                company_id: item.company_id,
                                company_name: item.company_name,
                            }
                        })
EKSAD's avatar
EKSAD committed
225

226 227 228 229 230 231 232
                        let arrayBaru = []
                        this.state.userCompany.map((item, index) => {
                            let indexID = companyData.findIndex((val) => val.company_id == item)
                            if (indexID !== -1) {
                                arrayBaru.push(companyData[indexID])
                            }
                        })
d.arizona's avatar
d.arizona committed
233

234 235 236
                        if (arrayBaru.length > 0) {
                            arrayBaru = arrayBaru.sort((a, b) => a.company_name.localeCompare(b.company_name))
                        }
d.arizona's avatar
d.arizona committed
237
                        let defaultProps = {
238
                            options: arrayBaru,
d.arizona's avatar
d.arizona committed
239
                            getOptionLabel: (option) => titleCase(option.company_name),
240
                        }
d.arizona's avatar
d.arizona committed
241 242
                        let indexID = null
                        if (this.state.rawData !== undefined) {
243
                            indexID = arrayBaru.findIndex((val) => val.company_id == this.state.rawData.company_id)
EKSAD's avatar
EKSAD committed
244
                        }
245 246 247 248 249 250 251 252 253 254 255 256 257 258

                        // if (companyData.length > 0) {
                        //     companyData = companyData.sort((a, b) => a.company_name.localeCompare(b.company_name))
                        // }

                        // let defaultProps = {
                        //     options: companyData,
                        //     getOptionLabel: (option) => titleCase(option.company_name),
                        // };
                        // let indexID = null
                        // if (this.state.rawData !== undefined) {
                        //     indexID = companyData.findIndex((val) => val.company_id == this.state.rawData.company_id)
                        // }
                        this.setState({ listCompany: defaultProps, company: indexID == null ? arrayBaru[0] : arrayBaru[indexID] }, () => {
d.arizona's avatar
d.arizona committed
259 260 261
                            console.log(response.data.data);
                            if (response.data.data.length > 0) {
                                this.getRevision()
262
                                this.getCurrency(this.state.company.company_id)
d.arizona's avatar
d.arizona committed
263 264 265
                            } else {
                                this.setState({ listRevision: null, revision: null, dataTable: [], checkApprover: false, lastRevision: "", visibleTableHistory: false, loading: false })
                            }
qorri_di's avatar
qorri_di committed
266
                            // 
d.arizona's avatar
d.arizona committed
267 268 269 270 271 272
                        })
                    } else {
                        this.setState({ listRevision: null, revision: null, listCompany: null, company: null, dataTable: [], lastRevision: "", visibleTableHistory: false, loading: false }, () => {
                            document.body.style.overflow = 'unset';
                        })
                    }
EKSAD's avatar
EKSAD committed
273 274
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
275
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
EKSAD's avatar
EKSAD committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listCompany: null, company: null })
            }
        })
    }

    getReportAttachment() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
            "revision": this.state.revision.revision,
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
295
        api.create().getOLPAAtt(payload).then(response => {
EKSAD's avatar
EKSAD committed
296
            // console.log(response)
EKSAD's avatar
EKSAD committed
297 298 299 300
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({ listAttachment: response.data.data })
                }
Riri Novita's avatar
Riri Novita committed
301 302
            } else {
                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
303
                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
304 305 306 307 308 309
                        setTimeout(() => {
                            localStorage.removeItem(Constant.TOKEN)
                            window.location.reload();
                        }, 1000);
                    }
                })
EKSAD's avatar
EKSAD committed
310
            }
EKSAD's avatar
EKSAD committed
311
            // console.log(response);
EKSAD's avatar
EKSAD committed
312 313 314 315 316 317 318
        })
    }

    getReport() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
319
            "currency_id": this.state.defaultCurrency.id,
EKSAD's avatar
EKSAD committed
320 321
            "report_type": "Outlook PA",
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
322
        api.create().getReportOLPA(payload).then(response => {
faisalhamdi's avatar
faisalhamdi committed
323
            console.log(response);
EKSAD's avatar
EKSAD committed
324 325 326 327 328 329 330 331 332
            if (response.data) {
                if (response.data.status === "success") {
                    let dataTable = response.data.data.map((item, index) => {
                        return [
                            item.number,
                            item.report_name,
                            item.revision,
                            this.state.isSubmit === false ? "CLOSED" : item.current_status,
                            item.report_id,
d.arizona's avatar
d.arizona committed
333 334
                            // Number(item.revision) > 0 ? (item.current_status == "not-yet" ? false : item.is_can_upload) : item.is_can_upload,
                            item.report_name === "Cash Flow" ? item.is_can_upload : (Number(item.revision) > 0 ? (item.current_status == "not-yet" ? false : item.is_can_upload) : item.is_can_upload),
EKSAD's avatar
EKSAD committed
335 336 337
                            item.revision
                        ]
                    })
r.kurnia's avatar
r.kurnia committed
338 339 340
                    // dataTable.push([
                    //     5, "Corporate Annual Target", 0, "not-yet", 39, false, 0
                    // ])
341 342 343 344 345 346 347 348 349 350
                    let dataTableRevision = []
                    response.data.data.map((item, index) => {
                        if (item.report_name !== 'Cash Flow') {
                            dataTableRevision.push([
                                item.report_id,
                                item.report_name === 'CAT' ? 'Corporate Annual Target' : item.report_name,
                                "",
                                item.number
                            ])
                        }
EKSAD's avatar
EKSAD committed
351
                    })
352 353
                    // console.log(dataTable);
                    this.setState({ dataTable, loading: false, dataTableRevision: dataTableRevision.sort((a, b) => a.number - b.number), dataForRevision: response.data.data })
Riri Novita's avatar
Riri Novita committed
354 355
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
356
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
357 358 359 360 361 362
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
EKSAD's avatar
EKSAD committed
363 364 365 366 367 368 369 370 371 372 373 374
                }
            } else {
                this.setState({ loading: false })
            }
        })
    }

    getLatestPeriodSubmit() {
        let body = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
375
        api.create().getSubmitOLPA(body).then(response => {
EKSAD's avatar
EKSAD committed
376
            // console.log(response);
EKSAD's avatar
EKSAD committed
377 378 379 380 381 382 383 384 385 386 387 388 389 390
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({ isSubmit: response.data.data.is_can_submit }, () => {
                        this.getReport()
                        this.getReportAttachment()
                    })
                }
            }
        })
    }

    getDetailUser() {
        let userId = localStorage.getItem(Constant.USER)
        api.create().getDetailUser(userId).then((response) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
391
            // console.log(response);
EKSAD's avatar
EKSAD committed
392 393 394
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
d.arizona's avatar
d.arizona committed
395
                        this.getRole(response.data.data.role_id)
EKSAD's avatar
EKSAD committed
396
                        this.setState({ userCompany: response.data.data.company }, () => {
d.arizona's avatar
d.arizona committed
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
                            this.getCompanySubmitted()
                        })
                    }
                }
            }
        })
    }

    getRole(id) {
        api.create().getDetailRole(id).then((response) => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        // this.setState({ tempData: response.data.data, privileges: response.data.data.privileges })
                        // // // console.log(response.data.data)
                        if (String(response.data.data.role_name).toLocaleLowerCase() == 'superadmin') {
                            this.setState({ isAdmin: true })
                        }
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
417
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
418 419 420 421 422
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
EKSAD's avatar
EKSAD committed
423 424
                        })
                    }
d.arizona's avatar
d.arizona committed
425 426
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
EKSAD's avatar
EKSAD committed
427
                }
d.arizona's avatar
d.arizona committed
428 429
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
EKSAD's avatar
EKSAD committed
430 431 432 433 434 435
            }
        })
    }

    getCompanyActive() {
        api.create().getPerusahaanActive().then((response) => {
d.arizona's avatar
d.arizona committed
436
            console.log(response);
EKSAD's avatar
EKSAD committed
437 438 439 440 441 442 443 444 445 446 447
            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,
                        }
                    })

d.arizona's avatar
d.arizona committed
448
                    if (companyData.length > 0) {
d.arizona's avatar
d.arizona committed
449
                        companyData = companyData.sort((a, b) => a.company_name.localeCompare(b.company_name))
d.arizona's avatar
d.arizona committed
450 451
                    }

EKSAD's avatar
EKSAD committed
452 453 454 455 456 457 458 459
                    let arrayBaru = []
                    this.state.userCompany.map((item, index) => {
                        let indexID = companyData.findIndex((val) => val.company_id == item)
                        if (indexID !== -1) {
                            arrayBaru.push(companyData[indexID])
                        }
                    })

d.arizona's avatar
d.arizona committed
460
                    if (arrayBaru.length > 0) {
d.arizona's avatar
d.arizona committed
461
                        arrayBaru = arrayBaru.sort((a, b) => a.company_name.localeCompare(b.company_name))
d.arizona's avatar
d.arizona committed
462 463 464 465
                    }

                    console.log(companyData)
                    console.log(arrayBaru)
d.arizona's avatar
d.arizona committed
466

EKSAD's avatar
EKSAD committed
467 468 469 470 471 472 473 474 475 476
                    let defaultProps = {
                        options: arrayBaru,
                        getOptionLabel: (option) => titleCase(option.company_name),
                    };
                    let index = arrayBaru.findIndex((val) => val.company_id == comID)
                    this.setState({ listCompany: defaultProps, company: arrayBaru.length < 1 ? companyData[0] : (index == -1 ? arrayBaru[0] : arrayBaru[index]) }, () => {
                        this.getLastPeriod()
                    })
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
477
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
EKSAD's avatar
EKSAD committed
478 479 480 481 482 483 484 485 486 487 488 489 490 491
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listCompany: null, company: null })
            }
        })
    }

    getLastPeriod() {
Deni Rinaldi's avatar
Deni Rinaldi committed
492
        api.create().getLastPeriodOLPA(this.state.company.company_id).then(response => {
EKSAD's avatar
EKSAD committed
493
            // console.log(response);
d.arizona's avatar
d.arizona committed
494
            let currentYear = new Date().getFullYear()
EKSAD's avatar
EKSAD committed
495
            if (response.data.status === "success") {
d.arizona's avatar
d.arizona committed
496
                this.setState({ lastPeriod: Number(response.data.data.last_periode) < Number(currentYear) ? String(currentYear) : response.data.data.last_periode, latestPeriode: response.data.data.latest_periode }, () => {
EKSAD's avatar
EKSAD committed
497 498 499 500 501 502 503 504 505 506 507
                    this.getPeriode()
                })
            }
        })
    }

    getPeriode() {
        api.create().getPeriodeTransaction().then(response => {
            // let dateNow = new Date
            // let year = this.state.rawData ? this.state.rawData.periode : format(dateNow, 'yyyy')
            let currentYear = new Date().getFullYear()
EKSAD's avatar
EKSAD committed
508
            // console.log(currentYear)
EKSAD's avatar
EKSAD committed
509 510 511 512 513
            if (response.data) {
                if (response.data.status === "success") {
                    let data = []
                    response.data.data.map((item) => {
                        if (this.state.isApprover) {
d.arizona's avatar
d.arizona committed
514
                            if (item >= 2000 && item <= (Number(currentYear))) {
EKSAD's avatar
EKSAD committed
515 516 517
                                data.push(item)
                            }
                        } else {
d.arizona's avatar
d.arizona committed
518
                            if ((item >= 2000) && (item == currentYear || item <= currentYear)) {
EKSAD's avatar
EKSAD committed
519 520 521 522 523 524 525 526 527 528 529 530 531
                                data.push(item)
                            }
                        }
                    })
                    let periodeData = data.map((item) => {
                        return {
                            periode: item,
                        }
                    })
                    let defaultProps = {
                        options: periodeData,
                        getOptionLabel: (option) => option.periode,
                    };
syadziy's avatar
syadziy committed
532
                    let periode = (this.state.lastPeriodProps == undefined ? (this.state.lastPeriod == "" ? String(Number(currentYear)) : Number(this.state.lastPeriod)) : this.state.lastPeriodProps)
d.arizona's avatar
d.arizona committed
533
                    let index = data.sort((a, b) => a - b).findIndex((val) => val == periode)
EKSAD's avatar
EKSAD committed
534
                    // console.log(data)
EKSAD's avatar
EKSAD committed
535
                    // console.log(this.state.lastPeriod)
d.arizona's avatar
d.arizona committed
536
                    // console.log(periode)
EKSAD's avatar
EKSAD committed
537
                    // console.log(index)
EKSAD's avatar
EKSAD committed
538
                    this.setState({ listPeriode: defaultProps, periode: index === -1 ? periodeData[0] : periodeData[index] }, () => {
d.arizona's avatar
d.arizona committed
539 540 541 542 543 544
                        // if (this.state.isApprover === true) {
                        //     this.getCompanySubmitted()
                        // } else {
                        //     this.getRevision()
                        // }
                        this.getDetailUser()
545
                        // this.getCurrency(this.state.company.company_id)
EKSAD's avatar
EKSAD committed
546 547 548 549 550 551 552
                    })
                }
            }
        })
    }

    getRevision() {
qorri_di's avatar
qorri_di committed
553 554 555 556
        this.setState({ selectReport: [], isCheckAll: false }, () => {
            let payload = {
                "company_id": this.state.company.company_id,
                "periode": this.state.periode.periode
557
            }
qorri_di's avatar
qorri_di committed
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
            api.create().getRevision(payload).then(response => {
                // console.log(response);
                if (response.data) {
                    if (response.data.status === "success") {
                        let data = response.data.data
                        let revisionData = data.map((item) => {
                            return {
                                revision: item,
                            }
                        })
                        let defaultProps = {
                            options: revisionData,
                            getOptionLabel: (option) => option.revision,
                        };
                        this.setState({ listRevision: defaultProps, revision: revisionData[0] }, () => {
                            this.getOutlookPAID()
                        })
                    }
                }
            })
EKSAD's avatar
EKSAD committed
578 579 580
        })
    }

Riri Novita's avatar
Riri Novita committed
581
    getOutlookPAID(type) {
EKSAD's avatar
EKSAD committed
582 583 584 585
        this.setState({ loading: true })
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
Faisal Hamdi's avatar
Faisal Hamdi committed
586
            "is_approver": this.state.isAdmin && this.state.lastStatus == 'WAITING FOR APPROVAL' ? false : this.state.isApprover
EKSAD's avatar
EKSAD committed
587
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
588
        api.create().getOutlookPAID(payload).then(response => {
d.arizona's avatar
d.arizona committed
589
            console.log(response)
EKSAD's avatar
EKSAD committed
590 591 592
            if (response) {
                if (response.data.status === "success") {
                    this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
593
                        outlook_pa_id: response.data.data.outlook_pa_id,
EKSAD's avatar
EKSAD committed
594 595 596 597
                        submitter: response.data.data.submitter,
                        approverID: response.data.data.approve_id, pic: response.data.data.approver == null ? '' : response.data.data.approver,
                        lastStatus: response.data.data.last_status === null ? 'SUBMIT' : response.data.data.last_status,
                        lastRevision: response.data.data.last_revision,
Deni Rinaldi's avatar
Deni Rinaldi committed
598
                        btnApprove: response.data.data.is_submit
EKSAD's avatar
EKSAD committed
599
                    }, () => {
EKSAD's avatar
EKSAD committed
600
                        // console.log(this.state.lastStatus);
601 602
                        if (this.state.isAdmin) {
                            console.log('masuk')
Faisal Hamdi's avatar
Faisal Hamdi committed
603
                            api.create().getListApprover('outlook_pa', this.state.outlook_pa_id).then((response) => {
604 605 606
                                console.log(response)
                                if (response.data.data) {
                                    let dataListApprover = []
Faisal Hamdi's avatar
Faisal Hamdi committed
607 608
                                    response.data.data.map((item, index) => {
                                        dataListApprover.push({ userId: item.user_id, fullname: item.fullname })
609 610 611 612 613
                                    })
                                    let defaultProps = {
                                        options: dataListApprover,
                                        getOptionLabel: (option) => option.fullname,
                                    };
Faisal Hamdi's avatar
Faisal Hamdi committed
614
                                    this.setState({ listApprover: defaultProps })
615 616 617
                                }
                            })
                        }
EKSAD's avatar
EKSAD committed
618 619
                        this.historyApproval()
                        this.getLatestPeriodSubmit()
d.arizona's avatar
d.arizona committed
620 621
                        if (type != undefined && type == 'PL') {
                            // this.getCashFlow(type)
Riri Novita's avatar
Riri Novita committed
622
                            this.getPL(type)
Faisal Hamdi's avatar
Faisal Hamdi committed
623 624 625 626 627
                        } else if (type != undefined && type == 'BS') {
                            let bodyRatioOLPA = {
                                "report": 'ratio',
                                "outlookPaId": this.state.outlook_pa_id,
                                "companyId": this.state.company.company_id,
Riri Novita's avatar
Riri Novita committed
628 629
                                "periode": this.state.periode.periode,
                                "currency_id": this.state.defaultCurrency.id,
Faisal Hamdi's avatar
Faisal Hamdi committed
630 631 632 633 634
                            }
                            api.create().triggerRatioOLPA(bodyRatioOLPA).then((res) => {
                                console.log(res)
                                this.setState({ loading: false })
                            })
d.arizona's avatar
d.arizona committed
635 636 637
                        } else {
                            this.setState({ loading: false })
                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
638
                        api.create().checkApproverOLPA().then(response => {
EKSAD's avatar
EKSAD committed
639
                            // console.log(response);
EKSAD's avatar
EKSAD committed
640 641 642
                            if (response.data.data.is_approver === true) {
                                this.setState({ isApprover: true, checkApprover: true })
                            } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
643
                                this.setState({ isApprover: false, checkApprover: false })
EKSAD's avatar
EKSAD committed
644 645 646 647 648
                            }

                        })
                    })
                } else {
Riri Novita's avatar
Riri Novita committed
649
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
650
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
651 652 653 654 655 656
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
d.arizona's avatar
d.arizona committed
657
                }
Riri Novita's avatar
Riri Novita committed
658 659
            } else {
                this.setState({ outlook_pa_id: null, loading: false })
EKSAD's avatar
EKSAD committed
660 661 662 663 664 665 666 667 668
            }
        })
    }

    historyApproval() {
        let body = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
669
        api.create().historyApprovalOLPA(body).then(response => {
EKSAD's avatar
EKSAD committed
670
            // console.log(response);
EKSAD's avatar
EKSAD committed
671 672 673 674
            if (response.data.data.length > 0) {
                let dataTableHistory = response.data.data.map(item => {
                    return [
                        item.pic,
EKSAD's avatar
EKSAD committed
675 676
                        item.status_approval,
                        // String(item.status_approval).replace('APPROVAL_PROCCESS', 'WAITING FOR APPROVAL').replace('- -', ''),
EKSAD's avatar
EKSAD committed
677 678 679 680 681 682 683 684 685 686
                        item.remarks,
                        item.item_revision,
                        item.history_approval_date
                    ]
                })
                this.setState({ dataTableHistory, visibleTableHistory: true })
            }
        })
    }

d.arizona's avatar
d.arizona committed
687
    async setHeaderTokenSuperadmin(type) {
688
        let realToken = await localStorage.getItem(Constant.TOKEN)
d.arizona's avatar
d.arizona committed
689 690 691 692 693 694 695 696 697
        api.create().getIdToken(this.state.approver.userId).then((response) => {
            console.log(response.data.data.token)
            localStorage.setItem(Constant.TOKEN, response.data.data.token)
            this.approvalSubmission(type, realToken)
        })
    }

    approvalSubmission(type, realToken) {
        this.scrollToMyRef()
Faisal Hamdi's avatar
Faisal Hamdi committed
698
        // if (this.state.isAdmin && type == 'approve') {
d.arizona's avatar
d.arizona committed
699 700 701 702 703 704
        //     api.create().getIdToken(this.state.approver.userId).then((response) => {
        //         // console.log(realToken)
        //         // console.log(response.data.data.token)
        //         localStorage.setItem(Constant.TOKEN, response.data.data.token)
        //     })
        // }
EKSAD's avatar
EKSAD committed
705 706 707 708
        this.setState({ loading: true })
        let body = {
            "approval_id": this.props.location.state == undefined ? this.state.approverID : this.state.rawData.approval_id,
            "status": type,
d.arizona's avatar
d.arizona committed
709
            "detail": this.state.detailRevisiCheck,
710 711
            "is_superadmin": this.state.isAdmin,
            "currency_id": this.state.defaultCurrency.id,
EKSAD's avatar
EKSAD committed
712
        }
EKSAD's avatar
EKSAD committed
713 714
        let payload = {
            "company_id": this.state.company.company_id,
syadziy's avatar
syadziy committed
715
            "periode": this.state.periode.periode,
EKSAD's avatar
EKSAD committed
716
            "min_periode": moment(this.state.minDateRevision).format('YYYY-MM-DD'),
Riri Novita's avatar
Riri Novita committed
717 718
            "max_periode": moment(this.state.maxDateRevision).format('YYYY-MM-DD'),
            "currency_id": this.state.defaultCurrency.id,
EKSAD's avatar
EKSAD committed
719
        }
EKSAD's avatar
EKSAD committed
720
        // console.log(payload)
721 722 723 724 725 726 727 728 729 730 731 732 733 734
        // api.create().approvalSubmissionOLPA(body).then((res) => {
        //     console.log(res)
        //     // this.setState({ loading: false }, () => {
        //         this.getOutlookPAID()
        //     // })
        //     if (type == 'revision') {
        //         api.create().createPeriodeRevisionOLPA(payload).then((res) => console.log(res))
        //     }
        // })
        setTimeout(() => {
            api.create().approvalSubmissionOLPA(body).then((res) => {
                console.log(res)
                // this.setState({ loading: false }, () => {
                // })
Faisal Hamdi's avatar
Faisal Hamdi committed
735
                if (this.state.isAdmin && type == 'approve') {
736
                    localStorage.setItem(Constant.TOKEN, realToken)
Faisal Hamdi's avatar
Faisal Hamdi committed
737
                    this.setState({ visibleApproveSuperadmin: false })
738 739 740 741 742 743 744
                }
                setTimeout(() => {
                    if (type == 'revision') {
                        api.create().createPeriodeRevisionOLPA(payload).then((res))
                    }
                    this.getOutlookPAID()
                }, 300);
EKSAD's avatar
EKSAD committed
745
            })
746
        }, 100);
EKSAD's avatar
EKSAD committed
747 748
    }

EKSAD's avatar
EKSAD committed
749 750 751
    clickDetail(item, id, revision, status) {
        this.state.dataForRevision.map(i => {
            if (i.report_name === item) {
Riri Novita's avatar
Riri Novita committed
752
                if (i.revision == revision) {
EKSAD's avatar
EKSAD committed
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
                    this.setState({ prevRevision: true })
                } else {
                    this.setState({ prevRevision: false })
                }
            }
        })
        this.setState({
            report_id: id,
            revisionTable: revision,
            status: status
        }, () => {
            if (item === 'Balance Sheet') {
                this.setState({
                    visibleOutlookPA: false,
                    visibleBS: true,
                    visiblePL: false,
                    visibleTP: false,
faisalhamdi's avatar
faisalhamdi committed
770 771
                    visibleCF: false,
                    visibleCAT: false
EKSAD's avatar
EKSAD committed
772
                })
d.arizona's avatar
d.arizona committed
773 774 775 776 777 778
            } else if (item === 'Profit Loss') {
                this.setState({
                    visibleOutlookPA: false,
                    visibleBS: false,
                    visiblePL: true,
                    visibleTP: false,
faisalhamdi's avatar
faisalhamdi committed
779 780
                    visibleCF: false,
                    visibleCAT: false
d.arizona's avatar
d.arizona committed
781 782 783 784 785 786 787
                })
            } else if (item === 'Tax Planning') {
                this.setState({
                    visibleOutlookPA: false,
                    visibleBS: false,
                    visiblePL: false,
                    visibleTP: true,
faisalhamdi's avatar
faisalhamdi committed
788 789
                    visibleCF: false,
                    visibleCAT: false
d.arizona's avatar
d.arizona committed
790 791 792 793 794 795 796
                })
            } else if (item === 'Cash Flow') {
                this.setState({
                    visibleOutlookPA: false,
                    visibleBS: false,
                    visiblePL: false,
                    visibleTP: false,
faisalhamdi's avatar
faisalhamdi committed
797 798 799
                    visibleCF: true,
                    visibleCAT: false
                })
d.arizona's avatar
d.arizona committed
800
                // } else if (item === 'Corporate Annual Target') {
r.kurnia's avatar
r.kurnia committed
801
            } else if (item === 'CAT') {
faisalhamdi's avatar
faisalhamdi committed
802 803 804 805 806
                this.setState({
                    visibleOutlookPA: false,
                    visibleBS: false,
                    visiblePL: false,
                    visibleTP: false,
r.kurnia's avatar
r.kurnia committed
807
                    visibleCF: false,
faisalhamdi's avatar
faisalhamdi committed
808
                    visibleCAT: true
d.arizona's avatar
d.arizona committed
809 810
                })
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
811 812 813
        })
    }

d.arizona's avatar
d.arizona committed
814
    validateRevision() {
Deni Rinaldi's avatar
Deni Rinaldi committed
815 816
        let arrayRevisi = this.state.detailRevisiCheck
        let remarksKosong = 0
d.arizona's avatar
d.arizona committed
817
        arrayRevisi.map((item, index) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
818 819 820
            if (item.remarks == "") {
                remarksKosong += 1
            }
EKSAD's avatar
EKSAD committed
821
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
822 823 824 825 826
        if (remarksKosong > 0) {
            this.setState({ alert: true, messageAlert: 'Remarks Cannot be Empty', tipeAlert: 'error' })
        } else {
            this.setState({ visibleRevision: false }, () => this.approvalSubmission('revision'))
        }
EKSAD's avatar
EKSAD committed
827
    }
EKSAD's avatar
EKSAD committed
828 829 830 831 832 833 834 835 836

    handleChange(value, tableMeta) {
        let data = this.state.dataTable
        data[tableMeta.rowIndex][tableMeta.columnIndex] = value
    }

    fileHandler = (event) => {
        let fileObj = event
        ExcelRenderer(fileObj, (err, resp) => {
EKSAD's avatar
EKSAD committed
837
            // console.log(resp)
EKSAD's avatar
EKSAD committed
838
            if (err) {
EKSAD's avatar
EKSAD committed
839
                // console.log(err);
EKSAD's avatar
EKSAD committed
840 841 842 843 844 845 846 847 848 849 850 851 852
            }
            else {
                const formData = new FormData();
                formData.append("revision", Number(this.state.revision.revision));
                formData.append("companyId", this.state.company.company_id);
                formData.append("periode", Number(this.state.periode.periode));
                formData.append("file", event);
                this.setState({ formData })
            }
        })
    }

    uploadAttachment(formData) {
Deni Rinaldi's avatar
Deni Rinaldi committed
853
        api.create().uploadAttOLPA(formData).then(response => {
EKSAD's avatar
EKSAD committed
854 855 856
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({ visibleUpload: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
857
                        this.getOutlookPAID()
EKSAD's avatar
EKSAD committed
858
                    })
Riri Novita's avatar
Riri Novita committed
859 860
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
861
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
862 863 864 865 866 867
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
d.arizona's avatar
d.arizona committed
868
                }
EKSAD's avatar
EKSAD committed
869 870 871 872 873
            }
        })
    }

    deleteAttachment(item) {
Deni Rinaldi's avatar
Deni Rinaldi committed
874
        api.create().deleteAttOLPA(item.attachment_id).then(response => {
EKSAD's avatar
EKSAD committed
875 876
            if (response.data) {
                if (response.data.status === "success") {
Deni Rinaldi's avatar
Deni Rinaldi committed
877
                    this.getOutlookPAID()
Riri Novita's avatar
Riri Novita committed
878 879
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
880
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
881 882 883 884 885 886
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
d.arizona's avatar
d.arizona committed
887
                }
EKSAD's avatar
EKSAD committed
888 889 890 891 892 893 894 895
            }
        })
    }

    closeAlert() {
        this.setState({ alert: false })
    }

d.arizona's avatar
d.arizona committed
896
    saveToOLPA(data, type) {
EKSAD's avatar
EKSAD committed
897
        this.setState({ loading: true })
EKSAD's avatar
EKSAD committed
898
        // console.log(JSON.stringify(data));
Deni Rinaldi's avatar
Deni Rinaldi committed
899
        api.create('UPLOAD').createReportOLPA(data).then(response => {
Riri Novita's avatar
Riri Novita committed
900
            console.log(response);
EKSAD's avatar
EKSAD committed
901 902
            if (response.data) {
                if (response.data.status === "success") {
Riri Novita's avatar
Riri Novita committed
903 904 905 906 907 908 909 910 911
                    if (type === "PL") {
                        this.setState({ visiblePL: false, visibleOutlookPA: true })
                    } else if (type === "TP") {
                        this.setState({ visibleTP: false, visibleOutlookPA: true })
                    } else if (type === "BS") {
                        this.setState({ visibleBS: false, visibleOutlookPA: true })
                    } else {
                        this.setState({ visibleOutlookPA: true, loading: false })
                    }
d.arizona's avatar
d.arizona committed
912
                    this.getOutlookPAID(type)
EKSAD's avatar
EKSAD committed
913
                } else {
Riri Novita's avatar
Riri Novita committed
914 915 916 917 918 919 920 921 922 923 924 925 926 927
                    if (response.data.message == "Please Set Up Rate Currency First") {
                        this.setState({ visibleAlertSave: true })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false, handleDoubleClick: 0 }, () => {
                            document.body.style.overflow = 'unset';
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                            this.getOutlookPAID()
                        })
                    }
EKSAD's avatar
EKSAD committed
928
                }
Riri Novita's avatar
Riri Novita committed
929 930 931 932 933 934
                // else {
                //     this.setState({ loading: false }, () => {
                //         // alert(response.data.message)
                //         this.getOutlookPAID()
                //     })
                // }
EKSAD's avatar
EKSAD committed
935 936
            } else {
                this.setState({ loading: false }, () => {
EKSAD's avatar
EKSAD committed
937 938
                    // alert(response.problem)
                    this.getOutlookPAID()
EKSAD's avatar
EKSAD committed
939 940 941 942 943 944 945 946
                })
            }
        })
    }

    async downloadAttachment(fileurl, name) {
        let length = name.split(".").length
        let fileType = name.split(".")[length - 1]
EKSAD's avatar
EKSAD committed
947
        // console.log(fileType);
faisalhamdi's avatar
faisalhamdi committed
948
        let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/outlook_pa/download_attachment?fileName=${fileurl}&&fileType=${fileType}`
EKSAD's avatar
EKSAD committed
949
        // console.log(url);
EKSAD's avatar
EKSAD committed
950
        let res = await fetch(
faisalhamdi's avatar
faisalhamdi committed
951
            `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/outlook_pa/download_attachment?fileName=${fileurl}&&fileType=${fileType}`
EKSAD's avatar
EKSAD committed
952 953 954 955 956 957 958
        )
        res = await res.blob()
        this.setState({ loading: false })
        if (res.size > 0) {
            let url = window.URL.createObjectURL(res);
            let a = document.createElement('a');
            a.href = url;
Deni Rinaldi's avatar
Deni Rinaldi committed
959
            a.download = 'Outlook Perfromance Appraisal.xlsx';
EKSAD's avatar
EKSAD committed
960 961 962 963 964 965 966 967 968
            a.click();
        }
    }

    validate() {
        this.setState({ loading: true })
        let array = []
        let canSubmit = true
        this.state.dataTable.map(item => {
969 970 971 972
            if (item[3] !== "submitted" && item[3] !== 'approved') {
                canSubmit = false
                array.push(item[3])
            }
EKSAD's avatar
EKSAD committed
973 974 975 976 977 978
            // if (item[1] !== 'Cash Flow') {
            //     if (item[3] !== "submitted" && item[3] !== 'approved') {
            //         canSubmit = false
            //         array.push(item[3])
            //     }
            // }
EKSAD's avatar
EKSAD committed
979 980 981 982 983 984 985 986
            // if (item[3].includes("not-yet") || item[3].includes("draft")) {
            //     array.push(item[3])
            // } else {
            //     array.push(item[3])
            // }
        })
        if (canSubmit === true) {
            let body = {
Deni Rinaldi's avatar
Deni Rinaldi committed
987
                outlook_pa_id: this.state.outlook_pa_id
EKSAD's avatar
EKSAD committed
988
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
989
            api.create().submitOLPA(body).then(response => {
EKSAD's avatar
EKSAD committed
990
                // console.log(response);
EKSAD's avatar
EKSAD committed
991
                if (response.data) {
Deni Rinaldi's avatar
Deni Rinaldi committed
992
                    if (response.data.status === "success") {
Deni Rinaldi's avatar
Deni Rinaldi committed
993
                        this.getOutlookPAID()
EKSAD's avatar
EKSAD committed
994 995 996 997 998 999 1000
                    }
                }
            })
        } else {
            this.setState({ alert: true, messageAlert: 'Data Is Not Complete', tipeAlert: 'warning', loading: false })
        }
        // if (array.includes("not-yet" || "draft")) {
EKSAD's avatar
EKSAD committed
1001
        //     // console.log('gagal');
EKSAD's avatar
EKSAD committed
1002
        // } else {
EKSAD's avatar
EKSAD committed
1003
        //     // console.log('masuk');
EKSAD's avatar
EKSAD committed
1004 1005 1006 1007
        // }

    }

Riri Novita's avatar
Riri Novita committed
1008
    getPL(type) {
d.arizona's avatar
d.arizona committed
1009 1010 1011
        let PLID = null
        let payloadID = {
            "periode": this.state.periode.periode,
Riri Novita's avatar
Riri Novita committed
1012 1013
            "company_id": this.state.company.company_id,
            "currency_id": this.state.defaultCurrency.id,
d.arizona's avatar
d.arizona committed
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
        }
        console.log(payloadID);
        api.create().getPLID(payloadID).then(response => {
            console.log(response);
            if (response) {
                PLID = response.data.data == null ? null : response.data.data.profit_loss_id
            } else {
                PLID = null
            }
            this.setState({ PLID }, () => {
                let payload = {
                    "report_id": 28,
                    "revision": Number(this.state.lastRevision),
                    "periode": this.state.periode.periode,
                    "company_id": this.state.company.company_id,
d.arizona's avatar
d.arizona committed
1029
                    "outlook_pa_id": this.state.PLID,
Riri Novita's avatar
Riri Novita committed
1030
                    "currency_id": this.state.defaultCurrency.id,
d.arizona's avatar
d.arizona committed
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
                }
                api.create().getHierarkiDBPLOLPA(payload).then(response => {
                    // console.log(response);
                    let dataTable = []
                    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_outlook.total_actual_before === null ? "0" : item.profit_detail_outlook.total_actual_before === "" ? "0" : item.profit_detail_outlook.total_actual_before,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.january, formula: item.profit_detail_outlook.january_formula } : item.profit_detail_outlook.january,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.february, formula: item.profit_detail_outlook.february_formula } : item.profit_detail_outlook.february,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.march, formula: item.profit_detail_outlook.march_formula } : item.profit_detail_outlook.march,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.april, formula: item.profit_detail_outlook.april_formula } : item.profit_detail_outlook.april,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.may, formula: item.profit_detail_outlook.may_formula } : item.profit_detail_outlook.may,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.june, formula: item.profit_detail_outlook.june_formula } : item.profit_detail_outlook.june,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.july, formula: item.profit_detail_outlook.july_formula } : item.profit_detail_outlook.july,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.august, formula: item.profit_detail_outlook.august_formula } : item.profit_detail_outlook.august,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.september, formula: item.profit_detail_outlook.september_formula } : item.profit_detail_outlook.september,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.october, formula: item.profit_detail_outlook.october_formula } : item.profit_detail_outlook.october,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.november, formula: item.profit_detail_outlook.november_formula } : item.profit_detail_outlook.november,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.december, formula: item.profit_detail_outlook.december_formula } : item.profit_detail_outlook.december,
                                item.profit_detail_outlook.total_current_year,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.profit_detail_outlook.total_next_year,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.profit_detail_outlook.total_more_year,
                                item.order,
                                item.condition_it_should_be,
                                item.condition_if_wrong,
                                item.profit_detail_outlook.forecast_formula == null ? [] : item.profit_detail_outlook.forecast_formula,
                                item.profit_detail_outlook.notes
                            ])

                            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_outlook.total_actual_before === null ? "0" : item.profit_detail_outlook.total_actual_before === "" ? "0" : item.profit_detail_outlook.total_actual_before,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.january, formula: item.profit_detail_outlook.january_formula } : item.profit_detail_outlook.january,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.february, formula: item.profit_detail_outlook.february_formula } : item.profit_detail_outlook.february,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.march, formula: item.profit_detail_outlook.march_formula } : item.profit_detail_outlook.march,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.april, formula: item.profit_detail_outlook.april_formula } : item.profit_detail_outlook.april,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.may, formula: item.profit_detail_outlook.may_formula } : item.profit_detail_outlook.may,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.june, formula: item.profit_detail_outlook.june_formula } : item.profit_detail_outlook.june,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.july, formula: item.profit_detail_outlook.july_formula } : item.profit_detail_outlook.july,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.august, formula: item.profit_detail_outlook.august_formula } : item.profit_detail_outlook.august,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.september, formula: item.profit_detail_outlook.september_formula } : item.profit_detail_outlook.september,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.october, formula: item.profit_detail_outlook.october_formula } : item.profit_detail_outlook.october,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.november, formula: item.profit_detail_outlook.november_formula } : item.profit_detail_outlook.november,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail_outlook.december, formula: item.profit_detail_outlook.december_formula } : item.profit_detail_outlook.december,
                                item.profit_detail_outlook.total_current_year,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.profit_detail_outlook.total_next_year,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.profit_detail_outlook.total_more_year,
                                item.order,
                                item.condition_it_should_be,
                                item.condition_if_wrong,
                                item.profit_detail_outlook.forecast_formula == null ? [] : item.profit_detail_outlook.forecast_formula,
                                item.profit_detail_outlook.notes
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
                        // console.log(dataTable)
                        this.setState({ dbPL: dataTable }, () => {
Riri Novita's avatar
Riri Novita committed
1118
                            this.olahDataPL(this.state.dbPL, type)
d.arizona's avatar
d.arizona committed
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328
                        })
                    } else {
                        this.setState({ dbPL: [], previewTable: false, previewDownload: false })
                    }


                })
            })
        })


    }

    handleValueFormulaDBPL = (indexDBCF, value, tableMeta, column, periode, forecast) => {
        let splitFormula = String(tableMeta[3]).split(/([()@])/)
        // let splitFormula = String(tableMeta.rowData[3]).split('@')
        let baru = []
        let anjay = []
        let dataTable2 = this.state.dbPL

        // if (forecast !== undefined) {
        //     console.log(tableMeta)
        // }

        splitFormula.map((item, index) => {
            let items = String(item).substr(Number(String(item).length) - 1, 1)
            let subForm = String(item).substr(0, Number(String(item).length) - 1)
            let re = /^[a-zA-Z0-9_]+$/;
            let asd = ''
            if (item !== "") {
                if (!re.test(items)) {
                    baru.push(subForm)
                    baru.push(items)
                } else {
                    baru.push(String(item))
                }
            }
        })

        baru.map((item, index) => {
            if (item == '-' || item == '+' || item == '/' || item == '*' || item == '(' || item == ')') {
                anjay.push(item)
            } else {
                if (String(item).includes('#')) {
                    if (forecast !== undefined) {
                        let forecastt = 0
                        forecast.map((items, index) => {
                            if (items.periode == periode) {
                                forecastt += Number(items.value)
                            }
                        })
                        anjay.push(forecastt)
                    } else {
                        if (String(item).includes('[M-1]')) {
                            let tst = String(item).replace('[M-1]', '')
                            let data = column == 7 ? 18 : column - 1
                            let period = data == 18 ? Number(this.state.periode.periode) - 1 : this.state.periode.periode
                            let indexID = tableMeta[data].formula.findIndex((val) => val.item_formula == String(`@${tst}`) && val.periode == period)

                            if (indexID !== -1) {
                                let valuezz = tableMeta[data].formula[indexID].value
                                anjay.push(valuezz == "" ? 0 : valuezz)
                            }
                        } else {
                            // console.log(item)
                            let indexID = value.formula.findIndex((val) => val.item_formula == String(`@${item}`) && val.periode == Number(this.state.periode.periode))
                            if (indexID !== -1) {
                                let valuezz = value.formula[indexID].value
                                anjay.push(valuezz == "" ? 0 : valuezz)
                            }
                        }
                    }

                } else {
                    let indexID = dataTable2.findIndex((val) => val[22] == item)
                    if (indexID !== -1) {
                        // if (forecast !== undefined) {
                        //     console.log(dataTable2[indexID])
                        //     console.log(column)
                        //     console.log(dataTable2[indexID][column])

                        // }
                        if (forecast != undefined) {
                            // console.log(dataTable2[indexID][column])
                        }
                        let valuezz = dataTable2[indexID][column].value == undefined ? dataTable2[indexID][column] : dataTable2[indexID][column].value
                        anjay.push(valuezz == "" ? 0 : valuezz)
                    } else {
                        if (item === '(-1)') {
                            anjay.push(-1)
                        }
                    }
                }
            }
        })

        let anjay2 = []
        let kurung = false
        let item1 = []
        anjay.map((item, index) => {
            if (item == "(") {
                kurung = true
            } else if (item == ")") {
                kurung = false
                anjay2.push(item1)
                item1 = []
            } else {
                if (kurung) {
                    item1.push(item)
                } else {
                    anjay2.push(item)
                }
            }
        })

        let total = 0
        let opt = ""
        let totalPrio = 0
        let optPrio = ""
        let prio = false
        anjay2.map((item, index) => {
            if (Array.isArray(item)) {
                prio = true
                item.map((items, indexs) => {
                    if (items == "+") {
                        optPrio = "tambah"
                    } else if (items == "-") {
                        optPrio = "kurang"
                    } else if (items == "*") {
                        optPrio = "kali"
                    } else if (items == "/") {
                        optPrio = "bagi"
                    } else {
                        if (optPrio == "tambah") {
                            totalPrio = Number(totalPrio) + Number(items)
                        } else if (optPrio == "kurang") {
                            totalPrio = Number(totalPrio) - Number(items)
                        } else if (optPrio == "kali") {
                            totalPrio = Number(totalPrio) * Number(items)
                        } else if (optPrio == "bagi") {
                            totalPrio = Number(totalPrio) / Number(items) == NaN ? 0 : Number(totalPrio) / Number(items)
                        } else {
                            totalPrio += Number(items)
                        }
                    }
                })

                if (index == anjay2.length - 1) {
                    if (opt == "tambah") {
                        total = Number(total) + Number(totalPrio)
                    } else if (opt == "kurang") {
                        total = Number(total) - Number(totalPrio)
                    } else if (opt == "kali") {
                        total = Number(total) * Number(totalPrio)
                    } else if (opt == "bagi") {
                        total = Number(total) / Number(totalPrio) == NaN ? 0 : Number(total) / Number(totalPrio)
                    } else {
                        total += Number(totalPrio)
                    }
                }
            } else {
                // console.log(item.length)
                if (item == "+") {
                    opt = "tambah"
                    if (prio) {
                        total = Number(Number(totalPrio) + Number(total))
                        prio = false
                        totalPrio = 0
                        optPrio = ""
                    }
                } else if (item == "-") {
                    opt = "kurang"
                    if (prio) {
                        total = Number(Number(totalPrio) + Number(total))
                        prio = false
                        totalPrio = 0
                        optPrio = ""
                    }
                } else if (item == "*") {
                    opt = "kali"
                    if (prio) {
                        total = Number(Number(totalPrio) + Number(total))
                        prio = false
                        totalPrio = 0
                        optPrio = ""
                    }
                } else if (item == "/") {
                    opt = "bagi"
                    if (prio) {
                        total = Number(Number(totalPrio) + Number(total))
                        prio = false
                        totalPrio = 0
                        optPrio = ""
                    }
                } else {
                    if (opt == "tambah") {
                        total = Number(total) + Number(item)
                    } else if (opt == "kurang") {
                        total = Number(total) - Number(item)
                    } else if (opt == "kali") {
                        total = Number(total) * Number(item)
                    } else if (opt == "bagi") {
                        total = Number(total) / Number(item) == NaN ? 0 : Number(total) / Number(item)
                    } else {
                        total += Number(item)
                    }
                }
            }
        })

d.arizona's avatar
d.arizona committed
1329
        if (String(tableMeta[5]) == "Cost of Goods Sold (COGS)" && column == 20) {
d.arizona's avatar
d.arizona committed
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
            console.log(splitFormula)
            console.log(baru)
            console.log(anjay)
            console.log(anjay2)
            console.log(total)
        }
        total = R.equals(total, NaN) ? "0.0" : total
        return total
    }

    handleForecastDBPL = (index, tableMeta, periode, column) => {
        let total = 0
        let dataTable2 = this.state.dbPL

        if (tableMeta[3].includes('#PL')) {
            dataTable2[index][25].map((item, index) => {
                if (item.periode == periode) {
                    total += Number(item.value)
                }
            })
        } else {
            total = this.handleValueFormulaDBPL(dataTable2[index][column], tableMeta[column], tableMeta, column, periode, dataTable2[index][25])
        }

        return total
    }

Riri Novita's avatar
Riri Novita committed
1357
    olahDataPL(dbPL, type) {
d.arizona's avatar
d.arizona committed
1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376
        dbPL.map((item, index) => {
            if (item[0] == 5 || item[0] == 6 || item[0] == 7) {
                item[7].value = this.handleValueFormulaDBPL(index, item[7], item, 7)
                item[8].value = this.handleValueFormulaDBPL(index, item[8], item, 8)
                item[9].value = this.handleValueFormulaDBPL(index, item[9], item, 9)
                item[10].value = this.handleValueFormulaDBPL(index, item[10], item, 10)
                item[11].value = this.handleValueFormulaDBPL(index, item[11], item, 11)
                item[12].value = this.handleValueFormulaDBPL(index, item[12], item, 12)
                item[13].value = this.handleValueFormulaDBPL(index, item[13], item, 13)
                item[14].value = this.handleValueFormulaDBPL(index, item[14], item, 14)
                item[15].value = this.handleValueFormulaDBPL(index, item[15], item, 15)
                item[16].value = this.handleValueFormulaDBPL(index, item[16], item, 16)
                item[17].value = this.handleValueFormulaDBPL(index, item[17], item, 17)
                item[18].value = this.handleValueFormulaDBPL(index, item[18], item, 18)
                item[20] = this.handleForecastDBPL(index, item, `${Number(this.state.periode.periode) + 1}`, 20)
                item[21] = this.handleForecastDBPL(index, item, `${Number(this.state.periode.periode) + 2}`, 21)
            }
        })
        this.setState({ dbPL }, () => {
Riri Novita's avatar
Riri Novita committed
1377
            this.payloadPL(type)
d.arizona's avatar
d.arizona committed
1378 1379 1380
        })
    }

Riri Novita's avatar
Riri Novita committed
1381
    payloadPL(type) {
d.arizona's avatar
d.arizona committed
1382 1383 1384 1385 1386 1387
        let listPL = []
        // console.log(this.state.dbPL)
        this.state.dbPL.map((item, index) => {
            if (item[0] == 5 || item[0] == 6 || item[0] == 7) {
                // if (item[7].value == "" || item[7].value == 0 || item[7].value == "0.0") {
                item[7].value = this.handleValueFormulaDBPL(index, item[7], item, 7)
qorri_di's avatar
qorri_di committed
1388
                // }  
d.arizona's avatar
d.arizona committed
1389 1390 1391

                // if (item[8].value == "" || item[8].value == 0 || item[8].value == "0.0") {
                item[8].value = this.handleValueFormulaDBPL(index, item[8], item, 8)
qorri_di's avatar
qorri_di committed
1392
                // } 
d.arizona's avatar
d.arizona committed
1393 1394 1395

                // if (item[9].value == "" || item[9].value == 0 || item[9].value == "0.0") {
                item[9].value = this.handleValueFormulaDBPL(index, item[9], item, 9)
qorri_di's avatar
qorri_di committed
1396
                // } 
d.arizona's avatar
d.arizona committed
1397 1398 1399

                // if (item[10].value == "" || item[10].value == 0 || item[10].value == "0.0") {
                item[10].value = this.handleValueFormulaDBPL(index, item[10], item, 10)
qorri_di's avatar
qorri_di committed
1400
                // } 
d.arizona's avatar
d.arizona committed
1401 1402 1403

                // if (item[11].value == "" || item[11].value == 0 || item[11].value == "0.0") {
                item[11].value = this.handleValueFormulaDBPL(index, item[11], item, 11)
qorri_di's avatar
qorri_di committed
1404
                // } 
d.arizona's avatar
d.arizona committed
1405 1406 1407

                // if (item[12].value == "" || item[12].value == 0 || item[12].value == "0.0") {
                item[12].value = this.handleValueFormulaDBPL(index, item[12], item, 12)
qorri_di's avatar
qorri_di committed
1408
                // } 
d.arizona's avatar
d.arizona committed
1409 1410 1411 1412 1413 1414 1415

                // if (item[13].value == "" || item[13].value == 0 || item[13].value == "0.0") {
                item[13].value = this.handleValueFormulaDBPL(index, item[13], item, 13)
                // }

                // if (item[14].value == "" || item[14].value == 0 || item[14].value == "0.0") {
                item[14].value = this.handleValueFormulaDBPL(index, item[14], item, 14)
qorri_di's avatar
qorri_di committed
1416
                // } 
d.arizona's avatar
d.arizona committed
1417 1418 1419

                // if (item[15].value == "" || item[15].value == 0 || item[15].value == "0.0") {
                item[15].value = this.handleValueFormulaDBPL(index, item[15], item, 15)
qorri_di's avatar
qorri_di committed
1420
                // } 
d.arizona's avatar
d.arizona committed
1421 1422 1423

                // if (item[16].value == "" || item[16].value == 0 || item[16].value == "0.0") {
                item[16].value = this.handleValueFormulaDBPL(index, item[16], item, 16)
qorri_di's avatar
qorri_di committed
1424
                // } 
d.arizona's avatar
d.arizona committed
1425 1426 1427

                // if (item[17].value == "" || item[17].value == 0 || item[17].value == "0.0") {
                item[17].value = this.handleValueFormulaDBPL(index, item[17], item, 17)
qorri_di's avatar
qorri_di committed
1428
                // } 
d.arizona's avatar
d.arizona committed
1429 1430 1431

                // if (item[18].value == "" || item[18].value == 0 || item[18].value == "0.0") {
                item[18].value = this.handleValueFormulaDBPL(index, item[18], item, 18)
qorri_di's avatar
qorri_di committed
1432
                // } 
d.arizona's avatar
d.arizona committed
1433 1434 1435

                // if (item[20] == "" || item[20] == 0 || item[20] == "0.0") {
                item[20] = this.handleForecastDBPL(index, item, `${Number(this.state.periode.periode) + 1}`, 20)
qorri_di's avatar
qorri_di committed
1436
                // } 
d.arizona's avatar
d.arizona committed
1437 1438 1439

                // if (item[21] == "" || item[21] == 0 || item[21] == "0.0") {
                item[21] = this.handleForecastDBPL(index, item, `${Number(this.state.periode.periode) + 2}`, 21)
qorri_di's avatar
qorri_di committed
1440
                // } 
d.arizona's avatar
d.arizona committed
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475
            }


            listPL.push(
                {
                    "item_report_id": item[1],
                    "january": String(item[7].value == undefined ? item[7] : Number(item[7].value).toFixed(1)),
                    "february": String(item[8].value == undefined ? item[8] : Number(item[8].value).toFixed(1)),
                    "march": String(item[9].value == undefined ? item[9] : Number(item[9].value).toFixed(1)),
                    "april": String(item[10].value == undefined ? item[10] : Number(item[10].value).toFixed(1)),
                    "may": String(item[11].value == undefined ? item[11] : Number(item[11].value).toFixed(1)),
                    "june": String(item[12].value == undefined ? item[12] : Number(item[12].value).toFixed(1)),
                    "july": String(item[13].value == undefined ? item[13] : Number(item[13].value).toFixed(1)),
                    "august": String(item[14].value == undefined ? item[14] : Number(item[14].value).toFixed(1)),
                    "september": String(item[15].value == undefined ? item[15] : Number(item[15].value).toFixed(1)),
                    "october": String(item[16].value == undefined ? item[16] : Number(item[16].value).toFixed(1)),
                    "november": String(item[17].value == undefined ? item[17] : Number(item[17].value).toFixed(1)),
                    "december": String(item[18].value == undefined ? item[18] : Number(item[18].value).toFixed(1)),
                    "total_current_year": String(item[19]),
                    "total_next_year": String(item[20] != '' ? Number(item[20]).toFixed(1) : item[20]),
                    "total_more_year": String(item[21] != '' ? Number(item[21]).toFixed(1) : item[21]),
                    "notes": String(item[26]),
                }
            )

        })

        // console.log(listPL)
        this.setState({ dbPL: listPL }, () => {
            // if (this.state.submissionID != null) {
            //     this.createDBPL()
            // }
            if (type != undefined) {
                if (type == 'PL') {
                    console.log('tarik sis')
Riri Novita's avatar
Riri Novita committed
1476
                    this.createDBPL()
d.arizona's avatar
d.arizona committed
1477 1478 1479 1480 1481
                }
            }
        })
    }

Riri Novita's avatar
Riri Novita committed
1482
    createDBPL() {
d.arizona's avatar
d.arizona committed
1483 1484 1485 1486 1487 1488 1489 1490
        let payload = {
            // "submission_id": this.state.submissionID,
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
            "report_id": 28,
            "status": "submitted",
            "profit_loss_id": this.state.PLID,
            "profit_loss_olpa": this.state.dbPL,
Riri Novita's avatar
Riri Novita committed
1491
            "currency_id": this.state.defaultCurrency.id,
d.arizona's avatar
d.arizona committed
1492 1493 1494
        }
        console.log(this.state.dbPL)
        // console.log(JSON.stringify(payload))
Riri Novita's avatar
Riri Novita committed
1495 1496 1497 1498
        api.create().createDBPLOLPA(payload).then((res) => {
            console.log(res)
            this.setState({ loading: false })
        })
d.arizona's avatar
d.arizona committed
1499 1500
    }

1501
    handleApproveAdmin() {
Faisal Hamdi's avatar
Faisal Hamdi committed
1502
        this.setState({ visibleApproveSuperadmin: true })
1503 1504
    }

qorri_di's avatar
qorri_di committed
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586
    handleSelectAll(data) {
        if (this.state.isCheckAll) {
            let checkAll = []
            this.setState({ selectReport: checkAll, isCheckAll: false })
        } else {
            let checkAll = this.state.selectReport
            data.map((item) => {
                if (item[5] == true || (this.state.periode.periode == '2020' && item[1] == 'Balance Sheet' && item[3] == 'CLOSED')) {
                    if (!this.state.selectReport.includes(item[4])) {
                        checkAll.push(item[4])
                    }
                }
            })
            this.setState({ selectReport: checkAll, isCheckAll: true })
        }
    }

    handleItemChecked(item) {
        let indexID = this.state.selectReport.findIndex((val) => val === item.rowData[4])
        return indexID === -1 ? false : true
    }

    handleItemClick(item) {
        let indexID = this.state.selectReport.findIndex((val) => val === item.rowData[4])
        let selectReport = this.state.selectReport
        if (indexID === -1) {
            selectReport.push(item.rowData[4])
        } else {
            selectReport.splice(indexID, 1)
        }
        let isCheckAll = selectReport.length === this.state.dataTable.length
        this.setState({ selectReport, isCheckAll })
        console.log(selectReport);
    }

    handleDownloadReport(tableMeta) {
        let { selectReport, company, periode, month } = this.state
        let payload = {
            "company_id": company.company_id,
            "year": periode.periode,
            "report_id": selectReport,
            "month": "",
            "quartal": "",
            "type_report_name": "Outlook PA"
        }
        console.log(payload);
        api.create().createDownloadFile(payload).then((response) => {
            console.log(response)
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        let data = response.data.data
                        this.setState({ downloadedFileReportId: data.downloadedFileReportId, popupDownload: true }, () => this.handleGenerateReport(tableMeta))
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
            } else {
                // this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error'})
                alert(response.problem)
            }
        })
    }

    // componentDidUpdate = (prevProps, prevState) => {
    //     if (this.state.selectReport.length > 0 && (this.state.arrayReport.length == this.state.selectReport.length)) {
    //         setTimeout(() => {
    //             this.handleZip()
    //         }, 200);
    //     }
    // }

    async handleGenerateReport(data) {
1587
        let { selectReport, outlook_pa_id, company, periode, month, downloadedFileReportId, quarter, defaultCurrency } = this.state
qorri_di's avatar
qorri_di committed
1588 1589 1590 1591 1592 1593 1594
        if (selectReport.length > 0) {
            let result = []
            console.log('mulai hit')
            for (const items of selectReport) {
                let datas = data.findIndex((val) => val[4] == items)
                let report = data[datas]
                if (items === 38) {
Riri Novita's avatar
Riri Novita committed
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
                    try {
                        let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/cash_flow/outlook_pa/export_outlook_pa?outlook_pa_id=${outlook_pa_id}&&report_id=${report[4]}&&company_id=${company.company_id}&&year=${periode.periode}&&revision=${report[2]}&&download_file_report_id=${downloadedFileReportId}&&currency_id=${defaultCurrency.id}`
                        let res = await fetch(
                            `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/cash_flow/outlook_pa/export_outlook_pa?outlook_pa_id=${outlook_pa_id === null ? "" : outlook_pa_id}&&report_id=${report[4]}&&company_id=${company.company_id}&&year=${periode.periode}&&revision=${report[2]}&&download_file_report_id=${downloadedFileReportId}&&currency_id=${defaultCurrency.id}`
                        )

                        if (res.status === 200) {
                            result = [...result, res];
                        }
                    } catch (error) {
                        alert(error)
qorri_di's avatar
qorri_di committed
1606 1607
                    }

Riri Novita's avatar
Riri Novita committed
1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
                } else {
                    try {
                        let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/outlook_pa/export_outlook_pa?outlook_pa_id=${outlook_pa_id}&&report_id=${report[4]}&&company_id=${company.company_id}&&year=${periode.periode}&&revision=${report[2]}&&download_file_report_id=${downloadedFileReportId}&&currency_id=${defaultCurrency.id}`
                        let res = await fetch(
                            `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/outlook_pa/export_outlook_pa?outlook_pa_id=${outlook_pa_id === null ? "" : outlook_pa_id}&&report_id=${report[4]}&&company_id=${company.company_id}&&year=${periode.periode}&&revision=${report[2]}&&download_file_report_id=${downloadedFileReportId}&&currency_id=${defaultCurrency.id}`
                        )

                        if (res.status === 200) {
                            result = [...result, res];
                        }
                    } catch (error) {
                        alert(error)
qorri_di's avatar
qorri_di committed
1620
                    }
Riri Novita's avatar
Riri Novita committed
1621

qorri_di's avatar
qorri_di committed
1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663
                }
            }

            console.log('ini result', result);
            // every untuk cek ke setiap result di dalam array
            if (result.every((e) => e.status == 200)) {
                this.handleZip();
            }

        } else {
            alert("Anda harus memilih report yang ingin di download terlebih dahulu!")
        }
    }

    async handleZip() {
        console.log('mulai zip')
        api.create().createZipReport(this.state.downloadedFileReportId).then((response) => {
            console.log(response)
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        this.setState({ arrayReport: [] })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
            } else {
                // this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error'})
                alert(response.problem)
            }
        })
    }

EKSAD's avatar
EKSAD committed
1664
    render() {
EKSAD's avatar
EKSAD committed
1665 1666 1667 1668
        const handleMaxDate = () => {
            let handleDate = Number(moment(this.state.maxDateRevision).format('YYYYMMDD')) - Number(moment(this.state.minDateRevision).format('YYYYMMDD'))
            return handleDate < 0 ? moment(this.state.minDateRevision).format('YYYY/MM/DD') : moment(this.state.maxDateRevision).format('YYYY/MM/DD')
        }
EKSAD's avatar
EKSAD committed
1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686
        const columns = ["#", "Report Type",
            {
                name: "Revision",
                options: {
                    customBodyRender: (val, tableMeta, updateValue) => {
                        var list = [];
                        for (var i = 0; i <= tableMeta.rowData[6]; i++) {
                            list.push(i);
                        }
                        return (
                            <div style={{ display: 'flex' }}>
                                <FormControlLabel
                                    style={{ margin: 0 }}
                                    value={val}
                                    control={
                                        <Select
                                            value={val}
                                            onChange={event => {
EKSAD's avatar
EKSAD committed
1687
                                                // console.log(event.target)
EKSAD's avatar
EKSAD committed
1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733
                                                updateValue(event.target.value)
                                                this.handleChange(event.target.value, tableMeta)
                                            }}
                                            autoWidth
                                        >
                                            {list.map((item, index) =>
                                                <MenuItem key={index} value={item}>{item}</MenuItem>
                                            )}
                                        </Select>
                                    }
                                />
                            </div >
                        );
                    }
                }
            }, {
                name: "Status",
                options: {
                    customBodyRender: (val, tableMeta) => {
                        return (
                            <div style={{ display: 'flex' }}>
                                {val === "submitted" || val === "approved" ?
                                    <span>COMPLETED</span> :
                                    val === "draft" ?
                                        <span>DRAFT</span> :
                                        val === "revision" ?
                                            <span>REVISION</span> :
                                            val === "approval_proccess" ?
                                                <span>APPROVAL PROCCESS</span> :
                                                val === "approval_review" ?
                                                    <span>APPROVAL REVIEW</span> :
                                                    val === "not-yet" ?
                                                        <span>OPEN</span> :
                                                        val === "CLOSED" ?
                                                            <span>CLOSED</span> :
                                                            <img src={Images.cross} style={{ width: 31, height: 24 }} />
                                }
                            </div >
                        );
                    }
                }
            },
            {
                name: "Action",
                options: {
                    customBodyRender: (val, tableMeta) => {
r.kurnia's avatar
r.kurnia committed
1734
                        // console.log(tableMeta)
EKSAD's avatar
EKSAD committed
1735 1736 1737 1738 1739
                        return (
                            <div style={{ display: 'flex' }}>
                                <button
                                    style={{
                                        backgroundColor: 'transparent',
syadziy's avatar
syadziy committed
1740
                                        cursor: (this.state.periode.periode == '2020' && tableMeta.rowData[1] == 'Balance Sheet' && tableMeta.rowData[3] == 'CLOSED') ? 'pointer' : (this.state.isSubmit === false ? 'default' : tableMeta.rowData[5] ? 'pointer' : 'default'),
EKSAD's avatar
EKSAD committed
1741
                                        // cursor: tableMeta.rowData[5] ? 'pointer' : 'default',
EKSAD's avatar
EKSAD committed
1742 1743 1744
                                        borderColor: 'transparent'
                                    }}
                                    onClick={() =>
syadziy's avatar
syadziy committed
1745
                                        tableMeta.rowData[5] == true || (this.state.periode.periode == '2020' && tableMeta.rowData[1] == 'Balance Sheet' && tableMeta.rowData[3] == 'CLOSED') ?
EKSAD's avatar
EKSAD committed
1746
                                            this.clickDetail(tableMeta.rowData[1], tableMeta.rowData[4], tableMeta.rowData[2], tableMeta.rowData[3])
Riri Novita's avatar
Riri Novita committed
1747
                                            : null
EKSAD's avatar
EKSAD committed
1748 1749
                                    }
                                >
qorri_di's avatar
qorri_di committed
1750
                                    {/* {this.state.isApprover == true ? 
EKSAD's avatar
EKSAD committed
1751 1752 1753
                                        (tableMeta.rowData[5] ? '#5198ea' : 'GrayText') :
                                        (this.state.lastRevision == 0 ? (tableMeta.rowData[5] ? '#5198ea' : 'GrayText') :
                                        (tableMeta.rowData[3] !== 'submitted' ? '#5198ea' : 'GrayText'))} */}
syadziy's avatar
syadziy committed
1754
                                    <Typography style={{ color: (this.state.periode.periode == '2020' && tableMeta.rowData[1] == 'Balance Sheet' && tableMeta.rowData[3] == 'CLOSED') ? '#5198ea' : tableMeta.rowData[5] ? '#5198ea' : 'GrayText', fontSize: 12, }}>Detail</Typography>
EKSAD's avatar
EKSAD committed
1755 1756 1757 1758 1759
                                </button>
                            </div >
                        );
                    }
                }
qorri_di's avatar
qorri_di committed
1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775
            }, {
                name: "Download",
                options: {
                    customBodyRender: (val, tableMeta) => {
                        // console.log(tableMeta);
                        return (
                            <div style={{ display: 'flex' }}>
                                <CustomCheckbox
                                    checked={this.handleItemChecked(tableMeta)}
                                    onChange={() => tableMeta.rowData[5] == true || (this.state.periode.periode == '2020' && tableMeta.rowData[1] == 'Balance Sheet' && tableMeta.rowData[3] == 'CLOSED') ? this.handleItemClick(tableMeta) : null}
                                    disabled={tableMeta.rowData[5] == true || (this.state.periode.periode == '2020' && tableMeta.rowData[1] == 'Balance Sheet' && tableMeta.rowData[3] == 'CLOSED') ? false : true}
                                />
                            </div >
                        );
                    }
                }
EKSAD's avatar
EKSAD committed
1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830
            }, {
                name: "",
                options: { display: false }
            }, {
                name: "",
                options: { display: false }
            }]

        const columnsHistory = [
            "Name", "Status", "Remarks", "Revision Item", "Date"
        ]

        const columnRevisi = [
            {
                name: "#",
                options: {
                    customBodyRender: (val, tableMeta, updateValue) => {
                        var list = [];
                        for (var i = 0; i <= tableMeta.rowData[6]; i++) {
                            list.push(i);
                        }
                        return (
                            <div style={{ display: 'flex' }}>
                                <FormControlLabel
                                    style={{ margin: 0 }}
                                    value={val}
                                    control={
                                        <Checkbox
                                            checked={this.state.detailRevisiCheck.findIndex((val) => val.report_id == tableMeta.rowData[0]) == -1 ? false : true}
                                            onClick={() => handleCheckRevision(tableMeta.rowData)} />
                                    }
                                />
                            </div >
                        );
                    }
                }
            }, "Report Type",
            {
                name: 'Remarks',
                options: {
                    customBodyRender: (value, tableMeta, updateValue) => {
                        return (
                            <div style={{ textAlign: 'left' }}>
                                <FormControlLabel
                                    style={{ margin: 0 }}
                                    // value={value}
                                    control={
                                        <Input
                                            disableUnderline={true}
                                            style={{ fontSize: 12, textAlign: 'center', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent', marginTop: -10 }}
                                            type="text"
                                            placeholder=""
                                            defaultValue={value}
                                            color={"#5198ea"}
                                            onBlur={(event) => {
EKSAD's avatar
EKSAD committed
1831
                                                // console.log(event.target.value)
EKSAD's avatar
EKSAD committed
1832 1833
                                                // updateValue(event.target.value)
                                                handleChangeText(event.target.value, tableMeta)
EKSAD's avatar
EKSAD committed
1834
                                                // console.log(dataTable2)
EKSAD's avatar
EKSAD committed
1835 1836 1837 1838 1839 1840 1841
                                            }}
                                        />}
                                />
                            </div>
                        )
                    }
                }
1842 1843 1844
            }, {
                name: "",
                options: { display: false }
EKSAD's avatar
EKSAD committed
1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860
            }
        ]

        const handleChangeText = (value, tableMeta) => {
            let dataTableRevision = this.state.dataTableRevision
            dataTableRevision[tableMeta.rowIndex][tableMeta.columnIndex] = value

            let detailRevisiCheck = this.state.detailRevisiCheck
            let indexId = detailRevisiCheck.findIndex((val) => val.report_id == tableMeta.rowData[0])
            if (indexId !== -1) {
                detailRevisiCheck[indexId].remarks = value
            }

            this.setState({ dataTableRevision, detailRevisiCheck })
        }

1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877
        // const handleCheckRevision = (value) => {
        //     let detailRevisiCheck = this.state.detailRevisiCheck
        //     let payload = {
        //         report_id: value[0],
        //         remarks: value[2]
        //     }

        //     let indexId = detailRevisiCheck.findIndex((val) => val.report_id == value[0])
        //     if (indexId == -1) {
        //         detailRevisiCheck.push(payload)
        //     } else {
        //         detailRevisiCheck.splice(indexId, 1)
        //     }
        //     this.setState({ detailRevisiCheck })
        //     // console.log(detailRevisiCheck)
        // }

EKSAD's avatar
EKSAD committed
1878 1879 1880 1881
        const handleCheckRevision = (value) => {
            let detailRevisiCheck = this.state.detailRevisiCheck
            let payload = {
                report_id: value[0],
1882 1883
                remarks: value[2],
                number: value[3]
EKSAD's avatar
EKSAD committed
1884
            }
1885 1886 1887
            let indexDataRevisi = this.state.dataTableRevision.findIndex((val) => val[3] == value[3])
            let indexId = detailRevisiCheck.sort((a, b) => a.number - b.number).findIndex((val) => val.number == value[3])
            // // console.log(indexId)
EKSAD's avatar
EKSAD committed
1888
            if (indexId == -1) {
1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901
                this.state.dataTableRevision.map((item, index) => {
                    if (index > indexDataRevisi) {
                        let indexIds = detailRevisiCheck.findIndex((val) => val.number == item[3])
                        if (indexIds == -1) {
                            let payload2 = {
                                report_id: item[0],
                                remarks: item[2],
                                number: item[3]
                            }
                            detailRevisiCheck.push(payload2)
                        }
                    }
                })
EKSAD's avatar
EKSAD committed
1902 1903
                detailRevisiCheck.push(payload)
            } else {
1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921

                let x = 0
                detailRevisiCheck.sort((a, b) => a.number - b.number).map((item, index) => {
                    if (item.number < value[3]) {
                        x += 1
                    }
                })
                if (x < 1) {
                    this.state.dataTableRevision.map((item, index) => {
                        if (index > indexDataRevisi) {
                            let indexIdz = detailRevisiCheck.findIndex((val) => val.number == item[3])
                            if (indexIdz !== -1) {
                                detailRevisiCheck.splice(indexIdz, 1)
                            }
                        }
                    })
                    detailRevisiCheck.splice(indexId, 1)
                }
EKSAD's avatar
EKSAD committed
1922
            }
1923
            this.setState({ detailRevisiCheck: detailRevisiCheck.sort((a, b) => a.number - b.number) })
EKSAD's avatar
EKSAD committed
1924
            // console.log(detailRevisiCheck)
EKSAD's avatar
EKSAD committed
1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937
        }

        const options = {
            filter: false,
            sort: false,
            responsive: "scroll",
            print: false,
            download: false,
            selectableRows: false,
            viewColumns: false,
            pagination: false,
            search: false
        }
EKSAD's avatar
EKSAD committed
1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949
        const optionsHistory = {
            filter: false,
            sort: false,
            responsive: "scroll",
            print: false,
            download: false,
            selectableRows: false,
            viewColumns: false,
            pagination: true,
            search: false,
            rowsPerPage: 5
        }
EKSAD's avatar
EKSAD committed
1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971
        const optionsRevision = {
            filter: false,
            sort: false,
            responsive: "scroll",
            print: false,
            download: false,
            selectableRows: false,
            viewColumns: false,
            pagination: false,
            search: false
        }
        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 (
EKSAD's avatar
EKSAD committed
1972
            <div style={{ flex: 1, backgroundColor: '#f8f8f8' }} ref={this.myRef}>
EKSAD's avatar
EKSAD committed
1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989
                <Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
                    <Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
                        {this.state.messageAlert}
                    </Alert>
                </Snackbar>
                {this.state.loading && loadingComponent}
                {this.state.visibleOutlookPA && (
                    <div>
                        <div className={"main-color"} style={{ height: 78, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
                            <Typography style={{ fontSize: '16px', color: 'white' }}>Outlook Performance Appraisal Submission</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 }}>Outlook Performance Appraisal</Typography>
                                </div>
                                <div style={{ padding: 20 }}>
1990
                                    <div style={{ display: "flex" }}>
EKSAD's avatar
EKSAD committed
1991 1992 1993 1994
                                        <Autocomplete
                                            {...this.state.listPeriode}
                                            id="periode"
                                            onChange={(event, newInputValue) => this.setState({ periode: newInputValue }, () => {
d.arizona's avatar
d.arizona committed
1995 1996 1997
                                                this.setState({ visibleTableHistory: false })
                                                if (this.state.listCompany == null) {
                                                    console.log('yak')
EKSAD's avatar
EKSAD committed
1998 1999
                                                    this.getCompanySubmitted()
                                                } else {
d.arizona's avatar
d.arizona committed
2000
                                                    console.log('zz')
EKSAD's avatar
EKSAD committed
2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
                                                    this.getRevision()
                                                }
                                            })}
                                            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}
                                        />
2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035
                                        <Autocomplete
                                            id="tipe"
                                            disableClearable
                                            options={this.state.currency}
                                            getOptionLabel={(option) => option.value}
                                            value={this.state.defaultCurrency}
                                            // onChange={(event, newInputValue) => this.setState({ defaultCurrency: newInputValue })}
                                            onChange={(event, newInputValue) => this.setState({ defaultCurrency: newInputValue }, () => {
                                                this.getRevision()
                                            })}
                                            style={{ width: 250 }}
                                            renderInput={(params) =>
                                                <TextField
                                                    {...params}
                                                    variant="standard"
                                                    label="Currency"
                                                    margin="normal"
                                                    style={{ marginTop: 7, marginLeft: 20 }}
                                                // InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
                                                // InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
                                                />
                                            }

                                        />
EKSAD's avatar
EKSAD committed
2036
                                    </div>
d.arizona's avatar
d.arizona committed
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053
                                    <div style={{ marginTop: 20 }}>
                                        <Autocomplete
                                            multiple
                                            id="tags-standard"
                                            options={this.state.listStatus}
                                            getOptionLabel={(option) => option.name}
                                            style={{ width: 250 }}
                                            onChange={(event, newInputValue) => {
                                                this.setState({ selectedStatus: newInputValue, loading: true }, () => {
                                                    console.log(newInputValue);
                                                    this.getCompanySubmitted()
                                                })
                                            }}
                                            value={this.state.selectedStatus}
                                            renderInput={(params) => <TextField {...params} label="Submission Status" margin="normal" style={{ marginTop: 7 }} />}
                                        />
                                    </div>
EKSAD's avatar
EKSAD committed
2054 2055 2056 2057 2058 2059 2060 2061
                                    <div style={{ marginTop: 20 }}>
                                        <Autocomplete
                                            {...this.state.listCompany}
                                            id="company"
                                            disabled={this.state.intent === 'Home' ? true : false}
                                            onChange={(event, newInputValue) => this.setState({ company: newInputValue }, () => {
                                                this.setState({ visibleTableHistory: false })
                                                this.getRevision()
2062
                                                this.getCurrency(newInputValue.company_id)
EKSAD's avatar
EKSAD committed
2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087
                                            })}
                                            disableClearable
                                            style={{ width: 250 }}
                                            renderInput={(params) => <TextField {...params} label="Company" margin="normal" style={{ marginTop: 7 }} />}
                                            value={this.state.company}
                                        />
                                    </div>
                                    <div style={{ marginTop: 20 }}>
                                        {/* <Autocomplete
                                            {...this.state.listRevision}
                                            id="revision"
                                            onChange={(event, newInputValue) => this.setState({ revision: newInputValue }, () => {
                                                this.getReport()
                                                this.getReportAttachment()
                                            })}
                                            disabled={true}
                                            disableClearable
                                            style={{ width: 250 }}
                                            renderInput={(params) => <TextField {...params} label="Revision" margin="normal" style={{ marginTop: 7 }} />}
                                            value={this.state.revision}
                                        /> */}
                                        <TextField disabled={true} label="Revision" margin="normal" style={{ marginTop: 7, width: 250 }} value={this.state.lastRevision} />
                                    </div>

                                    <div style={{ marginTop: 20 }}>
qorri_di's avatar
qorri_di committed
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119
                                        <div style={{ display: 'flex', justifyContent: 'flex-end', margin: '20px 15px' }}>
                                            <button
                                                className="button"
                                                type="button"
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    outline: 'none',
                                                    marginRight: 20
                                                }}
                                                onClick={() => this.handleSelectAll(this.state.dataTable)}
                                            >
                                                <div style={{ backgroundColor: '#fff', width: 100, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #354960' }}>
                                                    <Typography style={{ fontSize: '11px', color: '#354960', textAlign: 'center' }}>Check All</Typography>
                                                </div>
                                            </button>
                                            <button
                                                type="button"
                                                disabled={this.state.buttonError}
                                                onClick={() => this.state.selectReport.length > 0 ? this.handleDownloadReport(this.state.dataTable) : alert("Anda harus memilih report yang ingin di download terlebih dahulu!")}
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    borderColor: 'transparent',
                                                    outline: 'none',
                                                }}
                                            >
                                                <div style={{ backgroundColor: '#354960', width: 100, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                                    <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Download</Typography>
                                                </div>
                                            </button>
                                        </div>
EKSAD's avatar
EKSAD committed
2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131
                                        <MuiThemeProvider theme={getMuiTheme()}>
                                            <MUIDataTable
                                                data={this.state.dataTable}
                                                columns={columns}
                                                options={options}
                                            />
                                        </MuiThemeProvider>
                                    </div>
                                    <div style={{ display: 'flex', marginTop: 20 }}>
                                        <div style={{ width: '50%' }}>
                                            <Typography style={{ fontSize: '16px', color: '#4b4b4b', fontWeight: 'bold' }}>Attachment: </Typography>
                                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
2132
                                        {!this.state.isApprover && (this.state.lastStatus === 'SUBMIT' || this.state.lastStatus === 'REVISION') && (
EKSAD's avatar
EKSAD committed
2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177
                                            <div style={{ width: '50%' }}>
                                                <button
                                                    style={{
                                                        backgroundColor: 'transparent',
                                                        cursor: this.state.isSubmit === false ? 'default' : 'pointer',
                                                        borderColor: 'transparent',
                                                        outline: 'none'
                                                    }}
                                                    onClick={() => this.state.isSubmit === false ? null : this.setState({ visibleUpload: true })}
                                                >
                                                    <Typography style={{ fontSize: '16px', color: this.state.isSubmit === false ? 'GrayText' : '#5198ea' }}>Upload File</Typography>
                                                </button>
                                            </div>
                                        )}
                                    </div>
                                    <div style={{ display: 'flex', marginTop: 10 }}>
                                        <div style={{ width: '50%', paddingLeft: 20 }}>
                                            {this.state.listAttachment.length > 0 ?
                                                this.state.listAttachment.map((item, index) => {
                                                    return (
                                                        <div style={{ display: 'flex' }}>
                                                            <Typography style={{ fontSize: '13px', color: '#4b4b4b', width: 25 }}>{index + 1}. </Typography>

                                                            <button
                                                                style={{
                                                                    backgroundColor: 'transparent',
                                                                    cursor: 'pointer',
                                                                    borderColor: 'transparent',
                                                                    outline: 'none',
                                                                    display: 'grid'
                                                                }}
                                                                onClick={() => {
                                                                    this.downloadAttachment(item.attachment_url, item.attachment_name)
                                                                }}
                                                            >
                                                                <div>
                                                                    <Typography style={{ fontSize: '13px', color: '#5198ea' }}> {item.attachment_name}</Typography>
                                                                </div>
                                                            </button>
                                                        </div>
                                                    )
                                                })
                                                : null
                                            }
                                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
2178
                                        {!this.state.isApprover && (this.state.lastStatus === 'SUBMIT' || this.state.lastStatus === 'REVISION') && (
EKSAD's avatar
EKSAD committed
2179
                                            <div style={{ width: '50%' }}>
EKSAD's avatar
EKSAD committed
2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198
                                                {
                                                    this.state.listAttachment.length > 0 ?
                                                        this.state.listAttachment.map((item) => {
                                                            return (
                                                                <button
                                                                    style={{
                                                                        backgroundColor: 'transparent',
                                                                        cursor: this.state.isSubmit === false ? 'default' : 'pointer',
                                                                        borderColor: 'transparent',
                                                                        outline: 'none',
                                                                        display: 'grid'
                                                                    }}
                                                                    onClick={() => this.state.isSubmit === false ? null : this.deleteAttachment(item)}
                                                                >
                                                                    <Typography style={{ fontSize: '13px', color: this.state.isSubmit === false ? 'GrayText' : '#ff3939' }}>Delete</Typography>
                                                                </button>
                                                            )
                                                        })
                                                        : null
EKSAD's avatar
EKSAD committed
2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209
                                                }
                                            </div>
                                        )}
                                    </div>
                                    {this.state.checkApprover === true ?
                                        this.state.lastStatus === 'WAITING FOR REVIEW' ?
                                            <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
                                                <span>{this.state.lastStatus}</span>
                                            </div> : this.state.lastStatus === 'WAITING FOR YOUR APPROVAL' ?
                                                <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
                                                    <span>{this.state.lastStatus}</span>
EKSAD's avatar
EKSAD committed
2210 2211 2212 2213 2214 2215 2216
                                                </div> : this.state.lastStatus === 'WAITING FOR APPROVAL' ?
                                                    <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
                                                        <span>{`${this.state.lastStatus} - ${this.state.pic}`}</span>
                                                    </div> : this.state.lastStatus === 'APPROVED' ?
                                                        <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
                                                            <span>{`${this.state.lastStatus}`}</span>
                                                        </div> : null
EKSAD's avatar
EKSAD committed
2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246
                                        :
                                        this.state.lastStatus === 'SUBMITTED' ?
                                            <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
                                                <span>{this.state.lastStatus}</span>
                                            </div> :
                                            this.state.lastStatus === 'WAITING FOR APPROVAL' ?
                                                <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
                                                    <span>{`${this.state.lastStatus} - ${this.state.pic}`}</span>
                                                </div> :
                                                this.state.lastStatus === 'REVISION' ?
                                                    <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
                                                        <span>NEED REVISION</span>
                                                    </div> :
                                                    this.state.lastStatus === 'APPROVED' ?
                                                        <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
                                                            <span>APPROVED</span>
                                                        </div> : null
                                    }
                                    {this.state.visibleTableHistory && (
                                        <div style={{ marginTop: 20 }}>
                                            <MuiThemeProvider theme={getMuiTheme()}>
                                                <MUIDataTable
                                                    data={this.state.dataTableHistory}
                                                    columns={columnsHistory}
                                                    options={options}
                                                />
                                            </MuiThemeProvider>
                                        </div>
                                    )}
                                </div>
d.arizona's avatar
d.arizona committed
2247 2248 2249 2250
                                {this.state.isAdmin && this.state.lastStatus == 'APPROVED' ?
                                    <div className="grid grid-2x" style={{ borderTop: 'solid 1px #c4c4c4', padding: 10, backgroundColor: '#f5f5f5', width: '100%', }}>
                                        <div className="col-1" />
                                        <div className="col-2" style={{ display: 'flex', justifyContent: 'flex-end', maxWidth: '100%' }}>
EKSAD's avatar
EKSAD committed
2251 2252 2253 2254 2255 2256
                                            <button
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    outline: 'none',
d.arizona's avatar
d.arizona committed
2257
                                                    marginRight: 20
EKSAD's avatar
EKSAD committed
2258
                                                }}
d.arizona's avatar
d.arizona committed
2259
                                                onClick={() => this.setState({ visibleRevision: true })}
EKSAD's avatar
EKSAD committed
2260
                                            >
d.arizona's avatar
d.arizona committed
2261 2262
                                                <div style={{ backgroundColor: '#019ce5', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                                    <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Revision</Typography>
EKSAD's avatar
EKSAD committed
2263 2264
                                                </div>
                                            </button>
d.arizona's avatar
d.arizona committed
2265
                                            {/* <button
EKSAD's avatar
EKSAD committed
2266 2267 2268 2269 2270 2271
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    outline: 'none',
                                                }}
d.arizona's avatar
d.arizona committed
2272
                                                onClick={() => this.approvalSubmission('approve')}
EKSAD's avatar
EKSAD committed
2273 2274
                                            >
                                                <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
d.arizona's avatar
d.arizona committed
2275
                                                    <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Approve</Typography>
EKSAD's avatar
EKSAD committed
2276
                                                </div>
d.arizona's avatar
d.arizona committed
2277 2278 2279 2280
                                            </button> */}
                                        </div>
                                    </div>
                                    :
2281 2282 2283 2284
                                    this.state.isAdmin && (this.state.lastStatus == 'WAITING FOR YOUR APPROVAL' || this.state.lastStatus == 'WAITING FOR APPROVAL') ?
                                        <div className="grid grid-2x" style={{ borderTop: 'solid 1px #c4c4c4', padding: 10, backgroundColor: '#f5f5f5', width: '100%', }}>
                                            <div className="col-1" />
                                            <div className="col-2" style={{ display: 'flex', justifyContent: 'flex-end', maxWidth: '100%' }}>
d.arizona's avatar
d.arizona committed
2285 2286 2287 2288 2289 2290 2291
                                                <button
                                                    style={{
                                                        backgroundColor: 'transparent',
                                                        cursor: 'pointer',
                                                        borderColor: 'transparent',
                                                        outline: 'none',
                                                    }}
2292
                                                    onClick={() => this.handleApproveAdmin()}
d.arizona's avatar
d.arizona committed
2293 2294
                                                >
                                                    <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
2295
                                                        <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Approve</Typography>
d.arizona's avatar
d.arizona committed
2296 2297
                                                    </div>
                                                </button>
2298 2299
                                            </div>
                                        </div>
d.arizona's avatar
d.arizona committed
2300
                                        :
2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353
                                        this.state.checkApprover === true ?
                                            this.state.lastStatus === 'WAITING FOR REVIEW' ?
                                                <div style={{ borderTop: 'solid 1px #c4c4c4', padding: 10, backgroundColor: '#f5f5f5', width: '100%', display: 'flex', justifyContent: 'flex-end' }} >
                                                    <button
                                                        style={{
                                                            backgroundColor: 'transparent',
                                                            cursor: 'pointer',
                                                            borderColor: 'transparent',
                                                            outline: 'none',
                                                        }}
                                                        onClick={() =>
                                                            this.approvalSubmission('review')
                                                        }
                                                    >
                                                        <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                                            <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Review</Typography>
                                                        </div>
                                                    </button>
                                                </div> : (this.state.lastStatus === 'WAITING FOR YOUR APPROVAL' && this.state.btnApprove) ?
                                                    <div className="grid grid-2x" style={{ borderTop: 'solid 1px #c4c4c4', padding: 10, backgroundColor: '#f5f5f5', width: '100%', }}>
                                                        <div className="col-1">
                                                            <button
                                                                style={{
                                                                    backgroundColor: 'transparent',
                                                                    cursor: 'pointer',
                                                                    borderColor: 'transparent',
                                                                    outline: 'none',
                                                                }}
                                                                onClick={() => this.setState({ visibleRevision: true })}
                                                            >
                                                                <div style={{ backgroundColor: '#019ce5', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                                                    <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Revision</Typography>
                                                                </div>
                                                            </button>
                                                        </div>
                                                        <div className="col-2" style={{ display: 'flex', justifyContent: 'flex-end', maxWidth: '100%' }}>
                                                            <button
                                                                style={{
                                                                    backgroundColor: 'transparent',
                                                                    cursor: 'pointer',
                                                                    borderColor: 'transparent',
                                                                    outline: 'none',
                                                                }}
                                                                onClick={() => this.approvalSubmission('approve')}
                                                            >
                                                                <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                                                    <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Approve</Typography>
                                                                </div>
                                                            </button>
                                                        </div>
                                                    </div> : null
                                            :
                                            (this.state.lastStatus === 'SUBMIT' || this.state.lastStatus === 'REVISION') && this.state.isSubmit === true ?
d.arizona's avatar
d.arizona committed
2354 2355 2356 2357 2358 2359 2360 2361
                                                <div style={{ borderTop: 'solid 1px #c4c4c4', padding: 10, backgroundColor: '#f5f5f5', width: '100%', display: 'flex', justifyContent: 'flex-end' }} >
                                                    <button
                                                        style={{
                                                            backgroundColor: 'transparent',
                                                            cursor: 'pointer',
                                                            borderColor: 'transparent',
                                                            outline: 'none',
                                                        }}
2362
                                                        onClick={() => this.validate()}
d.arizona's avatar
d.arizona committed
2363
                                                    >
2364 2365
                                                        <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                                            <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Submit</Typography>
d.arizona's avatar
d.arizona committed
2366 2367
                                                        </div>
                                                    </button>
2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384
                                                </div> :
                                                this.state.lastStatus === 'SUBMITTED' && this.state.submitter ?
                                                    <div style={{ borderTop: 'solid 1px #c4c4c4', padding: 10, backgroundColor: '#f5f5f5', width: '100%', display: 'flex', justifyContent: 'flex-end' }} >
                                                        <button
                                                            style={{
                                                                backgroundColor: 'transparent',
                                                                cursor: 'pointer',
                                                                borderColor: 'transparent',
                                                                outline: 'none',
                                                            }}
                                                            onClick={() => this.approvalSubmission('cancel')}
                                                        >
                                                            <div style={{ backgroundColor: 'gray', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                                                <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Cancel</Typography>
                                                            </div>
                                                        </button>
                                                    </div> : null
EKSAD's avatar
EKSAD committed
2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425
                                }
                            </Paper>

                        </div>
                    </div>
                )}

                {this.state.visibleUpload && (
                    <div className="test app-popup-show">
                        <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
                            <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
                                <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                                    <div className="popup-title">
                                        <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Upload File</span>
                                    </div>
                                </div>
                                <div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
                                    <button
                                        type="button"
                                        className="btn btn-circle btn-white"
                                        onClick={() => this.setState({ visibleUpload: false })}
                                    >
                                        <img src={Images.close} />
                                    </button>
                                </div>
                            </div>
                            <UploadFile
                                type={this.state.uploadStatus}
                                percentage={this.state.percentage}
                                result={this.state.result}
                                acceptedFiles={["xlsx"]}
                                onHandle={(dt) => {
                                    this.fileHandler(dt)
                                    this.setState({ uploadStatus: 'idle', percentage: '0' })
                                }}
                                onUpload={() => this.uploadAttachment(this.state.formData)}
                            />
                        </div>
                    </div>
                )}

EKSAD's avatar
EKSAD committed
2426
                {this.state.visibleBS && (
Deni Rinaldi's avatar
Deni Rinaldi committed
2427
                    <BalanceSheetOLPA
EKSAD's avatar
EKSAD committed
2428 2429 2430 2431 2432
                        open={this.props.open}
                        report_id={this.state.report_id}
                        height={this.props.height}
                        width={this.props.width}
                        company={this.state.company}
2433 2434
                        defaultCurrency={this.state.defaultCurrency}
                        currency={this.state.currency}
EKSAD's avatar
EKSAD committed
2435 2436
                        revision={this.state.revisionTable}
                        periode={this.state.periode.periode}
Deni Rinaldi's avatar
Deni Rinaldi committed
2437 2438
                        outlook_pa_id={this.state.outlook_pa_id}
                        saveToOLPA={this.saveToOLPA.bind(this)}
EKSAD's avatar
EKSAD committed
2439
                        onClickClose={() => this.setState({ visibleBS: false, visibleOutlookPA: true })}
Deni Rinaldi's avatar
Deni Rinaldi committed
2440
                        getReport={this.getOutlookPAID.bind(this)}
EKSAD's avatar
EKSAD committed
2441 2442
                        isApprover={this.state.isApprover}
                        lastStatus={this.state.lastStatus}
EKSAD's avatar
EKSAD committed
2443
                        prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
EKSAD's avatar
EKSAD committed
2444 2445
                        status={this.state.status}
                    />
Deni Rinaldi's avatar
Deni Rinaldi committed
2446
                )}
EKSAD's avatar
EKSAD committed
2447 2448
                {this.state.visiblePL && (
                    <ProfitLossOLPA
EKSAD's avatar
EKSAD committed
2449 2450 2451 2452 2453
                        open={this.props.open}
                        report_id={this.state.report_id}
                        height={this.props.height}
                        width={this.props.width}
                        company={this.state.company}
2454 2455
                        defaultCurrency={this.state.defaultCurrency}
                        currency={this.state.currency}
EKSAD's avatar
EKSAD committed
2456 2457
                        revision={this.state.revisionTable}
                        periode={this.state.periode.periode}
Deni Rinaldi's avatar
Deni Rinaldi committed
2458 2459
                        outlook_pa_id={this.state.outlook_pa_id}
                        saveToOLPA={this.saveToOLPA.bind(this)}
EKSAD's avatar
EKSAD committed
2460
                        onClickClose={() => this.setState({ visiblePL: false, visibleOutlookPA: true })}
Deni Rinaldi's avatar
Deni Rinaldi committed
2461
                        getReport={this.getOutlookPAID.bind(this)}
EKSAD's avatar
EKSAD committed
2462 2463 2464
                        status={this.state.status}
                        isApprover={this.state.isApprover}
                        lastStatus={this.state.lastStatus}
EKSAD's avatar
EKSAD committed
2465
                        prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
EKSAD's avatar
EKSAD committed
2466 2467 2468 2469 2470 2471 2472 2473 2474 2475
                    />

                )}
                {this.state.visibleTP && (
                    <TaxPlanning
                        open={this.props.open}
                        report_id={this.state.report_id}
                        height={this.props.height}
                        width={this.props.width}
                        company={this.state.company}
2476 2477
                        defaultCurrency={this.state.defaultCurrency}
                        currency={this.state.currency}
EKSAD's avatar
EKSAD committed
2478 2479
                        revision={this.state.revisionTable}
                        periode={this.state.periode.periode}
Deni Rinaldi's avatar
Deni Rinaldi committed
2480 2481
                        outlook_pa_id={this.state.outlook_pa_id}
                        saveToOLPA={this.saveToOLPA.bind(this)}
EKSAD's avatar
EKSAD committed
2482
                        onClickClose={() => this.setState({ visibleTP: false, visibleOutlookPA: true })}
Deni Rinaldi's avatar
Deni Rinaldi committed
2483
                        getReport={this.getOutlookPAID.bind(this)}
EKSAD's avatar
EKSAD committed
2484 2485 2486
                        status={this.state.status}
                        isApprover={this.state.isApprover}
                        lastStatus={this.state.lastStatus}
EKSAD's avatar
EKSAD committed
2487
                        prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
d.arizona's avatar
d.arizona committed
2488 2489 2490 2491 2492 2493 2494 2495 2496
                    />
                )}
                {this.state.visibleCF && (
                    <CashFlow
                        open={this.props.open}
                        report_id={this.state.report_id}
                        height={this.props.height}
                        width={this.props.width}
                        company={this.state.company}
2497 2498
                        defaultCurrency={this.state.defaultCurrency}
                        currency={this.state.currency}
d.arizona's avatar
d.arizona committed
2499 2500 2501 2502 2503 2504 2505 2506 2507 2508
                        revision={this.state.revisionTable}
                        periode={this.state.periode.periode}
                        outlook_pa_id={this.state.outlook_pa_id}
                        saveToOLPA={this.saveToOLPA.bind(this)}
                        onClickClose={() => this.setState({ visibleCF: false, visibleOutlookPA: true })}
                        getReport={this.getOutlookPAID.bind(this)}
                        status={this.state.status}
                        isApprover={this.state.isApprover}
                        lastStatus={this.state.lastStatus}
                        prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
d.arizona's avatar
d.arizona committed
2509
                        PLBSFAMSubmitted={this.state.lastStatus == 'APPROVED' ? true : false}
EKSAD's avatar
EKSAD committed
2510
                    />
EKSAD's avatar
EKSAD committed
2511
                )}
faisalhamdi's avatar
faisalhamdi committed
2512 2513 2514 2515 2516 2517 2518
                {this.state.visibleCAT && (
                    <CorporateAnnualTargetOLPA
                        open={this.props.open}
                        report_id={this.state.report_id}
                        height={this.props.height}
                        width={this.props.width}
                        company={this.state.company}
2519 2520
                        defaultCurrency={this.state.defaultCurrency}
                        currency={this.state.currency}
faisalhamdi's avatar
faisalhamdi committed
2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532
                        revision={this.state.revisionTable}
                        periode={this.state.periode.periode}
                        outlook_pa_id={this.state.outlook_pa_id}
                        saveToOLPA={this.saveToOLPA.bind(this)}
                        onClickClose={() => this.setState({ visibleCAT: false, visibleOutlookPA: true })}
                        getReport={this.getOutlookPAID.bind(this)}
                        isApprover={this.state.isApprover}
                        lastStatus={this.state.lastStatus}
                        prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
                        status={this.state.status}
                    />
                )}
EKSAD's avatar
EKSAD committed
2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553

                {this.state.visibleRevision && (
                    <div className="test app-popup-show">
                        <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
                            <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
                                <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                                    <div className="popup-title">
                                        <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Revision</span>
                                    </div>
                                </div>
                                <div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
                                    <button
                                        type="button"
                                        className="btn btn-circle btn-white"
                                        onClick={() => this.setState({ visibleRevision: false })}
                                    >
                                        <img src={Images.close} />
                                    </button>
                                </div>
                            </div>
                            <div className="border-bottom" style={{ padding: 20 }}>
EKSAD's avatar
EKSAD committed
2554
                                <span>You ask your subsidiary to make a revision</span>
EKSAD's avatar
EKSAD committed
2555 2556 2557 2558 2559 2560 2561 2562 2563 2564
                                <div style={{ marginTop: 20 }}>
                                    <MuiThemeProvider theme={getMuiTheme()}>
                                        <MUIDataTable
                                            data={this.state.dataTableRevision}
                                            columns={columnRevisi}
                                            options={optionsRevision}
                                        />
                                    </MuiThemeProvider>
                                </div>
                                <div style={{ marginTop: 20 }}>
EKSAD's avatar
EKSAD committed
2565
                                    <span>Timing duration you give for revision:</span>
EKSAD's avatar
EKSAD committed
2566 2567 2568 2569 2570 2571 2572
                                    <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 20 }}>
                                        <div>
                                            <DatePicker
                                                margin="normal"
                                                id="startDate"
                                                label="Valid From"
                                                format="dd-MM-yyyy"
EKSAD's avatar
EKSAD committed
2573 2574 2575
                                                // onChange={(e) => null}
                                                onChange={(e) => this.setState({ minDateRevision: moment(e).format('YYYY/MM/DD') }, () => this.setState({ maxDateRevision: handleMaxDate() }))}
                                                value={moment(this.state.minDateRevision).format('YYYY/MM/DD')}
EKSAD's avatar
EKSAD committed
2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593
                                                KeyboardButtonProps={{
                                                    'aria-label': 'change date',
                                                }}
                                                inputProps={{
                                                    style: {
                                                        fontSize: 11
                                                    }
                                                }}
                                                InputLabelProps={{
                                                    style: {
                                                        fontSize: 11,
                                                        color: '#7e8085'
                                                    }
                                                }}

                                                style={{ padding: 0, margin: 0, width: '100%' }}
                                            />
                                        </div>
EKSAD's avatar
EKSAD committed
2594
                                        <span style={{ alignSelf: 'center' }}>Until</span>
EKSAD's avatar
EKSAD committed
2595 2596 2597 2598 2599 2600
                                        <div>
                                            <DatePicker
                                                margin="normal"
                                                id="startDate"
                                                label="Valid To"
                                                format="dd-MM-yyyy"
EKSAD's avatar
EKSAD committed
2601 2602 2603 2604
                                                // onChange={(e) => null}
                                                onChange={(e) => this.setState({ maxDateRevision: moment(e).format('YYYY/MM/DD') })}
                                                minDate={moment(this.state.minDateRevision).format('YYYY/MM/DD')}
                                                value={moment(this.state.maxDateRevision).format('YYYY/MM/DD')}
EKSAD's avatar
EKSAD committed
2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639
                                                KeyboardButtonProps={{
                                                    'aria-label': 'change date',
                                                }}
                                                inputProps={{
                                                    style: {
                                                        fontSize: 11
                                                    }
                                                }}
                                                InputLabelProps={{
                                                    style: {
                                                        fontSize: 11,
                                                        color: '#7e8085'
                                                    }
                                                }}

                                                style={{ padding: 0, margin: 0, width: '100%' }}
                                            />
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div className="border-top grid grid-2x" style={{ height: 56, backgroundColor: '#f5f5f5', paddingLeft: 20, paddingRight: 20 }}>
                                <div className="column-1" style={{ alignSelf: 'center' }}>
                                    <button
                                        type="button"
                                        onClick={() => this.setState({ visibleRevision: false })}
                                    >
                                        <div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                            <span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
                                        </div>
                                    </button>
                                </div>
                                <div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
                                    <button
                                        type="button"
Deni Rinaldi's avatar
Deni Rinaldi committed
2640
                                        onClick={() => this.validateRevision()}
EKSAD's avatar
EKSAD committed
2641 2642 2643 2644 2645 2646 2647 2648 2649 2650
                                    >
                                        <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                            <span style={{ color: '#fff', fontSize: 11 }}>Revision</span>
                                        </div>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                )}
2651

Faisal Hamdi's avatar
Faisal Hamdi committed
2652
                {this.state.visibleApproveSuperadmin && (
2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701
                    <div className="test app-popup-show">
                        <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
                            <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
                                <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                                    <div className="popup-title">
                                        <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Superadmin Approve</span>
                                    </div>
                                </div>
                                <div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
                                    <button
                                        type="button"
                                        className="btn btn-circle btn-white"
                                        onClick={() => this.setState({ visibleApproveSuperadmin: false })}
                                    >
                                        <img src={Images.close} />
                                    </button>
                                </div>
                            </div>
                            <div className="border-bottom" style={{ padding: 20 }}>
                                <span>Choose approver you want</span>
                                <div style={{ marginTop: 20 }}>
                                    <Autocomplete
                                        {...this.state.listApprover}
                                        id="periode"
                                        onChange={(event, newInputValue) => this.setState({ approver: newInputValue })}
                                        disabled={false}
                                        disableClearable
                                        style={{ width: 250 }}
                                        renderInput={(params) =>
                                            <TextField {...params} label="Approver" margin="normal" style={{ marginTop: 7 }}
                                            />}
                                        value={this.state.approver}
                                    />
                                </div>
                            </div>
                            <div className="border-top grid grid-2x" style={{ height: 56, backgroundColor: '#f5f5f5', paddingLeft: 20, paddingRight: 20 }}>
                                <div className="column-1" style={{ alignSelf: 'center' }}>
                                    <button
                                        type="button"
                                        onClick={() => this.setState({ visibleApproveSuperadmin: false })}
                                    >
                                        <div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                            <span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
                                        </div>
                                    </button>
                                </div>
                                <div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
                                    <button
                                        type="button"
Faisal Hamdi's avatar
Faisal Hamdi committed
2702
                                        onClick={() => this.state.approver == null ? this.setState({ alert: true, messageAlert: 'Approver Cannot be Empty', tipeAlert: 'error' }) : this.setHeaderTokenSuperadmin('approve')}
2703 2704 2705 2706 2707 2708 2709 2710 2711 2712
                                    >
                                        <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                            <span style={{ color: '#fff', fontSize: 11 }}>Confirm  Approve</span>
                                        </div>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                )}
qorri_di's avatar
qorri_di committed
2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741

                {this.state.popupDownload && (
                    <div className="test app-popup-show">
                        <div className="popup-content border-radius" style={{ background: '#D9D9D9', borderRadius: 10, width: 609, height: 276 }}>
                            <div>
                                <div style={{ justifyContent: 'center', fontSize: 20, color: '#33508B', margin: '70px 20px' }}>Download Outlook Performance Appraisal {this.state.company.company_name} {this.state.periode.periode} In Progress, silahkan cek status dan unduh report di menu <b>Download Report</b></div>
                                <div style={{ display: 'flex', justifyContent: 'flex-end' }}>
                                    <button
                                        className="button"
                                        type="button"
                                        style={{
                                            background: '#F6F7F9',
                                            cursor: 'pointer',
                                            border: '1px solid #3549609e',
                                            outline: 'none',
                                            marginRight: 20,
                                            borderRadius: 3
                                        }}
                                        onClick={() => this.setState({ popupDownload: false })}
                                    >
                                        <div style={{ backgroundColor: '#fff', width: 105, height: 30, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #3549609e' }}>
                                            <Typography style={{ fontSize: '15px', color: '#354960', textAlign: 'center' }}>Close</Typography>
                                        </div>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                )}
Riri Novita's avatar
Riri Novita committed
2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777

                {this.state.visibleAlertSave && (
                    <div className="test app-popup-show">
                        <div className="popup-content border-radius" style={{ background: '#FFF27D', borderRadius: 10, width: 715, height: 238 }}>
                            <div style={{ margin: 30 }}>
                                <div style={{ display: 'flex', marginTop: 76, marginBottom: 43 }}>
                                    <div style={{ alignSelf: 'center', marginRight: 25 }}>
                                        <img src={Images.warning} />
                                    </div>
                                    <div style={{ justifyContent: 'center', fontSize: 20, color: '#1D2995', marginTop: 10 }}>
                                        <b>Rate Currency USD</b> pada periode yang dipilih <b>belum</b> diatur.<br /> Silahkan menghubungi Superadmin
                                    </div>
                                </div>
                                <div style={{ display: 'flex', justifyContent: 'flex-end' }}>
                                    <button
                                        className="button"
                                        type="button"
                                        style={{
                                            background: '#F6F7F9',
                                            cursor: 'pointer',
                                            border: '1px solid #3549609e',
                                            outline: 'none',
                                            marginRight: 20,
                                            borderRadius: 9
                                        }}
                                        onClick={() => this.setState({ visibleAlertSave: false, loading: false })}
                                    >
                                        <div style={{ backgroundColor: '#fff', width: 105, height: 30, borderRadius: 9, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #3549609e' }}>
                                            <Typography style={{ fontSize: '15px', color: '#354960', textAlign: 'center' }}>Close</Typography>
                                        </div>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                )}
EKSAD's avatar
EKSAD committed
2778 2779 2780 2781
            </div >
        );
    }
}