OutlookPA.js 75.7 KB
Newer Older
EKSAD's avatar
EKSAD committed
1 2 3 4 5 6 7 8
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';
import Images from '../assets/Images';
import api from '../api';
import Autocomplete from '@material-ui/lab/Autocomplete';
import MuiAlert from '@material-ui/lab/Alert';
import { titleCase } from '../library/Utils';
EKSAD's avatar
EKSAD committed
9
import ProfitLossOLPA from './OutlookPA/ProfitLossOLPA';
Rifka Kurnia Irfiana's avatar
Rifka Kurnia Irfiana committed
10
import TaxPlanning from './OutlookPA/TaxPlanningOLPA';
EKSAD's avatar
EKSAD committed
11 12 13 14 15 16
import { ExcelRenderer } from 'react-excel-renderer';
import UploadFile from "../library/Upload";
import { format } from 'date-fns';
import Constant from '../library/Constant';
import PropagateLoader from "react-spinners/PropagateLoader"
import { DatePicker } from '@material-ui/pickers';
Deni Rinaldi's avatar
Deni Rinaldi committed
17
import BalanceSheetOLPA from './OutlookPA/BalanceSheetOLPA';
EKSAD's avatar
EKSAD committed
18
import moment from 'moment';
EKSAD's avatar
EKSAD committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

var ct = require("../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable());

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

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,
            listAttachment: [],
            visibleUpload: false,
            revisionTable: null,
            alert: false,
            tipeAlert: '',
            messageAlert: '',
Deni Rinaldi's avatar
Deni Rinaldi committed
47
            outlook_pa_id: null,
EKSAD's avatar
EKSAD committed
48 49 50 51 52 53 54 55 56 57 58 59
            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
60
            latestPeriode: '',
EKSAD's avatar
EKSAD committed
61 62
            minDateRevision: new Date(),
            maxDateRevision: new Date(),
Deni Rinaldi's avatar
Deni Rinaldi committed
63
            btnApprove: false
EKSAD's avatar
EKSAD committed
64
        }
EKSAD's avatar
EKSAD committed
65
        this.myRef = React.createRef()
EKSAD's avatar
EKSAD committed
66 67 68
        this.fileHandler = this.fileHandler.bind(this);
    }

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

EKSAD's avatar
EKSAD committed
71 72 73 74
    componentDidMount() {
        this.setState({ loading: true })
        this.props.selectIndex('Outlook Performance Appraisal')
        if (this.props.location.state !== undefined) {
r.kurnia's avatar
r.kurnia committed
75 76
            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
77 78 79 80 81 82 83 84
                this.checkApprover()
            })
        } else {
            this.checkApprover()
        }
    }

    checkApprover() {
Deni Rinaldi's avatar
Deni Rinaldi committed
85
        api.create().checkApproverOLPA().then(response => {
EKSAD's avatar
EKSAD committed
86
            // console.log(response);
EKSAD's avatar
EKSAD committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100
            if (response.data.data.is_approver === true) {
                this.setState({ isApprover: true, checkApprover: true }, () =>
                    this.getPeriode())
            } else {
                this.setState({ isApprover: false, checkApprover: false }, () =>
                    this.getDetailUser())
            }
        })
    }

    getCompanySubmitted() {
        let body = {
            "periode": this.state.periode.periode
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
101
        api.create().getCompanySubmittedOLPA(body).then(response => {
d.arizona's avatar
d.arizona committed
102
            console.log(response);
EKSAD's avatar
EKSAD committed
103 104 105 106 107 108 109 110 111 112
            if (response.data) {
                if (response.data.status === 'success') {
                    let data = response.data.data
                    let companyData = data.map((item) => {
                        return {
                            company_id: item.company_id,
                            company_name: item.company_name,
                        }
                    })

d.arizona's avatar
d.arizona committed
113
                    if (companyData.length > 0) {
d.arizona's avatar
d.arizona committed
114 115 116
                        companyData = companyData.sort((a,b) => a.company_name.localeCompare(b.company_name))
                    }

EKSAD's avatar
EKSAD committed
117 118 119 120
                    let defaultProps = {
                        options: companyData,
                        getOptionLabel: (option) => titleCase(option.company_name),
                    };
r.kurnia's avatar
r.kurnia committed
121 122 123 124 125
                    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 ? companyData[0] : companyData[indexID] }, () => {
EKSAD's avatar
EKSAD committed
126
                        // // console.log(response.data.data);
EKSAD's avatar
EKSAD committed
127 128 129
                        if (response.data.data.length > 0) {
                            this.getRevision()
                        } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
130
                            this.setState({ listRevision: null, revision: null, dataTable: [], checkApprover: false, lastRevision: "", visibleTableHistory: false, loading: false })
EKSAD's avatar
EKSAD committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
                        }
                        // 
                    })
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                        if (response.data.message.includes("Someone Logged In")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listCompany: null, company: null })
            }
        })
    }

    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
156
        api.create().getOLPAAtt(payload).then(response => {
EKSAD's avatar
EKSAD committed
157
            // console.log(response)
EKSAD's avatar
EKSAD committed
158 159 160 161
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({ listAttachment: response.data.data })
                }
Riri Novita's avatar
Riri Novita committed
162 163 164 165 166 167 168 169 170
            } else {
                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                    if (response.data.message.includes("Someone Logged In")) {
                        setTimeout(() => {
                            localStorage.removeItem(Constant.TOKEN)
                            window.location.reload();
                        }, 1000);
                    }
                })
EKSAD's avatar
EKSAD committed
171
            }
EKSAD's avatar
EKSAD committed
172
            // console.log(response);
EKSAD's avatar
EKSAD committed
173 174 175 176 177 178 179 180 181
        })
    }

    getReport() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
            "report_type": "Outlook PA",
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
182
        api.create().getReportOLPA(payload).then(response => {
EKSAD's avatar
EKSAD committed
183
            // console.log(response);
EKSAD's avatar
EKSAD committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
            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,
                            Number(item.revision) > 0 ? (item.current_status == "not-yet" ? false : item.is_can_upload) : item.is_can_upload,
                            item.revision
                        ]
                    })
                    let dataTableRevision = response.data.data.map((item, index) => {
                        return [
                            item.report_id,
                            item.report_name,
                            ""
                        ]
                    })
EKSAD's avatar
EKSAD committed
204
                    // console.log(dataTable);
EKSAD's avatar
EKSAD committed
205
                    this.setState({ dataTable, loading: false, dataTableRevision, dataForRevision: response.data.data })
Riri Novita's avatar
Riri Novita committed
206 207 208 209 210 211 212 213 214
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                        if (response.data.message.includes("Someone Logged In")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
EKSAD's avatar
EKSAD committed
215 216 217 218 219 220 221 222 223 224 225 226
                }
            } 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
227
        api.create().getSubmitOLPA(body).then(response => {
EKSAD's avatar
EKSAD committed
228
            // console.log(response);
EKSAD's avatar
EKSAD committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242
            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
243
            // console.log(response);
EKSAD's avatar
EKSAD committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        this.setState({ userCompany: response.data.data.company }, () => {
                            this.getCompanyActive()
                        })
                    }
                }
            }
        })
    }

    getCompanyActive() {
        api.create().getPerusahaanActive().then((response) => {
d.arizona's avatar
d.arizona committed
258
            console.log(response);
EKSAD's avatar
EKSAD committed
259 260 261 262 263 264 265 266 267 268 269
            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
270 271 272 273
                    if (companyData.length > 0) {
                        companyData = companyData.sort((a,b) => a.company_name.localeCompare(b.company_name))
                    }

EKSAD's avatar
EKSAD committed
274 275 276 277 278 279 280 281
                    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
282 283 284 285 286 287 288
                    if (arrayBaru.length > 0) {
                        arrayBaru = arrayBaru.sort((a,b) => a.company_name.localeCompare(b.company_name))
                    }

                    console.log(companyData)
                    console.log(arrayBaru)
                    
EKSAD's avatar
EKSAD committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
                    let defaultProps = {
                        options: arrayBaru,
                        getOptionLabel: (option) => titleCase(option.company_name),
                    };
                    let index = arrayBaru.findIndex((val) => val.company_id == comID)
                    this.setState({ listCompany: defaultProps, company: arrayBaru.length < 1 ? companyData[0] : (index == -1 ? arrayBaru[0] : arrayBaru[index]) }, () => {
                        this.getLastPeriod()
                    })
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                        if (response.data.message.includes("Someone Logged In")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listCompany: null, company: null })
            }
        })
    }

    getLastPeriod() {
Deni Rinaldi's avatar
Deni Rinaldi committed
314
        api.create().getLastPeriodOLPA(this.state.company.company_id).then(response => {
EKSAD's avatar
EKSAD committed
315
            // console.log(response);
d.arizona's avatar
d.arizona committed
316
            let currentYear = new Date().getFullYear()
EKSAD's avatar
EKSAD committed
317
            if (response.data.status === "success") {
d.arizona's avatar
d.arizona committed
318
                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
319 320 321 322 323 324 325 326 327 328 329
                    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
330
            // console.log(currentYear)
EKSAD's avatar
EKSAD committed
331 332 333 334 335
            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
336
                            if (item >= 2000 && item <= (Number(currentYear) + 1)) {
EKSAD's avatar
EKSAD committed
337 338 339
                                data.push(item)
                            }
                        } else {
d.arizona's avatar
d.arizona committed
340
                            if ((item >= 2000) && (item == Number(this.state.lastPeriod) || item < Number(this.state.lastPeriod))) {
EKSAD's avatar
EKSAD committed
341 342 343 344 345 346 347 348 349 350 351 352 353
                                data.push(item)
                            }
                        }
                    })
                    let periodeData = data.map((item) => {
                        return {
                            periode: item,
                        }
                    })
                    let defaultProps = {
                        options: periodeData,
                        getOptionLabel: (option) => option.periode,
                    };
354
                    let periode = (this.state.lastPeriod == "" ? String(Number(currentYear) + 1) : this.state.lastPeriodProps == undefined ? Number(this.state.lastPeriod) : this.state.lastPeriodProps )
d.arizona's avatar
d.arizona committed
355
                    let index = data.sort((a, b) => a - b).findIndex((val) => val == periode)
EKSAD's avatar
EKSAD committed
356
                    // console.log(data)
EKSAD's avatar
EKSAD committed
357
                    // console.log(this.state.lastPeriod)
d.arizona's avatar
d.arizona committed
358
                    // console.log(periode)
EKSAD's avatar
EKSAD committed
359
                    // console.log(index)
EKSAD's avatar
EKSAD committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
                    this.setState({ listPeriode: defaultProps, periode: index === -1 ? periodeData[0] : periodeData[index] }, () => {
                        if (this.state.isApprover === true) {
                            this.getCompanySubmitted()
                        } else {
                            this.getRevision()
                        }
                    })
                }
            }
        })
    }

    getRevision() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode
        }
        api.create().getRevision(payload).then(response => {
EKSAD's avatar
EKSAD committed
378
            // console.log(response);
EKSAD's avatar
EKSAD committed
379 380 381 382 383 384 385 386 387 388 389 390 391
            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] }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
392
                        this.getOutlookPAID()
EKSAD's avatar
EKSAD committed
393 394 395 396 397 398
                    })
                }
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
399
    getOutlookPAID() {
EKSAD's avatar
EKSAD committed
400 401 402 403 404 405
        this.setState({ loading: true })
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
            "is_approver": this.state.isApprover
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
406
        api.create().getOutlookPAID(payload).then(response => {
d.arizona's avatar
d.arizona committed
407
            console.log(response)
EKSAD's avatar
EKSAD committed
408 409 410
            if (response) {
                if (response.data.status === "success") {
                    this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
411
                        outlook_pa_id: response.data.data.outlook_pa_id,
EKSAD's avatar
EKSAD committed
412 413 414 415
                        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
416
                        btnApprove: response.data.data.is_submit
EKSAD's avatar
EKSAD committed
417
                    }, () => {
EKSAD's avatar
EKSAD committed
418
                        // console.log(this.state.lastStatus);
EKSAD's avatar
EKSAD committed
419 420
                        this.historyApproval()
                        this.getLatestPeriodSubmit()
Deni Rinaldi's avatar
Deni Rinaldi committed
421
                        api.create().checkApproverOLPA().then(response => {
EKSAD's avatar
EKSAD committed
422
                            // console.log(response);
EKSAD's avatar
EKSAD committed
423 424 425
                            if (response.data.data.is_approver === true) {
                                this.setState({ isApprover: true, checkApprover: true })
                            } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
426
                                this.setState({ isApprover: false, checkApprover: false })
EKSAD's avatar
EKSAD committed
427 428 429 430 431
                            }

                        })
                    })
                } else {
Riri Novita's avatar
Riri Novita committed
432 433 434 435 436 437 438 439 440 441 442
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                        if (response.data.message.includes("Someone Logged In")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                } 
            } else {
                this.setState({ outlook_pa_id: null, loading: false })
EKSAD's avatar
EKSAD committed
443 444 445 446 447 448 449 450 451
            }
        })
    }

    historyApproval() {
        let body = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
452
        api.create().historyApprovalOLPA(body).then(response => {
EKSAD's avatar
EKSAD committed
453
            // console.log(response);
EKSAD's avatar
EKSAD committed
454 455 456 457
            if (response.data.data.length > 0) {
                let dataTableHistory = response.data.data.map(item => {
                    return [
                        item.pic,
EKSAD's avatar
EKSAD committed
458 459
                        item.status_approval,
                        // String(item.status_approval).replace('APPROVAL_PROCCESS', 'WAITING FOR APPROVAL').replace('- -', ''),
EKSAD's avatar
EKSAD committed
460 461 462 463 464 465 466 467 468 469 470
                        item.remarks,
                        item.item_revision,
                        item.history_approval_date
                    ]
                })
                this.setState({ dataTableHistory, visibleTableHistory: true })
            }
        })
    }

    approvalSubmission(type) {
EKSAD's avatar
EKSAD committed
471
        this.scrollToMyRef()
EKSAD's avatar
EKSAD committed
472 473 474 475 476 477
        this.setState({ loading: true })
        let body = {
            "approval_id": this.props.location.state == undefined ? this.state.approverID : this.state.rawData.approval_id,
            "status": type,
            "detail": this.state.detailRevisiCheck
        }
EKSAD's avatar
EKSAD committed
478 479 480 481 482
        let payload = {
            "company_id": this.state.company.company_id,
            "min_periode": moment(this.state.minDateRevision).format('YYYY-MM-DD'),
            "max_periode": moment(this.state.maxDateRevision).format('YYYY-MM-DD')
        }
EKSAD's avatar
EKSAD committed
483
        // console.log(payload)
d.arizona's avatar
d.arizona committed
484 485
         api.create().approvalSubmissionOLPA(body).then((res) => {
            console.log(res)
EKSAD's avatar
EKSAD committed
486
            this.setState({ loading: false }, () => {
d.arizona's avatar
d.arizona committed
487
                this.getOutlookPAID()
EKSAD's avatar
EKSAD committed
488 489
            })
            if (type == 'revision') {
d.arizona's avatar
d.arizona committed
490
                api.create().createPeriodeRevisionOLPA(payload).then((res) => console.log(res))
Deni Rinaldi's avatar
Deni Rinaldi committed
491
            }
EKSAD's avatar
EKSAD committed
492 493 494
        })
    }

EKSAD's avatar
EKSAD committed
495
    clickDetail(item, id, revision, status) {
EKSAD's avatar
EKSAD committed
496
        // console.log(this.state.dataForRevision);
EKSAD's avatar
EKSAD committed
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
        this.state.dataForRevision.map(i => {
            if (i.report_name === item) {
                if (i.revision !== revision) {
                    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,
                })
Deni Rinaldi's avatar
Deni Rinaldi committed
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
            } else
                if (item === 'Profit Loss') {
                    this.setState({
                        visibleOutlookPA: false,
                        visibleBS: false,
                        visiblePL: true,
                        visibleTP: false,
                    })
                }
                else if (item === 'Tax Planning') {
                    this.setState({
                        visibleOutlookPA: false,
                        visibleBS: false,
                        visiblePL: false,
                        visibleTP: true,
                    })
                }
        })
    }

    validateRevision(){
        let arrayRevisi = this.state.detailRevisiCheck
        let remarksKosong = 0
        arrayRevisi.map((item,index) => {
            if (item.remarks == "") {
                remarksKosong += 1
            }
EKSAD's avatar
EKSAD committed
545
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
546 547 548 549 550
        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
551
    }
EKSAD's avatar
EKSAD committed
552 553 554 555 556 557 558 559 560

    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
561
            // console.log(resp)
EKSAD's avatar
EKSAD committed
562
            if (err) {
EKSAD's avatar
EKSAD committed
563
                // console.log(err);
EKSAD's avatar
EKSAD committed
564 565 566 567 568 569 570 571 572 573 574 575 576
            }
            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
577
        api.create().uploadAttOLPA(formData).then(response => {
EKSAD's avatar
EKSAD committed
578 579 580
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({ visibleUpload: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
581
                        this.getOutlookPAID()
EKSAD's avatar
EKSAD committed
582
                    })
Riri Novita's avatar
Riri Novita committed
583 584 585 586 587 588 589 590 591 592
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                        if (response.data.message.includes("Someone Logged In")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                } 
EKSAD's avatar
EKSAD committed
593 594 595 596 597
            }
        })
    }

    deleteAttachment(item) {
Deni Rinaldi's avatar
Deni Rinaldi committed
598
        api.create().deleteAttOLPA(item.attachment_id).then(response => {
EKSAD's avatar
EKSAD committed
599 600
            if (response.data) {
                if (response.data.status === "success") {
Deni Rinaldi's avatar
Deni Rinaldi committed
601
                    this.getOutlookPAID()
Riri Novita's avatar
Riri Novita committed
602 603 604 605 606 607 608 609 610 611
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                        if (response.data.message.includes("Someone Logged In")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                } 
EKSAD's avatar
EKSAD committed
612 613 614 615 616 617 618 619
            }
        })
    }

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

Deni Rinaldi's avatar
Deni Rinaldi committed
620
    saveToOLPA(data) {
EKSAD's avatar
EKSAD committed
621
        this.setState({ loading: true })
EKSAD's avatar
EKSAD committed
622
        // console.log(JSON.stringify(data));
Deni Rinaldi's avatar
Deni Rinaldi committed
623
        api.create('UPLOAD').createReportOLPA(data).then(response => {
Riri Novita's avatar
Riri Novita committed
624
            console.log(response);
EKSAD's avatar
EKSAD committed
625 626
            if (response.data) {
                if (response.data.status === "success") {
Deni Rinaldi's avatar
Deni Rinaldi committed
627
                    this.getOutlookPAID()
EKSAD's avatar
EKSAD committed
628
                } else {
Riri Novita's avatar
Riri Novita committed
629 630 631 632 633 634 635 636
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false, handleTekTekTek: 0 }, () => {
                        document.body.style.overflow = 'unset';
                        if (response.data.message.includes("Someone Logged In")) {
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
EKSAD's avatar
EKSAD committed
637
                        this.getOutlookPAID()
EKSAD's avatar
EKSAD committed
638 639
                    })
                }
Riri Novita's avatar
Riri Novita committed
640 641 642 643 644 645
                // else {
                //     this.setState({ loading: false }, () => {
                //         // alert(response.data.message)
                //         this.getOutlookPAID()
                //     })
                // }
EKSAD's avatar
EKSAD committed
646 647
            } else {
                this.setState({ loading: false }, () => {
EKSAD's avatar
EKSAD committed
648 649
                    // alert(response.problem)
                    this.getOutlookPAID()
EKSAD's avatar
EKSAD committed
650 651 652 653 654 655 656 657
                })
            }
        })
    }

    async downloadAttachment(fileurl, name) {
        let length = name.split(".").length
        let fileType = name.split(".")[length - 1]
EKSAD's avatar
EKSAD committed
658
        // console.log(fileType);
faisalhamdi's avatar
faisalhamdi committed
659
        let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/outlook_pa/download_attachment?fileName=${fileurl}&&fileType=${fileType}`
EKSAD's avatar
EKSAD committed
660
        // console.log(url);
EKSAD's avatar
EKSAD committed
661
        let res = await fetch(
faisalhamdi's avatar
faisalhamdi committed
662
            `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/outlook_pa/download_attachment?fileName=${fileurl}&&fileType=${fileType}`
EKSAD's avatar
EKSAD committed
663 664 665 666 667 668 669
        )
        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
670
            a.download = 'Outlook Perfromance Appraisal.xlsx';
EKSAD's avatar
EKSAD committed
671 672 673 674 675 676 677 678 679
            a.click();
        }
    }

    validate() {
        this.setState({ loading: true })
        let array = []
        let canSubmit = true
        this.state.dataTable.map(item => {
EKSAD's avatar
EKSAD committed
680 681 682 683 684 685
            // if (item[1] !== 'Cash Flow') {
            //     if (item[3] !== "submitted" && item[3] !== 'approved') {
            //         canSubmit = false
            //         array.push(item[3])
            //     }
            // }
EKSAD's avatar
EKSAD committed
686 687 688 689 690 691 692 693
            // 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
694
                outlook_pa_id: this.state.outlook_pa_id
EKSAD's avatar
EKSAD committed
695
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
696
            api.create().submitOLPA(body).then(response => {
EKSAD's avatar
EKSAD committed
697
                // console.log(response);
EKSAD's avatar
EKSAD committed
698
                if (response.data) {
Deni Rinaldi's avatar
Deni Rinaldi committed
699
                    if (response.data.status === "success") {
Deni Rinaldi's avatar
Deni Rinaldi committed
700
                        this.getOutlookPAID()
EKSAD's avatar
EKSAD committed
701 702 703 704 705 706 707
                    }
                }
            })
        } 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
708
        //     // console.log('gagal');
EKSAD's avatar
EKSAD committed
709
        // } else {
EKSAD's avatar
EKSAD committed
710
        //     // console.log('masuk');
EKSAD's avatar
EKSAD committed
711 712 713 714 715
        // }

    }

    render() {
EKSAD's avatar
EKSAD committed
716 717 718 719
        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
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
        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
738
                                                // console.log(event.target)
EKSAD's avatar
EKSAD committed
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
                                                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) => {
                        return (
                            <div style={{ display: 'flex' }}>
                                <button
                                    style={{
                                        backgroundColor: 'transparent',
                                        cursor: this.state.isSubmit === false ? 'default' : tableMeta.rowData[5] ? 'pointer' : 'default',
EKSAD's avatar
EKSAD committed
791
                                        // cursor: tableMeta.rowData[5] ? 'pointer' : 'default',
EKSAD's avatar
EKSAD committed
792 793 794
                                        borderColor: 'transparent'
                                    }}
                                    onClick={() =>
EKSAD's avatar
EKSAD committed
795 796 797
                                        tableMeta.rowData[5] == true ?
                                            this.clickDetail(tableMeta.rowData[1], tableMeta.rowData[4], tableMeta.rowData[2], tableMeta.rowData[3])
                                            : null
EKSAD's avatar
EKSAD committed
798 799 800 801 802 803
                                    }
                                >
                                    {/* {this.state.isApprover == true ? 
                                        (tableMeta.rowData[5] ? '#5198ea' : 'GrayText') :
                                        (this.state.lastRevision == 0 ? (tableMeta.rowData[5] ? '#5198ea' : 'GrayText') :
                                        (tableMeta.rowData[3] !== 'submitted' ? '#5198ea' : 'GrayText'))} */}
EKSAD's avatar
EKSAD committed
804
                                    <Typography style={{ color: tableMeta.rowData[5] ? '#5198ea' : 'GrayText', fontSize: 12, }}>Detail</Typography>
EKSAD's avatar
EKSAD committed
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
                                </button>
                            </div >
                        );
                    }
                }
            }, {
                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
865
                                                // console.log(event.target.value)
EKSAD's avatar
EKSAD committed
866 867
                                                // updateValue(event.target.value)
                                                handleChangeText(event.target.value, tableMeta)
EKSAD's avatar
EKSAD committed
868
                                                // console.log(dataTable2)
EKSAD's avatar
EKSAD committed
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
                                            }}
                                        />}
                                />
                            </div>
                        )
                    }
                }
            }
        ]

        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 })
        }

        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 })
EKSAD's avatar
EKSAD committed
906
            // console.log(detailRevisiCheck)
EKSAD's avatar
EKSAD committed
907 908 909 910 911 912 913 914 915 916 917 918 919
        }

        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
920 921 922 923 924 925 926 927 928 929 930 931
        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
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953
        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
954
            <div style={{ flex: 1, backgroundColor: '#f8f8f8' }} ref={this.myRef}>
EKSAD's avatar
EKSAD committed
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976
                <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 }}>
                                    <div>
                                        <Autocomplete
                                            {...this.state.listPeriode}
                                            id="periode"
                                            onChange={(event, newInputValue) => this.setState({ periode: newInputValue }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
977
                                                // console.log(this.state.isApprover, this.state.company);
EKSAD's avatar
EKSAD committed
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
                                                if (this.state.isApprover === true) {
                                                    this.getCompanySubmitted()
                                                } else {
                                                    this.setState({ visibleTableHistory: false })
                                                    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}
                                        />
                                    </div>
                                    <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()
                                            })}
                                            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 }}>
                                        <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
1039
                                        {!this.state.isApprover && (this.state.lastStatus === 'SUBMIT' || this.state.lastStatus === 'REVISION') && (
EKSAD's avatar
EKSAD committed
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
                                            <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
1085
                                        {!this.state.isApprover && (this.state.lastStatus === 'SUBMIT' || this.state.lastStatus === 'REVISION') && (
EKSAD's avatar
EKSAD committed
1086
                                            <div style={{ width: '50%' }}>
EKSAD's avatar
EKSAD committed
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
                                                {
                                                    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
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
                                                }
                                            </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
1117 1118 1119 1120 1121 1122 1123
                                                </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
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
                                        :
                                        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>
                                {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>
Deni Rinaldi's avatar
Deni Rinaldi committed
1172
                                        </div> : (this.state.lastStatus === 'WAITING FOR YOUR APPROVAL' && this.state.btnApprove) ?
EKSAD's avatar
EKSAD committed
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
                                            <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 ?
                                        <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.validate()}
                                            >
                                                <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>
                                                </div>
                                            </button>
                                        </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
                                }
                            </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
1279
                {this.state.visibleBS && (
Deni Rinaldi's avatar
Deni Rinaldi committed
1280
                    <BalanceSheetOLPA
EKSAD's avatar
EKSAD committed
1281 1282 1283 1284 1285 1286 1287
                        open={this.props.open}
                        report_id={this.state.report_id}
                        height={this.props.height}
                        width={this.props.width}
                        company={this.state.company}
                        revision={this.state.revisionTable}
                        periode={this.state.periode.periode}
Deni Rinaldi's avatar
Deni Rinaldi committed
1288 1289
                        outlook_pa_id={this.state.outlook_pa_id}
                        saveToOLPA={this.saveToOLPA.bind(this)}
EKSAD's avatar
EKSAD committed
1290
                        onClickClose={() => this.setState({ visibleBS: false, visibleOutlookPA: true })}
Deni Rinaldi's avatar
Deni Rinaldi committed
1291
                        getReport={this.getOutlookPAID.bind(this)}
EKSAD's avatar
EKSAD committed
1292 1293
                        isApprover={this.state.isApprover}
                        lastStatus={this.state.lastStatus}
EKSAD's avatar
EKSAD committed
1294
                        prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
EKSAD's avatar
EKSAD committed
1295 1296
                        status={this.state.status}
                    />
Deni Rinaldi's avatar
Deni Rinaldi committed
1297
                )}
EKSAD's avatar
EKSAD committed
1298 1299
                {this.state.visiblePL && (
                    <ProfitLossOLPA
EKSAD's avatar
EKSAD committed
1300 1301 1302 1303 1304 1305 1306
                        open={this.props.open}
                        report_id={this.state.report_id}
                        height={this.props.height}
                        width={this.props.width}
                        company={this.state.company}
                        revision={this.state.revisionTable}
                        periode={this.state.periode.periode}
Deni Rinaldi's avatar
Deni Rinaldi committed
1307 1308
                        outlook_pa_id={this.state.outlook_pa_id}
                        saveToOLPA={this.saveToOLPA.bind(this)}
EKSAD's avatar
EKSAD committed
1309
                        onClickClose={() => this.setState({ visiblePL: false, visibleOutlookPA: true })}
Deni Rinaldi's avatar
Deni Rinaldi committed
1310
                        getReport={this.getOutlookPAID.bind(this)}
EKSAD's avatar
EKSAD committed
1311 1312 1313
                        status={this.state.status}
                        isApprover={this.state.isApprover}
                        lastStatus={this.state.lastStatus}
EKSAD's avatar
EKSAD committed
1314
                        prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
EKSAD's avatar
EKSAD committed
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326
                    />

                )}
                {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}
                        revision={this.state.revisionTable}
                        periode={this.state.periode.periode}
Deni Rinaldi's avatar
Deni Rinaldi committed
1327 1328
                        outlook_pa_id={this.state.outlook_pa_id}
                        saveToOLPA={this.saveToOLPA.bind(this)}
EKSAD's avatar
EKSAD committed
1329
                        onClickClose={() => this.setState({ visibleTP: false, visibleOutlookPA: true })}
Deni Rinaldi's avatar
Deni Rinaldi committed
1330
                        getReport={this.getOutlookPAID.bind(this)}
EKSAD's avatar
EKSAD committed
1331 1332 1333
                        status={this.state.status}
                        isApprover={this.state.isApprover}
                        lastStatus={this.state.lastStatus}
EKSAD's avatar
EKSAD committed
1334
                        prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
EKSAD's avatar
EKSAD committed
1335
                    />
EKSAD's avatar
EKSAD committed
1336
                )}
EKSAD's avatar
EKSAD committed
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357

                {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
1358
                                <span>You ask your subsidiary to make a revision</span>
EKSAD's avatar
EKSAD committed
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368
                                <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
1369
                                    <span>Timing duration you give for revision:</span>
EKSAD's avatar
EKSAD committed
1370 1371 1372 1373 1374 1375 1376
                                    <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
1377 1378 1379
                                                // 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
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397
                                                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
1398
                                        <span style={{ alignSelf: 'center' }}>Until</span>
EKSAD's avatar
EKSAD committed
1399 1400 1401 1402 1403 1404
                                        <div>
                                            <DatePicker
                                                margin="normal"
                                                id="startDate"
                                                label="Valid To"
                                                format="dd-MM-yyyy"
EKSAD's avatar
EKSAD committed
1405 1406 1407 1408
                                                // 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
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443
                                                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
1444
                                        onClick={() => this.validateRevision()}
EKSAD's avatar
EKSAD committed
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
                                    >
                                        <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>
                )}
            </div >
        );
    }
}