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

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

Deni Rinaldi's avatar
Deni Rinaldi committed
29 30
const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
Deni Rinaldi's avatar
Deni Rinaldi committed
31

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

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

d.arizona's avatar
d.arizona committed
119 120
    scrollToMyRef = () => window.scrollTo(0, this.myRef.current.offsetTop)

Deni Rinaldi's avatar
Deni Rinaldi committed
121
    componentDidMount() {
Deni Rinaldi's avatar
Deni Rinaldi committed
122
        this.setState({ loading: true }, () => {
idlanirined's avatar
idlanirined committed
123 124
            document.body.style.overflow = 'hidden';
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
125
        this.props.selectIndex('Master Budget & CAT')
Riri Novita's avatar
Riri Novita committed
126

Riri Novita's avatar
Riri Novita committed
127
        console.log(this.props);
Deni Rinaldi's avatar
Deni Rinaldi committed
128
        if (this.props.location.state !== undefined) {
Deni Rinaldi's avatar
Deni Rinaldi committed
129
            this.setState({ userType: this.props.location.state.userType, intent: 'Home', lastPeriod: this.props.location.state.rawData.periode, rawData: this.props.location.state.rawData }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
130 131
                this.getPermission()
                // this.checkApprover()
Deni Rinaldi's avatar
Deni Rinaldi committed
132 133
            })
        } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
134 135
            this.getPermission()
            // this.checkApprover()
Deni Rinaldi's avatar
Deni Rinaldi committed
136 137
        }
    }
Deni Rinaldi's avatar
Deni Rinaldi committed
138

Deni Rinaldi's avatar
Deni Rinaldi committed
139 140 141 142 143 144 145 146 147 148 149 150
    getPermission() {
        let payload = {
            menu: "Master Budget & CAT"
        }
        api.create().getPermission(payload).then(response => {
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({
                        btncreate: response.data.data.create,
                        btnedit: response.data.data.edit,
                        btndelete: response.data.data.delete,
                        // load: true
Deni Rinaldi's avatar
Deni Rinaldi committed
151
                    }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
152 153 154
                        this.checkApprover()
                    })
                } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
155
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
156
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Deni Rinaldi's avatar
Deni Rinaldi committed
157 158 159 160 161
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
162 163 164
                    })
                }
            } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
165
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
Deni Rinaldi's avatar
Deni Rinaldi committed
166 167 168
            }
        })
    }
Deni Rinaldi's avatar
Deni Rinaldi committed
169

Dida Adams Arizona's avatar
Dida Adams Arizona committed
170 171 172 173 174 175
    getRole(id) {
        api.create().getDetailRole(id).then((response) => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        // this.setState({ tempData: response.data.data, privileges: response.data.data.privileges })
d.arizona's avatar
d.arizona committed
176
                        // // // console.log(response.data.data)
Dida Adams Arizona's avatar
Dida Adams Arizona committed
177
                        if (String(response.data.data.role_name).toLocaleLowerCase() == 'superadmin') {
Deni Rinaldi's avatar
Deni Rinaldi committed
178
                            this.setState({ isAdmin: true })
Dida Adams Arizona's avatar
Dida Adams Arizona committed
179 180 181
                        }
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
182
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Dida Adams Arizona's avatar
Dida Adams Arizona committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
            }
        })
    }

idlanirined's avatar
idlanirined committed
199 200 201 202
    componentWillUnmount() {
        document.body.style.overflow = 'unset';
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
203 204
    checkApprover() {
        api.create().checkApprover().then(response => {
Riri Novita's avatar
Riri Novita committed
205
            console.log(response)
r.kurnia's avatar
r.kurnia committed
206 207
            if (response.data) {
                if (response.data.status === "success") {
Deni Rinaldi's avatar
Deni Rinaldi committed
208
                    if (response.data.data.is_approver === true) {
syadziy's avatar
syadziy committed
209
                        this.setState({ truelyApprover: true, isApprover: true, permissionhandle: true, checkApprover: true }, () => {
d.arizona's avatar
d.arizona committed
210 211
                            this.getPeriode()
                        })
Deni Rinaldi's avatar
Deni Rinaldi committed
212
                    } else {
syadziy's avatar
syadziy committed
213
                        this.setState({ truelyApprover: false, isApprover: false, permissionhandle: false, checkApprover: false }, () =>
Deni Rinaldi's avatar
Deni Rinaldi committed
214 215
                            this.getDetailUser())
                    }
r.kurnia's avatar
r.kurnia committed
216 217
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
218
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
r.kurnia's avatar
r.kurnia committed
219 220 221 222 223 224 225 226 227 228 229 230 231
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
232 233 234 235 236
    getCompanySubmitted() {
        let body = {
            "periode": this.state.periode.periode
        }
        api.create().getCompanySubmitted(body).then(response => {
d.arizona's avatar
d.arizona committed
237
            // // // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
238 239
            if (response.data) {
                if (response.data.status === 'success') {
idlanirined's avatar
idlanirined committed
240 241 242 243 244 245 246 247
                    if (response.data.data.length > 0) {
                        let data = response.data.data
                        let companyData = data.map((item) => {
                            return {
                                company_id: item.company_id,
                                company_name: item.company_name,
                            }
                        })
Deni Rinaldi's avatar
Deni Rinaldi committed
248

d.arizona's avatar
d.arizona committed
249
                        if (companyData.length > 0) {
d.arizona's avatar
d.arizona committed
250
                            companyData = companyData.sort((a, b) => a.company_name.localeCompare(b.company_name))
d.arizona's avatar
d.arizona committed
251 252
                        }

idlanirined's avatar
idlanirined committed
253 254 255
                        let defaultProps = {
                            options: companyData,
                            getOptionLabel: (option) => titleCase(option.company_name),
256 257 258 259 260 261
                        }
                        let indexID = null
                        if (this.state.rawData !== undefined) {
                            indexID = companyData.findIndex((val) => val.company_id == this.state.rawData.company_id)
                        }

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

293 294 295 296 297 298 299
    getReportAttachment() {
        let payload = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
            "revision": this.state.revision.revision,
        }
        api.create().getMasterBudgetAtt(payload).then(response => {
d.arizona's avatar
d.arizona committed
300
            // // // console.log(response)
301 302 303 304 305
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({ listAttachment: response.data.data })
                }
            }
d.arizona's avatar
d.arizona committed
306
            // // // console.log(response);
307 308 309
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
310
    getReport() {
Deni Rinaldi's avatar
Deni Rinaldi committed
311 312
        let payload = {
            "company_id": this.state.company.company_id,
Deni Rinaldi's avatar
Deni Rinaldi committed
313
            "periode": this.state.periode.periode,
d.arizona's avatar
d.arizona committed
314
            "report_type": "Master Budget",
Riri Novita's avatar
Riri Novita committed
315
            "currency_id": this.state.defaultCurrency.id
Deni Rinaldi's avatar
Deni Rinaldi committed
316 317
        }
        api.create().getReportTypeBody(payload).then(response => {
Riri Novita's avatar
Riri Novita committed
318
            console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
319 320 321
            if (response.data) {
                if (response.data.status === "success") {
                    let dataTable = response.data.data.map((item, index) => {
d.arizona's avatar
d.arizona committed
322 323 324
                        let indexC = String(item.current_status).toLocaleUpperCase().indexOf('C')
                        let status_approv = ''
                        if (String(item.current_status).toLocaleUpperCase().includes('CC')) {
d.arizona's avatar
d.arizona committed
325
                            status_approv = `${String(item.current_status).substr(0, indexC)}${String(item.current_status).substr(indexC + 1, String(item.current_status).length)}`
d.arizona's avatar
d.arizona committed
326 327 328
                        } else {
                            status_approv = String(item.current_status)
                        }
d.arizona's avatar
d.arizona committed
329 330
                        const handleOpbal = (item) => {
                            let isUpload = false
331
                            if (Number(this.state.periode.periode) <= 2020) {
d.arizona's avatar
d.arizona committed
332 333 334 335 336 337
                                isUpload = true
                            } else {
                                isUpload = item
                            }
                            return isUpload
                        }
Riri Novita's avatar
Riri Novita committed
338 339 340
                        // console.log(this.state.lastStatus);
                        // console.log(this.state.isSubmit);
                        // console.log(status_approv);
Deni Rinaldi's avatar
Deni Rinaldi committed
341
                        return [
342
                            item.number,
idlanirined's avatar
idlanirined committed
343
                            item.report_name === 'CAT' ? 'Corporate Annual Target' : item.report_name,
344
                            item.revision,
d.arizona's avatar
d.arizona committed
345
                            this.state.lastStatus === 'APPROVED' ? 'CLOSED' : this.state.isSubmit === false ? "CLOSED" : status_approv,
346
                            item.report_id,
d.arizona's avatar
d.arizona committed
347
                            item.report_name === "Cash Flow" ? handleOpbal(item.is_can_upload) : (Number(item.revision) > 0 ? (item.current_status == "not-yet" ? false : handleOpbal(item.is_can_upload)) : handleOpbal(item.is_can_upload)),
348
                            item.revision
Deni Rinaldi's avatar
Deni Rinaldi committed
349 350
                        ]
                    })
Riri Novita's avatar
Riri Novita committed
351
                    // console.log(dataTable);
Deni Rinaldi's avatar
Deni Rinaldi committed
352 353
                    let dataTableRevision = []
                    response.data.data.map((item, index) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
354 355 356 357 358 359 360 361
                        if (item.report_name !== 'Cash Flow') {
                            dataTableRevision.push([
                                item.report_id,
                                item.report_name === 'CAT' ? 'Corporate Annual Target' : item.report_name,
                                "",
                                item.number
                            ])
                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
362
                    })
d.arizona's avatar
d.arizona committed
363
                    // // // console.log(dataTableRevision);
Riri Novita's avatar
Riri Novita committed
364
                    this.setState({ loading: false, dataTable, dataTableRevision: dataTableRevision.sort((a, b) => a.number - b.number), dataForRevision: response.data.data }, () => {
idlanirined's avatar
idlanirined committed
365 366
                        document.body.style.overflow = 'unset';
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
367
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
368
            } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
369
                this.setState({ loading: false }, () => {
idlanirined's avatar
idlanirined committed
370 371
                    document.body.style.overflow = 'unset';
                })
Deni Rinaldi's avatar
Deni Rinaldi committed
372 373 374 375
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
376 377 378 379 380 381
    getLatestPeriodSubmit() {
        let body = {
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode
        }
        api.create().getSubmitMasterBudget(body).then(response => {
Riri Novita's avatar
Riri Novita committed
382
            // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
383 384
            if (response.data) {
                if (response.data.status === "success") {
d.arizona's avatar
d.arizona committed
385
                    this.setState({ isSubmit: response.data.data.is_can_submit }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
386
                        this.getReportAttachment()
Riri Novita's avatar
Riri Novita committed
387
                        this.getReport()
Deni Rinaldi's avatar
Deni Rinaldi committed
388
                    })
Riri Novita's avatar
Riri Novita committed
389 390
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
391
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
392 393 394 395 396 397
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
398 399 400 401 402
                }
            }
        })
    }

Riri Novita's avatar
Riri Novita committed
403 404 405 406 407 408 409 410 411 412
    getCurrency(companyID) {
        // console.log(companyID);
        api.create().getDetailPerusahaan(companyID).then(response => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === "success") {
                        let data = response.data.data
                        let datas = []
                        if (response.data.data.currency.length > 0) {
                            response.data.data.currency.map((item) => {
Riri Novita's avatar
Riri Novita committed
413
                                // console.log(item);
Riri Novita's avatar
Riri Novita committed
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
                                datas.push({
                                    id: item.currencyId,
                                    value: item.currencyName
                                })

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

        })
    }

EKSAD's avatar
EKSAD committed
447 448 449 450 451 452
    getDetailUser() {
        let userId = localStorage.getItem(Constant.USER)
        api.create().getDetailUser(userId).then((response) => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
Dida Adams Arizona's avatar
Dida Adams Arizona committed
453
                        this.getRole(response.data.data.role_id)
Deni Rinaldi's avatar
Deni Rinaldi committed
454
                        this.setState({ userCompany: response.data.data.company }, () => {
EKSAD's avatar
EKSAD committed
455
                            this.getCompanyActive()
Deni Rinaldi's avatar
Deni Rinaldi committed
456
                        })
EKSAD's avatar
EKSAD committed
457 458
                    }
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
459
            }
EKSAD's avatar
EKSAD committed
460 461 462
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
463 464
    getCompanyActive() {
        api.create().getPerusahaanActive().then((response) => {
Riri Novita's avatar
Riri Novita committed
465
            // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
466 467 468
            if (response.data) {
                if (response.data.status === 'success') {
                    let data = response.data.data
Deni Rinaldi's avatar
Deni Rinaldi committed
469
                    let comID = this.state.rawData ? this.state.rawData.company_id : 0
Deni Rinaldi's avatar
Deni Rinaldi committed
470 471 472 473 474 475
                    let companyData = data.map((item) => {
                        return {
                            company_id: item.company_id,
                            company_name: item.company_name,
                        }
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
476

EKSAD's avatar
EKSAD committed
477
                    let arrayBaru = []
Deni Rinaldi's avatar
Deni Rinaldi committed
478
                    this.state.userCompany.map((item, index) => {
EKSAD's avatar
EKSAD committed
479 480 481 482 483
                        let indexID = companyData.findIndex((val) => val.company_id == item)
                        if (indexID !== -1) {
                            arrayBaru.push(companyData[indexID])
                        }
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
484

d.arizona's avatar
d.arizona committed
485
                    if (arrayBaru.length > 0) {
d.arizona's avatar
d.arizona committed
486
                        arrayBaru = arrayBaru.sort((a, b) => a.company_name.localeCompare(b.company_name))
d.arizona's avatar
d.arizona committed
487 488
                    }

Deni Rinaldi's avatar
Deni Rinaldi committed
489
                    let defaultProps = {
EKSAD's avatar
EKSAD committed
490
                        options: arrayBaru,
Deni Rinaldi's avatar
Deni Rinaldi committed
491 492
                        getOptionLabel: (option) => titleCase(option.company_name),
                    };
Deni Rinaldi's avatar
Deni Rinaldi committed
493
                    let index = arrayBaru.findIndex((val) => val.company_id == comID)
Deni Rinaldi's avatar
Deni Rinaldi committed
494
                    this.setState({ listCompany: defaultProps, company: arrayBaru.length < 1 ? companyData[0] : (index == -1 ? arrayBaru[0] : arrayBaru[index]) }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
495
                        this.getLastPeriod()
Deni Rinaldi's avatar
Deni Rinaldi committed
496 497 498
                    })
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
499
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Deni Rinaldi's avatar
Deni Rinaldi committed
500 501 502 503 504 505 506
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
507
            } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
508
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listCompany: null, company: null })
Deni Rinaldi's avatar
Deni Rinaldi committed
509 510 511 512
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
513
    getLastPeriod() {
r.kurnia's avatar
r.kurnia committed
514
        this.setState({ loading: false })
Deni Rinaldi's avatar
Deni Rinaldi committed
515
        api.create().getLastPeriod(this.state.company.company_id).then(response => {
Riri Novita's avatar
Riri Novita committed
516
            // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
517
            if (response.data.status === "success") {
d.arizona's avatar
d.arizona committed
518
                this.setState({ lastPeriod: this.state.userType !== '' ? this.state.lastPeriod : response.data.data.last_periode, latestPeriode: response.data.data.latest_periode }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
519 520 521 522 523 524
                    this.getPeriode()
                })
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
525
    getPeriode() {
526
        api.create().getPeriodeTransaction().then(response => {
Riri Novita's avatar
Riri Novita committed
527
            // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
528 529
            // let dateNow = new Date
            // let year = this.state.rawData ? this.state.rawData.periode : format(dateNow, 'yyyy')
d.arizona's avatar
d.arizona committed
530
            let currentYear = new Date().getFullYear()
d.arizona's avatar
d.arizona committed
531
            // // // console.log(currentYear)
532 533
            if (response.data) {
                if (response.data.status === "success") {
a.bairuha's avatar
a.bairuha committed
534 535
                    let data = []
                    response.data.data.map((item) => {
d.arizona's avatar
d.arizona committed
536 537 538 539 540 541 542 543
                        if (this.state.isApprover) {
                            if (item >= 2000 && item <= (Number(currentYear) + 1)) {
                                data.push(item)
                            }
                        } else {
                            if ((item >= 2000) && (item == this.state.lastPeriod || item < this.state.lastPeriod)) {
                                data.push(item)
                            }
a.bairuha's avatar
a.bairuha committed
544 545
                        }
                    })
546 547 548 549 550 551 552 553 554
                    let periodeData = data.map((item) => {
                        return {
                            periode: item,
                        }
                    })
                    let defaultProps = {
                        options: periodeData,
                        getOptionLabel: (option) => option.periode,
                    };
d.arizona's avatar
d.arizona committed
555
                    let periode = (this.state.lastPeriod == "" ? String(Number(currentYear)) : this.state.lastPeriod)
Deni Rinaldi's avatar
Deni Rinaldi committed
556
                    let index = data.sort((a, b) => a - b).findIndex((val) => val === periode)
d.arizona's avatar
d.arizona committed
557
                    // // console.log(this.props.location.state.rawData)
Riri Novita's avatar
Riri Novita committed
558 559 560
                    // console.log(this.state.lastPeriod)
                    // console.log(periode)
                    // console.log(index)
d.arizona's avatar
d.arizona committed
561 562
                    // console.log(periodeData)
                    // // // console.log(index)
Riri Novita's avatar
Riri Novita committed
563
                    console.log(this.state.isApprover);
Deni Rinaldi's avatar
Deni Rinaldi committed
564
                    this.setState({ listPeriode: defaultProps, periode: index === -1 ? periodeData[0] : periodeData[index] }, () => {
r.kurnia's avatar
r.kurnia committed
565
                        if (this.state.isApprover === true) {
Deni Rinaldi's avatar
Deni Rinaldi committed
566 567 568
                            this.getCompanySubmitted()
                        } else {
                            this.getRevision()
Riri Novita's avatar
Riri Novita committed
569
                            this.getCurrency(this.state.company.company_id)
Deni Rinaldi's avatar
Deni Rinaldi committed
570
                        }
571 572 573 574 575 576 577
                    })
                }
            }
        })
    }

    getRevision() {
qorri_di's avatar
qorri_di committed
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
        this.setState({ selectReport: [], isCheckAll: false }, () => {
            let payload = {
                "company_id": this.state.company.company_id,
                "periode": this.state.periode.periode
            }
            api.create().getRevision(payload).then(response => {
                // // // console.log(response);
                if (response.data) {
                    if (response.data.status === "success") {
                        let data = response.data.data
                        let revisionData = data.map((item) => {
                            return {
                                revision: item,
                            }
                        })
                        let defaultProps = {
                            options: revisionData,
                            getOptionLabel: (option) => option.revision,
                        };
                        this.setState({ listRevision: defaultProps, revision: revisionData[0] }, () => {
                            this.getSubmission()
                        })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
610
                } else {
qorri_di's avatar
qorri_di committed
611
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listRevision: null, revision: null })
Deni Rinaldi's avatar
Deni Rinaldi committed
612
                }
qorri_di's avatar
qorri_di committed
613
            })
Deni Rinaldi's avatar
Deni Rinaldi committed
614 615 616
        })
    }

Riri Novita's avatar
Riri Novita committed
617 618
    getSubmission(type, trigger) {
        console.log(trigger);
Deni Rinaldi's avatar
Deni Rinaldi committed
619
        this.setState({ loading: true }, () => {
idlanirined's avatar
idlanirined committed
620 621
            document.body.style.overflow = 'hidden';
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
622 623
        let payload = {
            "company_id": this.state.company.company_id,
Deni Rinaldi's avatar
Deni Rinaldi committed
624
            "periode": this.state.periode.periode,
Faisal Hamdi's avatar
Faisal Hamdi committed
625
            "is_approver": this.state.isAdmin && this.state.lastStatus == 'WAITING FOR APPROVAL' ? false : (this.state.permissionhandle ? this.state.permissionhandle : this.state.isApprover)
Deni Rinaldi's avatar
Deni Rinaldi committed
626
        }
d.arizona's avatar
d.arizona committed
627
        console.log(payload)
Deni Rinaldi's avatar
Deni Rinaldi committed
628
        api.create().getSubmission(payload).then(response => {
d.arizona's avatar
d.arizona committed
629
            console.log(response)
Deni Rinaldi's avatar
Deni Rinaldi committed
630
            if (response.data) {
Deni Rinaldi's avatar
Deni Rinaldi committed
631
                if (response.data.status === "success") {
Riri Novita's avatar
Riri Novita committed
632
                    if (type === "CAT" || type === "DraftCAT") {
Riri Novita's avatar
Riri Novita committed
633 634 635 636
                        this.setState({ visibleCAT: false, visibleBudgetTahunan: true, loading: false })
                    } else {
                        this.setState({ visibleBudgetTahunan: true, loading: false })
                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
637
                    this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
638
                        submissionID: response.data.data.submission_id,
a.bairuha's avatar
a.bairuha committed
639
                        submitter: response.data.data.submitter,
Deni Rinaldi's avatar
Deni Rinaldi committed
640
                        approverID: response.data.data.approve_id, pic: response.data.data.approver == null ? '' : response.data.data.approver,
Deni Rinaldi's avatar
Deni Rinaldi committed
641
                        lastStatus: response.data.data.last_status === null ? 'SUBMIT' : response.data.data.last_status,
Deni Rinaldi's avatar
Deni Rinaldi committed
642
                        lastRevision: response.data.data.last_revision,
d.arizona's avatar
d.arizona committed
643
                        btnApprove: response.data.data.is_submit,
Riri Novita's avatar
Riri Novita committed
644
                        loading: false
Deni Rinaldi's avatar
Deni Rinaldi committed
645
                    }, () => {
d.arizona's avatar
d.arizona committed
646 647
                        // // console.log(response.data.data.is_submit);
                        // // console.log(this.state.btnApprove)
Deni Rinaldi's avatar
Deni Rinaldi committed
648
                        this.historyApproval()
Deni Rinaldi's avatar
Deni Rinaldi committed
649
                        this.getLatestPeriodSubmit()
d.arizona's avatar
d.arizona committed
650 651
                        // this.getCashFlow(type)
                        // this.getPL(type)
652
                        if (this.state.isAdmin) {
Riri Novita's avatar
Riri Novita committed
653
                            // console.log('masuk')
Faisal Hamdi's avatar
Faisal Hamdi committed
654
                            api.create().getListApprover('master_budget', this.state.submissionID).then((response) => {
Riri Novita's avatar
Riri Novita committed
655
                                // console.log(response)
656 657
                                if (response.data.data) {
                                    let dataListApprover = []
Faisal Hamdi's avatar
Faisal Hamdi committed
658 659
                                    response.data.data.map((item, index) => {
                                        dataListApprover.push({ userId: item.user_id, fullname: item.fullname })
660 661 662 663 664
                                    })
                                    let defaultProps = {
                                        options: dataListApprover,
                                        getOptionLabel: (option) => option.fullname,
                                    };
Faisal Hamdi's avatar
Faisal Hamdi committed
665
                                    this.setState({ listApprover: defaultProps })
666 667 668
                                }
                            })
                        }
d.arizona's avatar
d.arizona committed
669
                        if (type != undefined && type == 'PL') {
d.arizona's avatar
d.arizona committed
670
                            // this.getCashFlow(type)
Riri Novita's avatar
Riri Novita committed
671
                            this.getPL(type, trigger)
Faisal Hamdi's avatar
Faisal Hamdi committed
672
                        } else if (type != undefined && type == 'BS') {
Riri Novita's avatar
Riri Novita committed
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
                            if (trigger === 'simulasiBS') {
                                let bodyRatioBs = {
                                    "report": 'ratio',
                                    "submissionId": this.state.submissionID,
                                    "periode": this.state.periode.periode,
                                    "companyId": this.state.company.company_id,
                                    "currency_id": this.state.defaultCurrency.id,
                                }
                                // console.log(bodyRatioBs);
                                api.create().triggerRatioMBSimulasi(bodyRatioBs).then((res) => {
                                    console.log(res)
                                    this.setState({ loading: false })
                                })
                            } else {
                                let bodyRatioBs = {
                                    "report": 'ratio',
                                    "submissionId": this.state.submissionID,
                                    "periode": this.state.periode.periode,
                                    "companyId": this.state.company.company_id,
                                    "currency_id": this.state.defaultCurrency.id,
                                }
                                // console.log(bodyRatioBs);
                                api.create().triggerRatioMB(bodyRatioBs).then((res) => {
                                    console.log(res)
                                    this.setState({ loading: false })
                                })
Faisal Hamdi's avatar
Faisal Hamdi committed
699
                            }
d.arizona's avatar
d.arizona committed
700
                        } else {
d.arizona's avatar
d.arizona committed
701
                            this.setState({ loading: false })
d.arizona's avatar
d.arizona committed
702
                        }
d.arizona's avatar
d.arizona committed
703
                        // this.getFR(type)
Deni Rinaldi's avatar
Deni Rinaldi committed
704
                        api.create().checkApprover().then(response => {
Riri Novita's avatar
Riri Novita committed
705 706 707
                            // console.log(this.state.btnedit)
                            // console.log(this.state.btncreate);
                            // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
708
                            if (this.state.btncreate === true && this.state.btnedit === true) {
Deni Rinaldi's avatar
Deni Rinaldi committed
709 710 711 712 713 714 715
                                this.setState({ isApprover: false }, () => {
                                    if (response.data.data.is_approver === true) {
                                        this.setState({ checkApprover: true })
                                    } else {
                                        this.setState({ checkApprover: false })
                                    }
                                })
Deni Rinaldi's avatar
Deni Rinaldi committed
716
                            } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
717 718 719 720 721 722 723
                                this.setState({ isApprover: true }, () => {
                                    if (response.data.data.is_approver === true) {
                                        this.setState({ checkApprover: true })
                                    } else {
                                        this.setState({ checkApprover: false })
                                    }
                                })
Deni Rinaldi's avatar
Deni Rinaldi committed
724 725 726
                            }

                        })
Deni Rinaldi's avatar
Deni Rinaldi committed
727
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
728 729 730
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', submissionID: null, loading: false }, () => {
                        document.body.style.overflow = 'unset';
d.arizona's avatar
d.arizona committed
731
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Deni Rinaldi's avatar
Deni Rinaldi committed
732 733 734 735 736 737 738 739 740 741
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
742 743 744
        })
    }

d.arizona's avatar
d.arizona committed
745 746 747 748 749 750
    getCashFlow(type) {
        let payload = {
            "report_id": 6,
            "revision": Number(this.state.lastRevision),
            "periode": this.state.periode.periode,
            "company_id": this.state.company.company_id,
Riri Novita's avatar
Riri Novita committed
751
            "currency_id": this.state.defaultCurrency.id,
d.arizona's avatar
d.arizona committed
752 753 754
            "submission_id": this.state.submissionID
        }
        api.create().getDetailReportCF(payload).then(response => {
755
            // console.log(response);
d.arizona's avatar
d.arizona committed
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 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
            let dataTable = []
            if (response.data) {
                let res = response.data.data
                const handlePushChild = (item) => {
                    let indexIDzz = dataTable.findIndex((val) => val[1] === item.id)
                    if (indexIDzz === -1) {
                        dataTable.push([
                            item.type_report_id,
                            item.id,
                            item.parent,
                            item.formula,
                            item.level,
                            item.description,
                            item.cash_flow.total_actual_before === null ? "0" : item.cash_flow.total_actual_before === "" ? "0" : item.cash_flow.total_actual_before,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.january, formula: item.cash_flow.january_formula } : item.cash_flow.january,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.february, formula: item.cash_flow.february_formula } : item.cash_flow.february,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.march, formula: item.cash_flow.march_formula } : item.cash_flow.march,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.april, formula: item.cash_flow.april_formula } : item.cash_flow.april,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.may, formula: item.cash_flow.may_formula } : item.cash_flow.may,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.june, formula: item.cash_flow.june_formula } : item.cash_flow.june,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.july, formula: item.cash_flow.july_formula } : item.cash_flow.july,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.august, formula: item.cash_flow.august_formula } : item.cash_flow.august,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.september, formula: item.cash_flow.september_formula } : item.cash_flow.september,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.october, formula: item.cash_flow.october_formula } : item.cash_flow.october,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.november, formula: item.cash_flow.november_formula } : item.cash_flow.november,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.december, formula: item.cash_flow.december_formula } : item.cash_flow.december,
                            item.cash_flow.total_current_year,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.cash_flow.total_next_year,
                            item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.cash_flow.total_more_year,
                            item.order,
                            item.condition_it_should_be,
                            item.condition_if_wrong,
                            item.cash_flow.forecast_formula == null ? [] : item.cash_flow.forecast_formula
                        ])
                    }
                    if (item.children !== null) {
                        if (item.children.length > 0) {
                            item.children.map((items, indexs) => {
                                handlePushChild(items)
                            })
                        }
                    }
                }
                res.map((item, index) => {
                    dataTable.push([
                        item.type_report_id,
                        item.id,
                        item.parent,
                        item.formula,
                        item.level,
                        item.description,
                        item.cash_flow.total_actual_before === null ? "0" : item.cash_flow.total_actual_before === "" ? "0" : item.cash_flow.total_actual_before,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.january, formula: item.cash_flow.january_formula } : item.cash_flow.january,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.february, formula: item.cash_flow.february_formula } : item.cash_flow.february,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.march, formula: item.cash_flow.march_formula } : item.cash_flow.march,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.april, formula: item.cash_flow.april_formula } : item.cash_flow.april,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.may, formula: item.cash_flow.may_formula } : item.cash_flow.may,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.june, formula: item.cash_flow.june_formula } : item.cash_flow.june,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.july, formula: item.cash_flow.july_formula } : item.cash_flow.july,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.august, formula: item.cash_flow.august_formula } : item.cash_flow.august,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.september, formula: item.cash_flow.september_formula } : item.cash_flow.september,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.october, formula: item.cash_flow.october_formula } : item.cash_flow.october,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.november, formula: item.cash_flow.november_formula } : item.cash_flow.november,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.cash_flow.december, formula: item.cash_flow.december_formula } : item.cash_flow.december,
                        item.cash_flow.total_current_year,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.cash_flow.total_next_year,
                        item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.cash_flow.total_more_year,
                        item.order,
                        item.condition_it_should_be,
                        item.condition_if_wrong,
                        item.cash_flow.forecast_formula == null ? [] : item.cash_flow.forecast_formula,
                    ])
                    if (item.children !== null) {
                        if (item.children.length > 0) {
                            item.children.map((items, indexs) => {
                                handlePushChild(items)
                            })
                        }
                    }
                })
Riri Novita's avatar
Riri Novita committed
836
                // console.log(dataTable)
d.arizona's avatar
d.arizona committed
837
                this.setState({ dbCF: dataTable }, () => {
d.arizona's avatar
d.arizona committed
838
                    this.olahDataCashFlow(this.state.dbCF, type)
d.arizona's avatar
d.arizona committed
839
                })
Riri Novita's avatar
Riri Novita committed
840 841
            } else {
                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
842
                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
843 844 845 846 847 848
                        setTimeout(() => {
                            localStorage.removeItem(Constant.TOKEN)
                            window.location.reload();
                        }, 1000);
                    }
                })
d.arizona's avatar
d.arizona committed
849 850 851 852 853 854 855 856 857 858 859 860 861 862
            }
        })
    }

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

        splitFormula.map((item, index) => {
            let items = String(item).substr(Number(String(item).length) - 1, 1)
            let subForm = String(item).substr(0, Number(String(item).length) - 1)
            let re = /^[a-zA-Z0-9_]+$/;
d.arizona's avatar
d.arizona committed
863
            if (item !== "" && item !== '@') {
d.arizona's avatar
d.arizona committed
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
                if (!re.test(items)) {
                    baru.push(subForm)
                    baru.push(items)
                } else {
                    baru.push(String(item))
                }
            }
        })

        baru.map((item, index) => {
            if (item == '-' || item == '+' || item == '/' || item == '*' || item == '(' || item == ')') {
                anjay.push(item)
            } else {
                if (String(item).includes('#')) {
                    if (String(item).includes('[M-1]')) {
                        if (forecast !== undefined) {
                            let forecastt = 0
d.arizona's avatar
d.arizona committed
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
                            if (column == 19) {
                                let tst = String(item).replace('[M-1]', '')
                                let data = 18
                                let period = this.state.periode.periode - 1
                                let indexID = tableMeta[data].formula.findIndex((val) => val.item_formula == String(`@${tst}`) && val.periode == period)
                                if (indexID !== -1) {
                                    let valuezz = tableMeta[data].formula[indexID].value
                                    if (tableMeta[5] == "Cash at the beginning period") {
                                        // console.log(dataTable2[tableMeta.rowIndex+1])
                                        // console.log(dataTable2[tableMeta.rowIndex+1][data].value)
                                        let valuezzz = dataTable2[indexDBCF + 1][data].value
                                        forecastt += Number(valuezzz == "" ? 0 : valuezzz)
                                    } else {
                                        forecastt += Number(valuezz == "" ? 0 : valuezz)
                                    }
                                }
                            }

d.arizona's avatar
d.arizona committed
899 900 901 902 903 904 905
                            if (column == 20) {
                                let tst = String(item).replace('[M-1]', '')
                                let data = 18
                                let period = this.state.periode.periode
                                let indexID = tableMeta[data].formula.findIndex((val) => val.item_formula == String(`@${tst}`) && val.periode == period)
                                if (indexID !== -1) {
                                    let valuezz = tableMeta[data].formula[indexID].value
d.arizona's avatar
d.arizona committed
906 907 908 909 910 911
                                    if (tableMeta[5] == "Cash at the beginning period") {
                                        let valuezzz = dataTable2[indexDBCF + 1][19]
                                        forecastt += Number(valuezzz == "" ? 0 : valuezzz)
                                    } else {
                                        forecastt += Number(valuezz == "" ? 0 : valuezz)
                                    }
d.arizona's avatar
d.arizona committed
912 913 914 915 916 917 918 919 920
                                }
                            }

                            if (column == 21) {
                                let tst = String(item).replace('[M-1]', '')
                                let period = Number(this.state.periode.periode) + 1
                                let indexID = forecast.findIndex((val) => String(val.item_formula).replace('forecast_', '') == String(`@${tst}`) && val.periode == period)
                                if (indexID !== -1) {
                                    let valuezz = forecast[indexID].value
d.arizona's avatar
d.arizona committed
921 922 923 924 925 926
                                    if (tableMeta[5] == "Cash at the beginning period") {
                                        let valuezzz = dataTable2[indexDBCF + 1][20]
                                        forecastt += Number(valuezzz == "" ? 0 : valuezzz)
                                    } else {
                                        forecastt += Number(valuezz == "" ? 0 : valuezz)
                                    }
d.arizona's avatar
d.arizona committed
927 928 929 930 931 932 933 934 935 936 937 938
                                }
                            }

                            anjay.push(forecastt)
                        } else {
                            let tst = String(item).replace('[M-1]', '')
                            let data = column == 7 ? 18 : column - 1
                            let period = data == 18 ? Number(this.state.periode.periode) - 1 : this.state.periode.periode
                            let indexID = tableMeta[data].formula.findIndex((val) => val.item_formula == String(`@${tst}`) && val.periode == period)

                            if (indexID !== -1) {
                                let valuezz = tableMeta[data].formula[indexID].value
d.arizona's avatar
d.arizona committed
939 940 941 942 943 944
                                if (tableMeta[5] == "Cash at the beginning period" && column != 7) {
                                    let valuezzz = dataTable2[indexDBCF + 1][data].value
                                    anjay.push(valuezzz == "" ? 0 : valuezzz)
                                } else {
                                    anjay.push(valuezz == "" ? 0 : valuezz)
                                }
d.arizona's avatar
d.arizona committed
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 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 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
                            }
                        }
                    } else {
                        if (forecast !== undefined) {
                            let indexID = forecast.findIndex((val) => String(val.item_formula).replace('forecast_', '') == String(`@${item}`) && val.periode == Number(periode))
                            if (indexID !== -1) {
                                let valuezz = forecast[indexID].value
                                anjay.push(valuezz == "" ? 0 : Number(valuezz))
                            }
                        } else {
                            let indexID = value.formula.findIndex((val) => val.item_formula == String(`@${item}`) && val.periode == Number(this.state.periode.periode))
                            if (indexID !== -1) {
                                let valuezz = value.formula[indexID].value
                                anjay.push(valuezz == "" ? 0 : valuezz)
                            }
                        }
                    }
                } else {
                    let indexID = dataTable2.findIndex((val) => val[22] == item)
                    if (indexID !== -1) {
                        let valuezz = dataTable2[indexID][column].value == undefined ? dataTable2[indexID][column] : dataTable2[indexID][column].value
                        if (item == dataTable2[indexDBCF][22]) {
                            anjay.push(0)
                        } else {
                            anjay.push(valuezz == "" ? 0 : valuezz)
                        }
                    } else {
                        if (item === '(-1)') {
                            anjay.push(-1)
                        }
                    }
                }
            }
        })

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

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

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

d.arizona's avatar
d.arizona committed
1135 1136 1137 1138 1139 1140 1141 1142
        // if(tableMeta[5] == '2.1 Additional fixed assets and CIP' && column == 7) {
        //     console.log(splitFormula)
        //     console.log(baru)
        //     console.log(anjay)
        //     console.log(anjay2)
        //     console.log(total)
        // }

1143
        total = R.equals(total, NaN) ? "0.0" : Number(total).toFixed(1)
d.arizona's avatar
d.arizona committed
1144 1145 1146 1147 1148 1149 1150 1151
        return total
    }

    handleForecast = (index, tableMeta, periode, column) => {
        let total = 0
        let dataTable2 = this.state.dbCF
        // let indexID = dataTable2.findIndex((val) => tableMeta[1] == val[1])
        // if (indexID != -1) {
d.arizona's avatar
d.arizona committed
1152
        total = this.handleValueFormula(index, dataTable2[index][column], tableMeta, column, periode, dataTable2[index][25])
d.arizona's avatar
d.arizona committed
1153 1154 1155 1156 1157
        // }
        return total
    }

    olahDataCashFlow(dbCF, type) {
d.arizona's avatar
d.arizona committed
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
        dbCF.map((item, index) => {
            if (item[0] == 5 || item[0] == 6 || item[0] == 7) {
                item[7].value = this.handleValueFormula(index, item[7], item, 7)
                item[8].value = this.handleValueFormula(index, item[8], item, 8)
                item[9].value = this.handleValueFormula(index, item[9], item, 9)
                item[10].value = this.handleValueFormula(index, item[10], item, 10)
                item[11].value = this.handleValueFormula(index, item[11], item, 11)
                item[12].value = this.handleValueFormula(index, item[12], item, 12)
                item[13].value = this.handleValueFormula(index, item[13], item, 13)
                item[14].value = this.handleValueFormula(index, item[14], item, 14)
                item[15].value = this.handleValueFormula(index, item[15], item, 15)
                item[16].value = this.handleValueFormula(index, item[16], item, 16)
                item[17].value = this.handleValueFormula(index, item[17], item, 17)
                item[18].value = this.handleValueFormula(index, item[18], item, 18)
                item[19] = this.handleForecast(index, item, `${Number(this.state.periode.periode)}`, 19)
d.arizona's avatar
d.arizona committed
1173 1174 1175 1176 1177
                item[20] = this.handleForecast(index, item, `${Number(this.state.periode.periode) + 1}`, 20)
                item[21] = this.handleForecast(index, item, `${Number(this.state.periode.periode) + 2}`, 21)
            }
        })
        // console.log(dbCF)
d.arizona's avatar
d.arizona committed
1178
        this.setState({ dbCF }, () => {
d.arizona's avatar
d.arizona committed
1179 1180 1181 1182 1183 1184
            this.payloadCF(type)
        })
    }

    payloadCF(type) {
        let listCF = []
d.arizona's avatar
d.arizona committed
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
        this.state.dbCF.map((item, index) => {
            if (item[0] == 5 || item[0] == 6 || item[0] == 7) {
                item[7].value = this.handleValueFormula(index, item[7], item, 7)
                item[8].value = this.handleValueFormula(index, item[8], item, 8)
                item[9].value = this.handleValueFormula(index, item[9], item, 9)
                item[10].value = this.handleValueFormula(index, item[10], item, 10)
                item[11].value = this.handleValueFormula(index, item[11], item, 11)
                item[12].value = this.handleValueFormula(index, item[12], item, 12)
                item[13].value = this.handleValueFormula(index, item[13], item, 13)
                item[14].value = this.handleValueFormula(index, item[14], item, 14)
                item[15].value = this.handleValueFormula(index, item[15], item, 15)
                item[16].value = this.handleValueFormula(index, item[16], item, 16)
                item[17].value = this.handleValueFormula(index, item[17], item, 17)
                item[18].value = this.handleValueFormula(index, item[18], item, 18)
                item[19] = this.handleForecast(index, item, `${Number(this.state.periode.periode)}`, 19)
                item[20] = this.handleForecast(index, item, `${Number(this.state.periode.periode) + 1}`, 20)
                item[21] = this.handleForecast(index, item, `${Number(this.state.periode.periode) + 2}`, 21)
            }
            listCF.push(item)
        })

d.arizona's avatar
d.arizona committed
1206
        this.setState({ dbCF: listCF }, () => {
d.arizona's avatar
d.arizona committed
1207
            this.olahDataCashFlowOneMore(listCF, type)
d.arizona's avatar
d.arizona committed
1208 1209 1210 1211
        })
    }

    olahDataCashFlowOneMore(list, type) {
Riri Novita's avatar
Riri Novita committed
1212
        // console.log(list)
d.arizona's avatar
d.arizona committed
1213 1214
        let listCF = []
        list.map((item, index) => {
d.arizona's avatar
d.arizona committed
1215 1216
            if (item[0] == 5 || item[0] == 6 || item[0] == 7) {
                // if (item[7].value == "" || item[7].value == 0 || item[7].value == "0.0") {
d.arizona's avatar
d.arizona committed
1217
                item[7].value = this.handleValueFormula(index, item[7], item, 7)
qorri_di's avatar
qorri_di committed
1218
                // }  
d.arizona's avatar
d.arizona committed
1219

d.arizona's avatar
d.arizona committed
1220
                // if (item[8].value == "" || item[8].value == 0 || item[8].value == "0.0") {
d.arizona's avatar
d.arizona committed
1221
                item[8].value = this.handleValueFormula(index, item[8], item, 8)
qorri_di's avatar
qorri_di committed
1222
                // } 
d.arizona's avatar
d.arizona committed
1223

d.arizona's avatar
d.arizona committed
1224
                // if (item[9].value == "" || item[9].value == 0 || item[9].value == "0.0") {
d.arizona's avatar
d.arizona committed
1225
                item[9].value = this.handleValueFormula(index, item[9], item, 9)
qorri_di's avatar
qorri_di committed
1226
                // } 
d.arizona's avatar
d.arizona committed
1227

d.arizona's avatar
d.arizona committed
1228
                // if (item[10].value == "" || item[10].value == 0 || item[10].value == "0.0") {
d.arizona's avatar
d.arizona committed
1229
                item[10].value = this.handleValueFormula(index, item[10], item, 10)
qorri_di's avatar
qorri_di committed
1230
                // } 
d.arizona's avatar
d.arizona committed
1231

d.arizona's avatar
d.arizona committed
1232
                // if (item[11].value == "" || item[11].value == 0 || item[11].value == "0.0") {
d.arizona's avatar
d.arizona committed
1233
                item[11].value = this.handleValueFormula(index, item[11], item, 11)
qorri_di's avatar
qorri_di committed
1234
                // } 
d.arizona's avatar
d.arizona committed
1235

d.arizona's avatar
d.arizona committed
1236
                // if (item[12].value == "" || item[12].value == 0 || item[12].value == "0.0") {
d.arizona's avatar
d.arizona committed
1237
                item[12].value = this.handleValueFormula(index, item[12], item, 12)
qorri_di's avatar
qorri_di committed
1238
                // } 
d.arizona's avatar
d.arizona committed
1239

d.arizona's avatar
d.arizona committed
1240
                // if (item[13].value == "" || item[13].value == 0 || item[13].value == "0.0") {
d.arizona's avatar
d.arizona committed
1241
                item[13].value = this.handleValueFormula(index, item[13], item, 13)
d.arizona's avatar
d.arizona committed
1242
                // }
d.arizona's avatar
d.arizona committed
1243

d.arizona's avatar
d.arizona committed
1244
                // if (item[14].value == "" || item[14].value == 0 || item[14].value == "0.0") {
d.arizona's avatar
d.arizona committed
1245
                item[14].value = this.handleValueFormula(index, item[14], item, 14)
qorri_di's avatar
qorri_di committed
1246
                // } 
d.arizona's avatar
d.arizona committed
1247

d.arizona's avatar
d.arizona committed
1248
                // if (item[15].value == "" || item[15].value == 0 || item[15].value == "0.0") {
d.arizona's avatar
d.arizona committed
1249
                item[15].value = this.handleValueFormula(index, item[15], item, 15)
qorri_di's avatar
qorri_di committed
1250
                // } 
d.arizona's avatar
d.arizona committed
1251

d.arizona's avatar
d.arizona committed
1252
                // if (item[16].value == "" || item[16].value == 0 || item[16].value == "0.0") {
d.arizona's avatar
d.arizona committed
1253
                item[16].value = this.handleValueFormula(index, item[16], item, 16)
qorri_di's avatar
qorri_di committed
1254
                // } 
d.arizona's avatar
d.arizona committed
1255

d.arizona's avatar
d.arizona committed
1256
                // if (item[17].value == "" || item[17].value == 0 || item[17].value == "0.0") {
d.arizona's avatar
d.arizona committed
1257
                item[17].value = this.handleValueFormula(index, item[17], item, 17)
qorri_di's avatar
qorri_di committed
1258
                // } 
d.arizona's avatar
d.arizona committed
1259

d.arizona's avatar
d.arizona committed
1260
                // if (item[18].value == "" || item[18].value == 0 || item[18].value == "0.0") {
d.arizona's avatar
d.arizona committed
1261
                item[18].value = this.handleValueFormula(index, item[18], item, 18)
qorri_di's avatar
qorri_di committed
1262
                // } 
d.arizona's avatar
d.arizona committed
1263 1264 1265

                item[19] = this.handleForecast(index, item, `${Number(this.state.periode.periode)}`, 19)

d.arizona's avatar
d.arizona committed
1266
                // if (item[20] == "" || item[20] == 0 || item[20] == "0.0") {
d.arizona's avatar
d.arizona committed
1267
                item[20] = this.handleForecast(index, item, `${Number(this.state.periode.periode) + 1}`, 20)
qorri_di's avatar
qorri_di committed
1268
                // } 
d.arizona's avatar
d.arizona committed
1269

d.arizona's avatar
d.arizona committed
1270
                // if (item[21] == "" || item[21] == 0 || item[21] == "0.0") {
d.arizona's avatar
d.arizona committed
1271
                item[21] = this.handleForecast(index, item, `${Number(this.state.periode.periode) + 2}`, 21)
qorri_di's avatar
qorri_di committed
1272
                // } 
d.arizona's avatar
d.arizona committed
1273
            }
d.arizona's avatar
d.arizona committed
1274

d.arizona's avatar
d.arizona committed
1275 1276 1277 1278 1279 1280 1281

            listCF.push(
                {
                    "item_report_id": item[1],
                    "parent": item[2],
                    "formula": String(item[3]),
                    "item_name": item[5],
d.arizona's avatar
d.arizona committed
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296
                    "january": String(item[7].value == undefined ? item[7] : Number(item[7].value).toFixed(1)),
                    "february": String(item[8].value == undefined ? item[8] : Number(item[8].value).toFixed(1)),
                    "march": String(item[9].value == undefined ? item[9] : Number(item[9].value).toFixed(1)),
                    "april": String(item[10].value == undefined ? item[10] : Number(item[10].value).toFixed(1)),
                    "may": String(item[11].value == undefined ? item[11] : Number(item[11].value).toFixed(1)),
                    "june": String(item[12].value == undefined ? item[12] : Number(item[12].value).toFixed(1)),
                    "july": String(item[13].value == undefined ? item[13] : Number(item[13].value).toFixed(1)),
                    "august": String(item[14].value == undefined ? item[14] : Number(item[14].value).toFixed(1)),
                    "september": String(item[15].value == undefined ? item[15] : Number(item[15].value).toFixed(1)),
                    "october": String(item[16].value == undefined ? item[16] : Number(item[16].value).toFixed(1)),
                    "november": String(item[17].value == undefined ? item[17] : Number(item[17].value).toFixed(1)),
                    "december": String(item[18].value == undefined ? item[18] : Number(item[18].value).toFixed(1)),
                    "total_current_year": String(item[19] != '' ? Number(item[19]).toFixed(1) : item[19]),
                    "total_next_year": String(item[20] != '' ? Number(item[20]).toFixed(1) : item[20]),
                    "total_more_year": String(item[21] != '' ? Number(item[21]).toFixed(1) : item[21]),
d.arizona's avatar
d.arizona committed
1297 1298 1299 1300 1301 1302 1303
                    "kpi_type": "",
                    "max_ach": "",
                    "pic": "",
                    "strategic": "",
                    "total_actual_before": "",
                    "uom": "",
                    "weight": ""
d.arizona's avatar
d.arizona committed
1304
                }
d.arizona's avatar
d.arizona committed
1305
            )
d.arizona's avatar
d.arizona committed
1306

d.arizona's avatar
d.arizona committed
1307 1308
        })

Riri Novita's avatar
Riri Novita committed
1309
        // console.log(listCF)
d.arizona's avatar
d.arizona committed
1310
        this.setState({ dbCF: listCF }, () => {
1311 1312
            // if (this.state.submissionID != null) {
            //     this.createCashFlow()
d.arizona's avatar
d.arizona committed
1313
            // }
d.arizona's avatar
d.arizona committed
1314 1315
            // if (type != undefined) {
            //     if (type == 'BS' || type == 'FAM' || type == 'PL') {
Riri Novita's avatar
Riri Novita committed
1316
            // console.log('tarik sis')
d.arizona's avatar
d.arizona committed
1317
            // this.createCashFlow()
d.arizona's avatar
d.arizona committed
1318 1319
            //     }
            // }
d.arizona's avatar
d.arizona committed
1320 1321 1322
        })
    }

Riri Novita's avatar
Riri Novita committed
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332
    createCashFlow(payload, trigger) {
        console.log(trigger);
        if (trigger === "simulasi") {
            api.create().createReportCFSimulasi(payload).then((res) => {
                console.log(res)
                // this.getSubmission()
                if (res.data) {
                    if (res.data.status === "success") {
                        this.setState({ visibleCF: false, visibleBudgetTahunan: true })
                        this.getSubmission()
1333
                    } else {
Riri Novita's avatar
Riri Novita committed
1334 1335 1336 1337 1338
                        if (res.data.message == "Please Set Up Rate Currency First") {
                            this.setState({ visibleAlertSave: true })
                        } else {
                            this.setState({ alert: true, messageAlert: res.data.message, tipeAlert: 'warning', loading: false })
                        }
1339
                    }
1340
                }
Riri Novita's avatar
Riri Novita committed
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373
            })
        } else {
            api.create().createReportCF(payload).then((res) => {
                console.log(res)
                // this.getSubmission()
                if (res.data) {
                    if (res.data.status === "success") {
                        this.setState({ visibleCF: false, visibleBudgetTahunan: true })
                        this.getSubmission()
                    } else {
                        if (res.data.message == "Please Set Up Rate Currency First") {
                            this.setState({ visibleAlertSave: true })
                        } else {
                            this.setState({ alert: true, messageAlert: res.data.message, tipeAlert: 'warning', loading: false })
                        }
                    }
                }
                // if (response.data) {
                //     if (response.data.status === "success") {
                //         this.props.saveToMonthlyReport()
                //     } else {
                //         this.setState({ loading: false }, () => {
                //             this.props.saveToMonthlyReport()
                //         })
                //     }
                // } else {
                //     this.setState({ loading: false }, () => {
                //         // this.getSubmission()
                //         document.body.style.overflow = 'unset';
                //     })
                // }
            })
        }
1374 1375
    }

Riri Novita's avatar
Riri Novita committed
1376
    getPL(type, trigger) {
d.arizona's avatar
d.arizona committed
1377 1378
        let PLID = null
        let payloadID = {
1379
            "periode": this.state.periode.periode,
d.arizona's avatar
d.arizona committed
1380
            "company_id": this.state.company.company_id
1381
        }
d.arizona's avatar
d.arizona committed
1382 1383
        console.log(payloadID);
        api.create().getPLID(payloadID).then(response => {
Riri Novita's avatar
Riri Novita committed
1384
            // console.log(response);
d.arizona's avatar
d.arizona committed
1385
            if (response) {
d.arizona's avatar
d.arizona committed
1386
                PLID = response.data.data == null ? null : response.data.data.profit_loss_id
d.arizona's avatar
d.arizona committed
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
            } else {
                PLID = null
            }
            this.setState({ PLID }, () => {
                let payload = {
                    "report_id": 28,
                    "revision": Number(this.state.lastRevision),
                    "periode": this.state.periode.periode,
                    "company_id": this.state.company.company_id,
                    "submission_id": this.state.PLID,
Riri Novita's avatar
Riri Novita committed
1397
                    "currency_id": this.state.defaultCurrency.id,
d.arizona's avatar
d.arizona committed
1398 1399
                    "months": 0,
                    "quarter": 0,
1400
                }
d.arizona's avatar
d.arizona committed
1401 1402 1403 1404 1405
                api.create().getHierarkiCreateReportPLMB(payload).then(response => {
                    // console.log(response);
                    let dataTable = []
                    if (response.data) {
                        // let dataTable = []
Riri Novita's avatar
Riri Novita committed
1406
                        // console.log(response)
d.arizona's avatar
d.arizona committed
1407 1408 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
                        let res = response.data.data
                        const handlePushChild = (item) => {
                            dataTable.push([
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
                                item.profit_detail.total_actual_before === null ? "0" : item.profit_detail.total_actual_before === "" ? "0" : item.profit_detail.total_actual_before,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.january, formula: item.profit_detail.january_formula } : item.profit_detail.january,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.february, formula: item.profit_detail.february_formula } : item.profit_detail.february,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.march, formula: item.profit_detail.march_formula } : item.profit_detail.march,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.april, formula: item.profit_detail.april_formula } : item.profit_detail.april,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.may, formula: item.profit_detail.may_formula } : item.profit_detail.may,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.june, formula: item.profit_detail.june_formula } : item.profit_detail.june,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.july, formula: item.profit_detail.july_formula } : item.profit_detail.july,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.august, formula: item.profit_detail.august_formula } : item.profit_detail.august,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.september, formula: item.profit_detail.september_formula } : item.profit_detail.september,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.october, formula: item.profit_detail.october_formula } : item.profit_detail.october,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.november, formula: item.profit_detail.november_formula } : item.profit_detail.november,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.december, formula: item.profit_detail.december_formula } : item.profit_detail.december,
                                item.profit_detail.total_current_year,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.profit_detail.total_next_year,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.profit_detail.total_more_year,
                                item.order,
                                item.condition_it_should_be,
                                item.condition_if_wrong,
d.arizona's avatar
d.arizona committed
1435 1436
                                item.profit_detail.forecast_formula == null ? [] : item.profit_detail.forecast_formula,
                                item.profit_detail.notes
d.arizona's avatar
d.arizona committed
1437
                            ])
d.arizona's avatar
d.arizona committed
1438

d.arizona's avatar
d.arizona committed
1439 1440 1441 1442 1443 1444 1445
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
1446
                        }
d.arizona's avatar
d.arizona committed
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473
                        res.map((item, index) => {
                            dataTable.push([
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
                                item.profit_detail.total_actual_before === null ? "0" : item.profit_detail.total_actual_before === "" ? "0" : item.profit_detail.total_actual_before,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.january, formula: item.profit_detail.january_formula } : item.profit_detail.january,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.february, formula: item.profit_detail.february_formula } : item.profit_detail.february,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.march, formula: item.profit_detail.march_formula } : item.profit_detail.march,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.april, formula: item.profit_detail.april_formula } : item.profit_detail.april,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.may, formula: item.profit_detail.may_formula } : item.profit_detail.may,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.june, formula: item.profit_detail.june_formula } : item.profit_detail.june,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.july, formula: item.profit_detail.july_formula } : item.profit_detail.july,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.august, formula: item.profit_detail.august_formula } : item.profit_detail.august,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.september, formula: item.profit_detail.september_formula } : item.profit_detail.september,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.october, formula: item.profit_detail.october_formula } : item.profit_detail.october,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.november, formula: item.profit_detail.november_formula } : item.profit_detail.november,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? { value: item.profit_detail.december, formula: item.profit_detail.december_formula } : item.profit_detail.december,
                                item.profit_detail.total_current_year,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.profit_detail.total_next_year,
                                item.type_report_id == 5 || item.type_report_id == 6 || item.type_report_id == 7 ? 0 : item.profit_detail.total_more_year,
                                item.order,
                                item.condition_it_should_be,
                                item.condition_if_wrong,
d.arizona's avatar
d.arizona committed
1474 1475
                                item.profit_detail.forecast_formula == null ? [] : item.profit_detail.forecast_formula,
                                item.profit_detail.notes
d.arizona's avatar
d.arizona committed
1476 1477 1478 1479 1480 1481 1482 1483 1484
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
d.arizona's avatar
d.arizona committed
1485
                        // console.log(dataTable)
d.arizona's avatar
d.arizona committed
1486
                        this.setState({ dbPL: dataTable }, () => {
Riri Novita's avatar
Riri Novita committed
1487
                            this.olahDataPL(this.state.dbPL, type, trigger)
d.arizona's avatar
d.arizona committed
1488 1489
                        })
                    } else {
1490
                        this.setState({ dbPL: [], previewTable: false, previewDownload: false })
1491
                    }
d.arizona's avatar
d.arizona committed
1492 1493


1494
                })
d.arizona's avatar
d.arizona committed
1495
            })
1496
        })
d.arizona's avatar
d.arizona committed
1497 1498


1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543
    }

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

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

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

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

                            if (indexID !== -1) {
d.arizona's avatar
d.arizona committed
1548
                                let valuezz = tableMeta[data].formula[indexID].value
1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601
                                anjay.push(valuezz == "" ? 0 : valuezz)
                            }
                        } else {
                            // console.log(item)
                            let indexID = value.formula.findIndex((val) => val.item_formula == String(`@${item}`) && val.periode == Number(this.state.periode.periode))
                            if (indexID !== -1) {
                                let valuezz = value.formula[indexID].value
                                anjay.push(valuezz == "" ? 0 : valuezz)
                            }
                        }
                    }

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

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

        let anjay2 = []
        let kurung = false
        let item1 = []
        anjay.map((item, index) => {
            if (item == "(") {
                kurung = true
            } else if (item == ")") {
                kurung = false
                anjay2.push(item1)
                item1 = []
            } else {
                if (kurung) {
                    item1.push(item)
                } else {
                    anjay2.push(item)
                }
            }
        })
d.arizona's avatar
d.arizona committed
1602

1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632
        let total = 0
        let opt = ""
        let totalPrio = 0
        let optPrio = ""
        let prio = false
        anjay2.map((item, index) => {
            if (Array.isArray(item)) {
                prio = true
                item.map((items, indexs) => {
                    if (items == "+") {
                        optPrio = "tambah"
                    } else if (items == "-") {
                        optPrio = "kurang"
                    } else if (items == "*") {
                        optPrio = "kali"
                    } else if (items == "/") {
                        optPrio = "bagi"
                    } else {
                        if (optPrio == "tambah") {
                            totalPrio = Number(totalPrio) + Number(items)
                        } else if (optPrio == "kurang") {
                            totalPrio = Number(totalPrio) - Number(items)
                        } else if (optPrio == "kali") {
                            totalPrio = Number(totalPrio) * Number(items)
                        } else if (optPrio == "bagi") {
                            totalPrio = Number(totalPrio) / Number(items) == NaN ? 0 : Number(totalPrio) / Number(items)
                        } else {
                            totalPrio += Number(items)
                        }
                    }
d.arizona's avatar
d.arizona committed
1633
                })
1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697

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

Riri Novita's avatar
Riri Novita committed
1698 1699 1700 1701 1702 1703 1704
        // if (String(tableMeta[5]) == "Cost of Goods Sold (COGS)" && column == 20) {
        //     console.log(splitFormula)
        //     console.log(baru)
        //     console.log(anjay)
        //     console.log(anjay2)
        //     console.log(total)
        // }
1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719
        total = R.equals(total, NaN) ? "0.0" : total
        return total
    }

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

        if (tableMeta[3].includes('#PL')) {
            dataTable2[index][25].map((item, index) => {
                if (item.periode == periode) {
                    total += Number(item.value)
                }
            })
        } else {
d.arizona's avatar
d.arizona committed
1720
            total = this.handleValueFormulaDBPL(dataTable2[index][column], tableMeta[column], tableMeta, column, periode, dataTable2[index][25])
1721 1722 1723 1724 1725
        }

        return total
    }

Riri Novita's avatar
Riri Novita committed
1726
    olahDataPL(dbPL, type, trigger) {
d.arizona's avatar
d.arizona committed
1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740
        dbPL.map((item, index) => {
            if (item[0] == 5 || item[0] == 6 || item[0] == 7) {
                item[7].value = this.handleValueFormulaDBPL(index, item[7], item, 7)
                item[8].value = this.handleValueFormulaDBPL(index, item[8], item, 8)
                item[9].value = this.handleValueFormulaDBPL(index, item[9], item, 9)
                item[10].value = this.handleValueFormulaDBPL(index, item[10], item, 10)
                item[11].value = this.handleValueFormulaDBPL(index, item[11], item, 11)
                item[12].value = this.handleValueFormulaDBPL(index, item[12], item, 12)
                item[13].value = this.handleValueFormulaDBPL(index, item[13], item, 13)
                item[14].value = this.handleValueFormulaDBPL(index, item[14], item, 14)
                item[15].value = this.handleValueFormulaDBPL(index, item[15], item, 15)
                item[16].value = this.handleValueFormulaDBPL(index, item[16], item, 16)
                item[17].value = this.handleValueFormulaDBPL(index, item[17], item, 17)
                item[18].value = this.handleValueFormulaDBPL(index, item[18], item, 18)
1741 1742 1743 1744
                item[20] = this.handleForecastDBPL(index, item, `${Number(this.state.periode.periode) + 1}`, 20)
                item[21] = this.handleForecastDBPL(index, item, `${Number(this.state.periode.periode) + 2}`, 21)
            }
        })
d.arizona's avatar
d.arizona committed
1745
        this.setState({ dbPL }, () => {
Riri Novita's avatar
Riri Novita committed
1746
            this.payloadPL(type, trigger)
1747 1748 1749
        })
    }

Riri Novita's avatar
Riri Novita committed
1750
    payloadPL(type, trigger) {
1751
        let listPL = []
d.arizona's avatar
d.arizona committed
1752
        // console.log(this.state.dbPL)
d.arizona's avatar
d.arizona committed
1753
        this.state.dbPL.map((item, index) => {
1754 1755
            if (item[0] == 5 || item[0] == 6 || item[0] == 7) {
                // if (item[7].value == "" || item[7].value == 0 || item[7].value == "0.0") {
d.arizona's avatar
d.arizona committed
1756
                item[7].value = this.handleValueFormulaDBPL(index, item[7], item, 7)
qorri_di's avatar
qorri_di committed
1757
                // }  
d.arizona's avatar
d.arizona committed
1758

1759
                // if (item[8].value == "" || item[8].value == 0 || item[8].value == "0.0") {
d.arizona's avatar
d.arizona committed
1760
                item[8].value = this.handleValueFormulaDBPL(index, item[8], item, 8)
qorri_di's avatar
qorri_di committed
1761
                // } 
d.arizona's avatar
d.arizona committed
1762

1763
                // if (item[9].value == "" || item[9].value == 0 || item[9].value == "0.0") {
d.arizona's avatar
d.arizona committed
1764
                item[9].value = this.handleValueFormulaDBPL(index, item[9], item, 9)
qorri_di's avatar
qorri_di committed
1765
                // } 
d.arizona's avatar
d.arizona committed
1766

1767
                // if (item[10].value == "" || item[10].value == 0 || item[10].value == "0.0") {
d.arizona's avatar
d.arizona committed
1768
                item[10].value = this.handleValueFormulaDBPL(index, item[10], item, 10)
qorri_di's avatar
qorri_di committed
1769
                // } 
d.arizona's avatar
d.arizona committed
1770

1771
                // if (item[11].value == "" || item[11].value == 0 || item[11].value == "0.0") {
d.arizona's avatar
d.arizona committed
1772
                item[11].value = this.handleValueFormulaDBPL(index, item[11], item, 11)
qorri_di's avatar
qorri_di committed
1773
                // } 
d.arizona's avatar
d.arizona committed
1774

1775
                // if (item[12].value == "" || item[12].value == 0 || item[12].value == "0.0") {
d.arizona's avatar
d.arizona committed
1776
                item[12].value = this.handleValueFormulaDBPL(index, item[12], item, 12)
qorri_di's avatar
qorri_di committed
1777
                // } 
d.arizona's avatar
d.arizona committed
1778

1779
                // if (item[13].value == "" || item[13].value == 0 || item[13].value == "0.0") {
d.arizona's avatar
d.arizona committed
1780
                item[13].value = this.handleValueFormulaDBPL(index, item[13], item, 13)
1781
                // }
d.arizona's avatar
d.arizona committed
1782

1783
                // if (item[14].value == "" || item[14].value == 0 || item[14].value == "0.0") {
d.arizona's avatar
d.arizona committed
1784
                item[14].value = this.handleValueFormulaDBPL(index, item[14], item, 14)
qorri_di's avatar
qorri_di committed
1785
                // } 
d.arizona's avatar
d.arizona committed
1786

1787
                // if (item[15].value == "" || item[15].value == 0 || item[15].value == "0.0") {
d.arizona's avatar
d.arizona committed
1788
                item[15].value = this.handleValueFormulaDBPL(index, item[15], item, 15)
qorri_di's avatar
qorri_di committed
1789
                // } 
d.arizona's avatar
d.arizona committed
1790

1791
                // if (item[16].value == "" || item[16].value == 0 || item[16].value == "0.0") {
d.arizona's avatar
d.arizona committed
1792
                item[16].value = this.handleValueFormulaDBPL(index, item[16], item, 16)
qorri_di's avatar
qorri_di committed
1793
                // } 
d.arizona's avatar
d.arizona committed
1794

1795
                // if (item[17].value == "" || item[17].value == 0 || item[17].value == "0.0") {
d.arizona's avatar
d.arizona committed
1796
                item[17].value = this.handleValueFormulaDBPL(index, item[17], item, 17)
qorri_di's avatar
qorri_di committed
1797
                // } 
d.arizona's avatar
d.arizona committed
1798

1799
                // if (item[18].value == "" || item[18].value == 0 || item[18].value == "0.0") {
d.arizona's avatar
d.arizona committed
1800
                item[18].value = this.handleValueFormulaDBPL(index, item[18], item, 18)
qorri_di's avatar
qorri_di committed
1801
                // } 
d.arizona's avatar
d.arizona committed
1802

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

1807
                // if (item[21] == "" || item[21] == 0 || item[21] == "0.0") {
d.arizona's avatar
d.arizona committed
1808
                item[21] = this.handleForecastDBPL(index, item, `${Number(this.state.periode.periode) + 2}`, 21)
qorri_di's avatar
qorri_di committed
1809
                // } 
1810
            }
d.arizona's avatar
d.arizona committed
1811

1812 1813 1814 1815

            listPL.push(
                {
                    "item_report_id": item[1],
d.arizona's avatar
d.arizona committed
1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827
                    "january": String(item[7].value == undefined ? item[7] : Number(item[7].value).toFixed(1)),
                    "february": String(item[8].value == undefined ? item[8] : Number(item[8].value).toFixed(1)),
                    "march": String(item[9].value == undefined ? item[9] : Number(item[9].value).toFixed(1)),
                    "april": String(item[10].value == undefined ? item[10] : Number(item[10].value).toFixed(1)),
                    "may": String(item[11].value == undefined ? item[11] : Number(item[11].value).toFixed(1)),
                    "june": String(item[12].value == undefined ? item[12] : Number(item[12].value).toFixed(1)),
                    "july": String(item[13].value == undefined ? item[13] : Number(item[13].value).toFixed(1)),
                    "august": String(item[14].value == undefined ? item[14] : Number(item[14].value).toFixed(1)),
                    "september": String(item[15].value == undefined ? item[15] : Number(item[15].value).toFixed(1)),
                    "october": String(item[16].value == undefined ? item[16] : Number(item[16].value).toFixed(1)),
                    "november": String(item[17].value == undefined ? item[17] : Number(item[17].value).toFixed(1)),
                    "december": String(item[18].value == undefined ? item[18] : Number(item[18].value).toFixed(1)),
1828
                    "total_current_year": String(item[19]),
d.arizona's avatar
d.arizona committed
1829 1830
                    "total_next_year": String(item[20] != '' ? Number(item[20]).toFixed(1) : item[20]),
                    "total_more_year": String(item[21] != '' ? Number(item[21]).toFixed(1) : item[21]),
d.arizona's avatar
d.arizona committed
1831
                    "notes": String(item[26]),
d.arizona's avatar
d.arizona committed
1832
                }
1833
            )
d.arizona's avatar
d.arizona committed
1834

1835 1836
        })

d.arizona's avatar
d.arizona committed
1837
        // console.log(listPL)
d.arizona's avatar
d.arizona committed
1838
        this.setState({ dbPL: listPL }, () => {
1839 1840 1841
            // if (this.state.submissionID != null) {
            //     this.createDBPL()
            // }
d.arizona's avatar
d.arizona committed
1842 1843
            if (type != undefined) {
                if (type == 'PL') {
Riri Novita's avatar
Riri Novita committed
1844
                    // console.log('tarik sis')
Riri Novita's avatar
Riri Novita committed
1845
                    this.createDBPL(trigger)
d.arizona's avatar
d.arizona committed
1846 1847
                }
            }
1848 1849 1850
        })
    }

Riri Novita's avatar
Riri Novita committed
1851 1852
    createDBPL(trigger) {
        console.log(trigger);
1853
        let payload = {
d.arizona's avatar
d.arizona committed
1854
            // "submission_id": this.state.submissionID,
1855 1856
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
d.arizona's avatar
d.arizona committed
1857
            "report_id": 28,
1858
            "status": "submitted",
d.arizona's avatar
d.arizona committed
1859
            "profit_loss_id": this.state.PLID,
Riri Novita's avatar
Riri Novita committed
1860
            "currency_id": this.state.defaultCurrency.id,
1861 1862 1863 1864
            "profit_loss_mb": this.state.dbPL,
            "months": 0,
        }
        // console.log(this.state.dbCF)
d.arizona's avatar
d.arizona committed
1865
        // console.log(JSON.stringify(payload))
Riri Novita's avatar
Riri Novita committed
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890
        if (trigger === "simulasiPL") {
            api.create().createReportPLMBSimulasi(payload).then((res) => {
                // console.log(res)
                this.setState({ loading: false })
            })
        } else {
            api.create().createReportPLMB(payload).then((res) => {
                // console.log(res)
                this.setState({ loading: false })
                // if (response.data) {
                //     if (response.data.status === "success") {
                //         this.props.saveToMonthlyReport()
                //     } else {
                //         this.setState({ loading: false }, () => {
                //             this.props.saveToMonthlyReport()
                //         })
                //     }
                // } else {
                //     this.setState({ loading: false }, () => {
                //         // this.getSubmission()
                //         document.body.style.overflow = 'unset';
                //     })
                // }
            })
        }
1891 1892 1893
    }

    getFR(type) {
Riri Novita's avatar
Riri Novita committed
1894
        // console.log("get FR");
1895 1896 1897 1898 1899
        let FRID = null
        let payloadID = {
            "periode": this.state.periode.periode,
            "company_id": this.state.company.company_id
        }
Riri Novita's avatar
Riri Novita committed
1900
        // console.log(payloadID);
1901
        api.create().getFRID(payloadID).then(response => {
Riri Novita's avatar
Riri Novita committed
1902
            // console.log(response);
1903
            if (response) {
d.arizona's avatar
d.arizona committed
1904
                FRID = response.data.data == null ? null : response.data.data.ratio_id
1905 1906 1907 1908 1909 1910 1911 1912 1913
            } else {
                FRID = null
            }
            this.setState({ FRID }, () => {
                let payload = {
                    "report_id": 29,
                    "revision": Number(this.state.lastRevision),
                    "periode": this.state.periode.periode,
                    "company_id": this.state.company.company_id,
Riri Novita's avatar
Riri Novita committed
1914
                    "currency_id": this.state.defaultCurrency.id,
d.arizona's avatar
d.arizona committed
1915
                    "submission_id": this.state.submissionID,
1916 1917 1918 1919 1920 1921
                }
                api.create().getHierarkiCreateReportFRMB(payload).then(response => {
                    // console.log(response);
                    let dataTable = []
                    if (response.data) {
                        // let dataTable = []
Riri Novita's avatar
Riri Novita committed
1922
                        // console.log(response)
1923 1924
                        let res = response.data.data
                        const handlePushChild = (item) => {
d.arizona's avatar
d.arizona committed
1925
                            if (item.description == 'Return on Invested Capital - YTD (ROIC)') {
Riri Novita's avatar
Riri Novita committed
1926
                                // console.log(item.ratio.january)
d.arizona's avatar
d.arizona committed
1927
                            }
1928 1929 1930 1931 1932 1933 1934 1935
                            dataTable.push([
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
                                item.uom,
d.arizona's avatar
d.arizona committed
1936
                                // "",
1937
                                // item.ratio.total_actual_before === null ? "0.0" : item.ratio.total_actual_before === "" ? "0.0" : item.ratio.total_actual_before,
d.arizona's avatar
d.arizona committed
1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951
                                Number(item.ratio.january).toFixed(2),
                                Number(item.ratio.february).toFixed(2),
                                Number(item.ratio.march).toFixed(2),
                                Number(item.ratio.april).toFixed(2),
                                Number(item.ratio.may).toFixed(2),
                                Number(item.ratio.june).toFixed(2),
                                Number(item.ratio.july).toFixed(2),
                                Number(item.ratio.august).toFixed(2),
                                Number(item.ratio.september).toFixed(2),
                                Number(item.ratio.october).toFixed(2),
                                Number(item.ratio.november).toFixed(2),
                                Number(item.ratio.december).toFixed(2),
                                Number(item.ratio.total_next_year).toFixed(2),
                                Number(item.ratio.total_more_year).toFixed(2),
1952
                            ])
d.arizona's avatar
d.arizona committed
1953

1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        }
                        res.map((item, index) => {
                            dataTable.push([
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                item.description,
                                item.uom,
d.arizona's avatar
d.arizona committed
1971
                                // "",
1972
                                // item.ratio.total_actual_before === null ? "0.0" : item.ratio.total_actual_before === "" ? "0.0" : item.ratio.total_actual_before,
d.arizona's avatar
d.arizona committed
1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986
                                Number(item.ratio.january).toFixed(2),
                                Number(item.ratio.february).toFixed(2),
                                Number(item.ratio.march).toFixed(2),
                                Number(item.ratio.april).toFixed(2),
                                Number(item.ratio.may).toFixed(2),
                                Number(item.ratio.june).toFixed(2),
                                Number(item.ratio.july).toFixed(2),
                                Number(item.ratio.august).toFixed(2),
                                Number(item.ratio.september).toFixed(2),
                                Number(item.ratio.october).toFixed(2),
                                Number(item.ratio.november).toFixed(2),
                                Number(item.ratio.december).toFixed(2),
                                Number(item.ratio.total_next_year).toFixed(2),
                                Number(item.ratio.total_more_year).toFixed(2),
1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
                        this.setState({ dbFR: dataTable, loading: false }, () => {
Riri Novita's avatar
Riri Novita committed
1997
                            // console.log(this.state.dbFR)
d.arizona's avatar
d.arizona committed
1998
                            this.olahDataFR(this.state.dbFR, type)
1999 2000
                        })
                    } else {
d.arizona's avatar
d.arizona committed
2001
                        this.setState({ dbFR: [], previewTable: false, loading: false, previewDownload: false })
2002
                    }
d.arizona's avatar
d.arizona committed
2003 2004


2005 2006 2007
                })
            })
        })
d.arizona's avatar
d.arizona committed
2008 2009


2010 2011 2012 2013 2014 2015 2016
    }

    handleFormulaRatio = (value, tableMeta, month) => {
        // console.log(dataTable2)
        let dataTable2 = this.state.dbFR
        let total = 0
        if (month > 12) {
d.arizona's avatar
d.arizona committed
2017
            total = Number(dataTable2[35][6 + month])
2018 2019
        } else {
            for (let index = 0; index < month; index++) {
d.arizona's avatar
d.arizona committed
2020
                total += Number(dataTable2[35][7 + index])
2021 2022
                // console.log(index);
            }
d.arizona's avatar
d.arizona committed
2023
            total = total / month
2024 2025
        }
        let hasil = Number(value) / total
d.arizona's avatar
d.arizona committed
2026 2027 2028
        // console.log(value)
        // console.log(total)
        // console.log(hasil, value, total);
d.arizona's avatar
d.arizona committed
2029
        return Number(hasil).toFixed(2)
2030 2031 2032 2033
    }

    olahDataFR(dbFR, type) {
        // let totalCY = 0
d.arizona's avatar
d.arizona committed
2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050
        dbFR.map((item, index) => {
            if (item[0] != 4 || item[0] != 1) {
                if (item[5] === "Return on Invested Capital - YTD (ROIC)") {
                    item[7] = this.handleFormulaRatio(item[7], item, 1)
                    item[8] = this.handleFormulaRatio(item[8], item, 2)
                    item[9] = this.handleFormulaRatio(item[9], item, 3)
                    item[10] = this.handleFormulaRatio(item[10], item, 4)
                    item[11] = this.handleFormulaRatio(item[11], item, 5)
                    item[12] = this.handleFormulaRatio(item[12], item, 6)
                    item[13] = this.handleFormulaRatio(item[13], item, 7)
                    item[14] = this.handleFormulaRatio(item[14], item, 8)
                    item[15] = this.handleFormulaRatio(item[15], item, 9)
                    item[16] = this.handleFormulaRatio(item[16], item, 10)
                    item[17] = this.handleFormulaRatio(item[17], item, 11)
                    item[18] = this.handleFormulaRatio(item[18], item, 12)
                    item[19] = this.handleFormulaRatio(item[19], item, 13)
                    item[20] = this.handleFormulaRatio(item[20], item, 14)
2051
                    // totalCY = Number(item[7]) + Number(item[8]) + Number(item[9]) + Number(item[10]) + Number(item[11]) + Number(item[12]) + Number(item[13]) + Number(item[14]) + Number(item[15]) + Number(item[16]) + Number(item[17]) + Number(item[18])
d.arizona's avatar
d.arizona committed
2052
                }
2053 2054
            }
        })
d.arizona's avatar
d.arizona committed
2055
        this.setState({ dbFR }, () => {
2056 2057 2058 2059 2060 2061
            this.payloadFR(type)
        })
    }

    payloadFR(type) {
        let listFR = []
d.arizona's avatar
d.arizona committed
2062
        // console.log(this.state.dbFR)
2063
        let totalCY = 0
d.arizona's avatar
d.arizona committed
2064
        this.state.dbFR.map((item, index) => {
2065
            if (item[0] != 4 || item[0] != 1) {
d.arizona's avatar
d.arizona committed
2066
                if (item[5] === "Return on Invested Capital - YTD (ROIC)") {
d.arizona's avatar
d.arizona committed
2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080
                    // item[7] = this.handleFormulaRatio(item[7],item,1)
                    // item[8] = this.handleFormulaRatio(item[8],item,2)
                    // item[9] = this.handleFormulaRatio(item[9],item,3)
                    // item[10] = this.handleFormulaRatio(item[10],item,4)
                    // item[11] = this.handleFormulaRatio(item[11],item,5)
                    // item[12] = this.handleFormulaRatio(item[12],item,6)
                    // item[13] = this.handleFormulaRatio(item[13],item,7)
                    // item[14] = this.handleFormulaRatio(item[14],item,8)
                    // item[15] = this.handleFormulaRatio(item[15],item,9)
                    // item[16] = this.handleFormulaRatio(item[16],item,10)
                    // item[17] = this.handleFormulaRatio(item[17],item,11)
                    // item[18] = this.handleFormulaRatio(item[18],item,12)
                    // item[19] = this.handleFormulaRatio(item[19],item,13)
                    // item[20] = this.handleFormulaRatio(item[20],item,14)
d.arizona's avatar
d.arizona committed
2081
                }
d.arizona's avatar
d.arizona committed
2082
                totalCY = Number(item[7]) + Number(item[8]) + Number(item[9]) + Number(item[10]) + Number(item[11]) + Number(item[12]) + Number(item[13]) + Number(item[14]) + Number(item[15]) + Number(item[16]) + Number(item[17]) + Number(item[18])
2083 2084 2085 2086 2087
            }

            listFR.push(
                {
                    "item_report_id": item[1],
d.arizona's avatar
d.arizona committed
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103
                    "january": String(item[7] == undefined || item[7] == 'Infinity' || item[7] == '-Infinity' ? "0.0" : Number(item[7]).toFixed(2)),
                    "february": String(item[8] == undefined || item[8] == 'Infinity' || item[8] == '-Infinity' ? "0.0" : Number(item[8]).toFixed(2)),
                    "march": String(item[9] == undefined || item[9] == 'Infinity' || item[9] == '-Infinity' ? "0.0" : Number(item[9]).toFixed(2)),
                    "april": String(item[10] == undefined || item[10] == 'Infinity' || item[10] == '-Infinity' ? "0.0" : Number(item[10]).toFixed(2)),
                    "may": String(item[11] == undefined || item[11] == 'Infinity' || item[11] == '-Infinity' ? "0.0" : Number(item[11]).toFixed(2)),
                    "june": String(item[12] == undefined || item[12] == 'Infinity' || item[12] == '-Infinity' ? "0.0" : Number(item[12]).toFixed(2)),
                    "july": String(item[13] == undefined || item[13] == 'Infinity' || item[13] == '-Infinity' ? "0.0" : Number(item[13]).toFixed(2)),
                    "august": String(item[14] == undefined || item[14] == 'Infinity' || item[14] == '-Infinity' ? "0.0" : Number(item[14]).toFixed(2)),
                    "september": String(item[15] == undefined || item[15] == 'Infinity' || item[15] == '-Infinity' ? "0.0" : Number(item[15]).toFixed(2)),
                    "october": String(item[16] == undefined || item[16] == 'Infinity' || item[16] == '-Infinity' ? "0.0" : Number(item[16]).toFixed(2)),
                    "november": String(item[17] == undefined || item[17] == 'Infinity' || item[17] == '-Infinity' ? "0.0" : Number(item[17]).toFixed(2)),
                    "december": String(item[18] == undefined || item[18] == 'Infinity' || item[18] == '-Infinity' ? "0.0" : Number(item[18]).toFixed(2)),
                    "total_current_year": String(totalCY == undefined || totalCY == 'Infinity' || totalCY == '-Infinity' ? "0.0" : Number(totalCY).toFixed(2)),
                    "total_next_year": String(item[19] != '' || item[19] != 'Infinity' || item[19] != '-Infinity' ? Number(item[19]).toFixed(2) : item[19]),
                    "total_more_year": String(item[20] != '' || item[20] != 'Infinity' || item[20] != '-Infinity' ? Number(item[20]).toFixed(2) : item[20]),
                }
2104
            )
d.arizona's avatar
d.arizona committed
2105

2106 2107
        })

Riri Novita's avatar
Riri Novita committed
2108 2109
        // console.log(listFR)
        // console.log('subOD', this.state.submissionID)
d.arizona's avatar
d.arizona committed
2110
        this.setState({ dbFR: listFR }, () => {
2111 2112 2113 2114 2115 2116 2117
            if (this.state.submissionID != null) {
                this.createDBFR()
            }
        })
    }

    createDBFR() {
Riri Novita's avatar
Riri Novita committed
2118
        // console.log("create FR");
2119 2120 2121 2122 2123 2124 2125
        let payload = {
            // "submission_id": this.state.submissionID,
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
            "report_id": 29,
            "status": "submitted",
            "ratio_id": this.state.FRID,
Riri Novita's avatar
Riri Novita committed
2126
            "currency_id": this.state.defaultCurrency.id,
2127 2128 2129 2130
            "ratio_mb": this.state.dbFR,
            "months": 0,
        }
        // console.log(this.state.dbCF)
d.arizona's avatar
d.arizona committed
2131
        // console.log(JSON.stringify(payload))
2132
        api.create().createReportFRMB(payload).then((res) => {
Riri Novita's avatar
Riri Novita committed
2133
            // console.log(res)
2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144
            // if (response.data) {
            //     if (response.data.status === "success") {
            //         this.props.saveToMonthlyReport()
            //     } else {
            //         this.setState({ loading: false }, () => {
            //             this.props.saveToMonthlyReport()
            //         })
            //     }
            // } else {
            //     this.setState({ loading: false }, () => {
            //         // this.getSubmission()
d.arizona's avatar
d.arizona committed
2145 2146 2147 2148 2149 2150
            //         document.body.style.overflow = 'unset';
            //     })
            // }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
2151 2152
    historyApproval() {
        let body = {
Deni Rinaldi's avatar
Deni Rinaldi committed
2153 2154
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode
Deni Rinaldi's avatar
Deni Rinaldi committed
2155 2156
        }
        api.create().historyApproval(body).then(response => {
d.arizona's avatar
d.arizona committed
2157
            // // // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
2158 2159
            if (response.data.data.length > 0) {
                let dataTableHistory = response.data.data.map(item => {
d.arizona's avatar
d.arizona committed
2160 2161 2162
                    let indexC = String(item.status_approval).toLocaleUpperCase().indexOf('C')
                    let status_approv = ''
                    if (String(item.status_approval).toLocaleUpperCase().includes('CC')) {
d.arizona's avatar
d.arizona committed
2163
                        status_approv = `${String(item.status_approval).substr(0, indexC)}${String(item.status_approval).substr(indexC + 1, String(item.status_approval).length)}`
d.arizona's avatar
d.arizona committed
2164 2165 2166
                    } else {
                        status_approv = String(item.status_approval)
                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
2167 2168
                    return [
                        item.pic,
d.arizona's avatar
d.arizona committed
2169
                        status_approv,
Deni Rinaldi's avatar
Deni Rinaldi committed
2170 2171 2172 2173 2174
                        item.remarks,
                        item.item_revision,
                        item.history_approval_date
                    ]
                })
Deni Rinaldi's avatar
Deni Rinaldi committed
2175
                this.setState({ dataTableHistory, visibleTableHistory: true })
Deni Rinaldi's avatar
Deni Rinaldi committed
2176 2177 2178 2179
            }
        })
    }

d.arizona's avatar
d.arizona committed
2180
    async setHeaderTokenSuperadmin(type) {
2181
        let realToken = await localStorage.getItem(Constant.TOKEN)
d.arizona's avatar
d.arizona committed
2182
        api.create().getIdToken(this.state.approver.userId).then((response) => {
Riri Novita's avatar
Riri Novita committed
2183
            // console.log(response.data.data.token)
d.arizona's avatar
d.arizona committed
2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198
            localStorage.setItem(Constant.TOKEN, response.data.data.token)
            this.approvalSubmission(type, realToken)
        })
    }

    approvalSubmission(type, realToken) {
        // this.scrollToMyRef()
        // let realToken = await localStorage.getItem(Constant.TOKEN)
        // if (this.state.isAdmin && type == 'approve') {
        //     api.create().getIdToken(this.state.approver.userId).then((response) => {
        //         console.log(response.data.data.token)
        //         console.log(realToken)
        //         localStorage.setItem(Constant.TOKEN, response.data.data.token)
        //     })
        // }
Deni Rinaldi's avatar
Deni Rinaldi committed
2199
        this.setState({ loading: true }, () => {
idlanirined's avatar
idlanirined committed
2200 2201
            document.body.style.overflow = 'hidden';
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2202
        let body = {
Deni Rinaldi's avatar
Deni Rinaldi committed
2203
            "approval_id": this.state.approverID,
Deni Rinaldi's avatar
Deni Rinaldi committed
2204
            "status": type,
d.arizona's avatar
d.arizona committed
2205
            "detail": this.state.detailRevisiCheck,
2206 2207
            "is_superadmin": this.state.isAdmin,
            "currency_id": this.state.defaultCurrency.id,
Deni Rinaldi's avatar
Deni Rinaldi committed
2208
        }
d.arizona's avatar
d.arizona committed
2209 2210
        let payload = {
            "company_id": this.state.company.company_id,
d.arizona's avatar
d.arizona committed
2211
            "periode": this.state.periode.periode,
d.arizona's avatar
d.arizona committed
2212 2213 2214
            "min_periode": moment(this.state.minDateRevision).format('YYYY-MM-DD'),
            "max_periode": moment(this.state.maxDateRevision).format('YYYY-MM-DD')
        }
Riri Novita's avatar
Riri Novita committed
2215
        // console.log(payload)
d.arizona's avatar
d.arizona committed
2216
        // // console.log(this.props.location);
Riri Novita's avatar
Riri Novita committed
2217
        // console.log(body)
2218 2219
        setTimeout(() => {
            api.create().approvalSubmission(body).then((res) => {
Riri Novita's avatar
Riri Novita committed
2220
                // console.log(res)
2221 2222
                // this.setState({ loading: false }, () => {
                // })
Faisal Hamdi's avatar
Faisal Hamdi committed
2223
                if (this.state.isAdmin && type == 'approve') {
2224
                    localStorage.setItem(Constant.TOKEN, realToken)
Faisal Hamdi's avatar
Faisal Hamdi committed
2225
                    this.setState({ visibleApproveSuperadmin: false })
2226 2227 2228 2229 2230 2231 2232 2233 2234
                }
                setTimeout(() => {
                    if (type == 'revision') {
                        api.create().createPeriodeRevision(payload).then((res))
                    }
                    this.getSubmission()
                }, 400);
            })
        }, 200);
Deni Rinaldi's avatar
Deni Rinaldi committed
2235 2236
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
2237
    clickDetail(item, id, revision, status) {
idlanirined's avatar
idlanirined committed
2238 2239 2240 2241 2242 2243
        let items = ''
        if (item === 'Corporate Annual Target') {
            items = 'CAT'
        } else {
            items = item
        }
d.arizona's avatar
d.arizona committed
2244
        let PLBSFAMSubmitted = 0
d.arizona's avatar
d.arizona committed
2245
        // // // console.log(this.state.dataForRevision);
Deni Rinaldi's avatar
Deni Rinaldi committed
2246
        this.state.dataForRevision.map(i => {
idlanirined's avatar
idlanirined committed
2247
            if (i.report_name === items) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2248 2249 2250 2251 2252 2253
                if (i.revision !== revision) {
                    this.setState({ prevRevision: true })
                } else {
                    this.setState({ prevRevision: false })
                }
            }
d.arizona's avatar
d.arizona committed
2254
            if (String(i.report_name).toLocaleLowerCase() == "profit loss" || String(i.report_name).toLocaleLowerCase() == "balance sheet" || String(i.report_name).toLocaleLowerCase() == "fixed assets movement") {
d.arizona's avatar
d.arizona committed
2255 2256 2257 2258
                if (String(i.current_status).toLocaleLowerCase() == "submitted") {
                    PLBSFAMSubmitted += 1
                }
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
2259
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2260 2261 2262
        this.setState({
            report_id: id,
            revisionTable: revision,
Deni Rinaldi's avatar
Deni Rinaldi committed
2263
            status: status
Deni Rinaldi's avatar
Deni Rinaldi committed
2264 2265 2266 2267 2268 2269 2270 2271 2272
        }, () => {
            if (item === 'Balance Sheet') {
                this.setState({
                    visibleBudgetTahunan: false,
                    visibleBS: true,
                    visiblePL: false,
                    visibleCAT: false,
                    visibleFAM: false,
                    visibleTP: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2273
                    visibleCF: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2274 2275 2276 2277 2278 2279 2280 2281
                })
            } else if (item === 'Profit Loss') {
                this.setState({
                    visibleBudgetTahunan: false,
                    visibleBS: false,
                    visiblePL: true,
                    visibleCAT: false,
                    visibleFAM: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2282 2283
                    visibleTP: false,
                    visibleCF: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2284 2285 2286 2287 2288 2289 2290 2291
                })
            } else if (item === 'Tax Planning') {
                this.setState({
                    visibleBudgetTahunan: false,
                    visibleBS: false,
                    visiblePL: false,
                    visibleCAT: false,
                    visibleFAM: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2292 2293
                    visibleTP: true,
                    visibleCF: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2294 2295 2296 2297 2298 2299 2300 2301
                })
            } else if (item === 'Fixed Assets Movement') {
                this.setState({
                    visibleBudgetTahunan: false,
                    visibleBS: false,
                    visiblePL: false,
                    visibleCAT: false,
                    visibleFAM: true,
Deni Rinaldi's avatar
Deni Rinaldi committed
2302 2303
                    visibleTP: false,
                    visibleCF: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2304
                })
idlanirined's avatar
idlanirined committed
2305
            } else if (item === 'Corporate Annual Target') {
Deni Rinaldi's avatar
Deni Rinaldi committed
2306 2307 2308 2309 2310 2311
                this.setState({
                    visibleBudgetTahunan: false,
                    visibleBS: false,
                    visiblePL: false,
                    visibleCAT: true,
                    visibleFAM: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2312 2313 2314
                    visibleTP: false,
                    visibleCF: false,
                })
Deni Rinaldi's avatar
Deni Rinaldi committed
2315
            } else if (item === "Cash Flow") {
Deni Rinaldi's avatar
Deni Rinaldi committed
2316 2317 2318 2319 2320 2321 2322 2323
                this.setState({
                    visibleBudgetTahunan: false,
                    visibleBS: false,
                    visiblePL: false,
                    visibleCAT: false,
                    visibleFAM: false,
                    visibleTP: false,
                    visibleCF: true,
d.arizona's avatar
d.arizona committed
2324
                    PLBSFAMSubmitted: PLBSFAMSubmitted == 3 ? true : false
Deni Rinaldi's avatar
Deni Rinaldi committed
2325 2326 2327
                })
            }
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2328 2329
    }

2330 2331 2332 2333 2334
    handleChange(value, tableMeta) {
        let data = this.state.dataTable
        data[tableMeta.rowIndex][tableMeta.columnIndex] = value
    }

2335 2336 2337
    fileHandler = (event) => {
        let fileObj = event
        ExcelRenderer(fileObj, (err, resp) => {
d.arizona's avatar
d.arizona committed
2338
            // // // console.log(resp)
2339
            if (err) {
d.arizona's avatar
d.arizona committed
2340
                // // // console.log(err);
2341 2342 2343
            }
            else {
                const formData = new FormData();
Deni Rinaldi's avatar
Deni Rinaldi committed
2344
                formData.append("revision", Number(this.state.lastRevision));
2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357
                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) {
        api.create().uploadAttachment(formData).then(response => {
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({ visibleUpload: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
2358
                        this.getSubmission()
2359 2360 2361
                    })
                }
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
2362 2363 2364 2365 2366
        })
    }

    deleteAttachment(item) {
        api.create().deleteAttachment(item.attachment_id).then(response => {
d.arizona's avatar
d.arizona committed
2367
            // // // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
2368 2369
            if (response.data) {
                if (response.data.status === "success") {
Deni Rinaldi's avatar
Deni Rinaldi committed
2370
                    this.getSubmission()
Deni Rinaldi's avatar
Deni Rinaldi committed
2371 2372
                }
            }
2373 2374
        })
    }
Deni Rinaldi's avatar
Deni Rinaldi committed
2375

Deni Rinaldi's avatar
Deni Rinaldi committed
2376 2377 2378 2379
    closeAlert() {
        this.setState({ alert: false })
    }

d.arizona's avatar
d.arizona committed
2380
    saveToMasterBudget(data, type) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2381
        this.setState({ loading: true }, () => {
idlanirined's avatar
idlanirined committed
2382 2383
            document.body.style.overflow = 'hidden';
        })
2384
        console.log(type);
Riri Novita's avatar
Riri Novita committed
2385
        // // console.log(JSON.stringify(data));
Deni Rinaldi's avatar
Deni Rinaldi committed
2386
        api.create('UPLOAD').createSubmitReport(data).then(response => {
Riri Novita's avatar
Riri Novita committed
2387
            console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
2388
            if (response.data) {
d.arizona's avatar
d.arizona committed
2389 2390
                if (response.ok) {
                    if (response.data.status === 'success') {
Riri Novita's avatar
Riri Novita committed
2391
                        if (type === "PL" || type === "DraftPL") {
Riri Novita's avatar
Riri Novita committed
2392
                            this.setState({ visiblePL: false, visibleBudgetTahunan: true, loading: false })
Riri Novita's avatar
Riri Novita committed
2393
                        } else if (type === "TP" || type === "DraftTP") {
Riri Novita's avatar
Riri Novita committed
2394
                            this.setState({ visibleTP: false, visibleBudgetTahunan: true, loading: false })
Riri Novita's avatar
Riri Novita committed
2395
                        } else if (type === "BS" || type === "DraftBS") {
Riri Novita's avatar
Riri Novita committed
2396
                            this.setState({ visibleBS: false, visibleBudgetTahunan: true, loading: false })
Riri Novita's avatar
Riri Novita committed
2397
                        } else if (type === "FAM" || type === "DraftFAM") {
Riri Novita's avatar
Riri Novita committed
2398
                            this.setState({ visibleFAM: false, visibleBudgetTahunan: true, loading: false })
Riri Novita's avatar
Riri Novita committed
2399
                        } else if (type === "CAT" || type === "DraftCAT") {
Riri Novita's avatar
Riri Novita committed
2400
                            this.setState({ visibleCAT: false, visibleBudgetTahunan: true, loading: false })
2401
                        } else {
Riri Novita's avatar
Riri Novita committed
2402
                            this.setState({ visibleBudgetTahunan: true, visiblePL: false, visibleTP: false, visibleBS: false, visibleFAM: false, visibleCAT: false, loading: false })
2403
                        }
d.arizona's avatar
d.arizona committed
2404
                        this.getSubmission(type)
d.arizona's avatar
d.arizona committed
2405
                    } else {
2406 2407 2408 2409 2410 2411 2412 2413
                        console.log(response.data);
                        if (response.data.message == "Please Set Up Rate Currency First") {
                            this.setState({ visibleAlertSave: true })
                        } else {
                            // this.setState({ loading: false }, () => {
                            this.getSubmission()
                            document.body.style.overflow = 'unset';
                        }
d.arizona's avatar
d.arizona committed
2414
                        // })
d.arizona's avatar
d.arizona committed
2415
                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
2416
                } else {
d.arizona's avatar
d.arizona committed
2417
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
2418
                        this.getSubmission()
idlanirined's avatar
idlanirined committed
2419
                        document.body.style.overflow = 'unset';
d.arizona's avatar
d.arizona committed
2420
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
2421
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
2422
            } else {
d.arizona's avatar
d.arizona committed
2423
                this.setState({ alert: true, messageAlert: 'Error saving data. Please try again', tipeAlert: 'error', loading: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
2424
                    this.getSubmission()
idlanirined's avatar
idlanirined committed
2425
                    document.body.style.overflow = 'unset';
Deni Rinaldi's avatar
Deni Rinaldi committed
2426
                })
Deni Rinaldi's avatar
Deni Rinaldi committed
2427 2428
            }
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2429 2430
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
2431 2432 2433
    async downloadAttachment(fileurl, name) {
        let length = name.split(".").length
        let fileType = name.split(".")[length - 1]
d.arizona's avatar
d.arizona committed
2434
        // // // console.log(fileType);
faisalhamdi's avatar
faisalhamdi committed
2435
        let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/master_budget/download_attachment?fileName=${fileurl}&&fileType=${fileType}`
d.arizona's avatar
d.arizona committed
2436
        // // // console.log(url);
Deni Rinaldi's avatar
Deni Rinaldi committed
2437
        let res = await fetch(
faisalhamdi's avatar
faisalhamdi committed
2438
            `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/master_budget/download_attachment?fileName=${fileurl}&&fileType=${fileType}`
Deni Rinaldi's avatar
Deni Rinaldi committed
2439 2440
        )
        res = await res.blob()
Deni Rinaldi's avatar
Deni Rinaldi committed
2441
        this.setState({ loading: false }, () => {
idlanirined's avatar
idlanirined committed
2442 2443
            document.body.style.overflow = 'unset';
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2444 2445 2446 2447
        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
2448
            a.download = 'Master Budget Attachment.xlsx';
Deni Rinaldi's avatar
Deni Rinaldi committed
2449 2450 2451 2452
            a.click();
        }
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
2453
    validate() {
Deni Rinaldi's avatar
Deni Rinaldi committed
2454
        this.setState({ loading: true }, () => {
idlanirined's avatar
idlanirined committed
2455 2456
            document.body.style.overflow = 'hidden';
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2457
        let array = []
Deni Rinaldi's avatar
Deni Rinaldi committed
2458
        let canSubmit = true
Deni Rinaldi's avatar
Deni Rinaldi committed
2459
        this.state.dataTable.map(item => {
idlanirined's avatar
idlanirined committed
2460 2461
            // if (item[1] !== 'Cash Flow') {
            if (item[3] !== "submitted" && item[3] !== 'approved') {
d.arizona's avatar
d.arizona committed
2462
                canSubmit = false
idlanirined's avatar
idlanirined committed
2463
                array.push(item[3])
Deni Rinaldi's avatar
Deni Rinaldi committed
2464
            }
idlanirined's avatar
idlanirined committed
2465
            // }
Deni Rinaldi's avatar
Deni Rinaldi committed
2466 2467 2468 2469 2470
            // if (item[3].includes("not-yet") || item[3].includes("draft")) {
            //     array.push(item[3])
            // } else {
            //     array.push(item[3])
            // }
Deni Rinaldi's avatar
Deni Rinaldi committed
2471
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2472 2473 2474 2475
        if (canSubmit === true) {
            let body = {
                submission_id: this.state.submissionID
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
2476
            api.create().submitMasterBudget(body).then(response => {
d.arizona's avatar
d.arizona committed
2477
                // // // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
2478
                if (response.data) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2479
                    if (response.data.status === "success") {
Deni Rinaldi's avatar
Deni Rinaldi committed
2480
                        this.getSubmission()
Deni Rinaldi's avatar
Deni Rinaldi committed
2481 2482 2483
                    }
                }
            })
Deni Rinaldi's avatar
Deni Rinaldi committed
2484
        } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
2485
            this.setState({ alert: true, messageAlert: 'Data Is Not Complete', tipeAlert: 'warning', loading: false }, () => {
idlanirined's avatar
idlanirined committed
2486 2487
                document.body.style.overflow = 'unset';
            })
Deni Rinaldi's avatar
Deni Rinaldi committed
2488
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
2489
        // if (array.includes("not-yet" || "draft")) {
d.arizona's avatar
d.arizona committed
2490
        //     // // console.log('gagal');
Deni Rinaldi's avatar
Deni Rinaldi committed
2491
        // } else {
d.arizona's avatar
d.arizona committed
2492
        //     // // console.log('masuk');
Deni Rinaldi's avatar
Deni Rinaldi committed
2493 2494
        // }

Deni Rinaldi's avatar
Deni Rinaldi committed
2495
    }
Deni Rinaldi's avatar
Deni Rinaldi committed
2496

d.arizona's avatar
d.arizona committed
2497
    validateRevision() {
d.arizona's avatar
d.arizona committed
2498
        // this.scrollToMyRef()
d.arizona's avatar
d.arizona committed
2499 2500
        let arrayRevisi = this.state.detailRevisiCheck
        let remarksKosong = 0
Deni Rinaldi's avatar
Deni Rinaldi committed
2501
        arrayRevisi.map((item, index) => {
d.arizona's avatar
d.arizona committed
2502 2503 2504 2505
            if (item.remarks == "") {
                remarksKosong += 1
            }
        })
d.arizona's avatar
d.arizona committed
2506
        // // console.log(arrayRevisi)
d.arizona's avatar
d.arizona committed
2507
        if (arrayRevisi.length == 0 || remarksKosong > 0) {
d.arizona's avatar
d.arizona committed
2508 2509 2510 2511 2512 2513
            this.setState({ alert: true, messageAlert: 'Remarks Cannot be Empty', tipeAlert: 'error' })
        } else {
            this.setState({ visibleRevision: false }, () => this.approvalSubmission('revision'))
        }
    }

2514 2515 2516 2517
    handleApproveAdmin() {
        this.setState({ visibleApproveSuperadmin: true })
    }

qorri_di's avatar
qorri_di committed
2518
    handleSelectAll(data) {
Riri Novita's avatar
Riri Novita committed
2519
        // console.log(this.state.isCheckAll);
qorri_di's avatar
qorri_di committed
2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535
        if (this.state.isCheckAll) {
            let checkAll = []
            this.setState({ selectReport: checkAll, isCheckAll: false })
        } else {
            let checkAll = this.state.selectReport
            let isAllDetail = true
            data.map((item, index) => {
                if (item[5] === true) {
                    if (!this.state.selectReport.includes(item[4])) {
                        checkAll.push(item[4])
                    }
                } else {
                    isAllDetail = false
                    checkAll.splice(index, 1)
                }
            })
Riri Novita's avatar
Riri Novita committed
2536
            // console.log(checkAll);
qorri_di's avatar
qorri_di committed
2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555
            this.setState({ selectReport: checkAll, isCheckAll: isAllDetail })
        }
    }

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

    handleItemClick(item) {
        let indexID = this.state.selectReport.findIndex((val) => val === item.rowData[4])
        let selectReport = this.state.selectReport
        if (indexID === -1) {
            selectReport.push(item.rowData[4])
        } else {
            selectReport.splice(indexID, 1)
        }
        let isCheckAll = selectReport.length === this.state.dataTable.length
        this.setState({ selectReport, isCheckAll })
Riri Novita's avatar
Riri Novita committed
2556
        // console.log(selectReport);
qorri_di's avatar
qorri_di committed
2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568
    }

    handleDownloadReport(tableMeta) {
        let { selectReport, company, periode, month } = this.state
        let payload = {
            "company_id": company.company_id,
            "year": periode.periode,
            "report_id": selectReport,
            "month": "",
            "quartal": "",
            "type_report_name": "Master Budget"
        }
Riri Novita's avatar
Riri Novita committed
2569
        // console.log(payload);
qorri_di's avatar
qorri_di committed
2570
        api.create().createDownloadFile(payload).then((response) => {
Riri Novita's avatar
Riri Novita committed
2571
            // console.log(response)
qorri_di's avatar
qorri_di committed
2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        let data = response.data.data
                        this.setState({ downloadedFileReportId: data.downloadedFileReportId, popupDownload: true }, () => this.handleGenerateReport(tableMeta))
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
            } else {
                // this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error'})
                alert(response.problem)
            }
        })
    }

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

    async handleGenerateReport(data) {
Riri Novita's avatar
Riri Novita committed
2607
        let { selectReport, submissionID, company, periode, month, downloadedFileReportId, defaultCurrency } = this.state
qorri_di's avatar
qorri_di committed
2608 2609
        if (selectReport.length > 0) {
            let result = []
Riri Novita's avatar
Riri Novita committed
2610
            // console.log('mulai hit')
qorri_di's avatar
qorri_di committed
2611 2612 2613 2614
            for (const items of selectReport) {
                let datas = data.findIndex((val) => val[4] == items)
                let report = data[datas]
                if (items === 6) {
Riri Novita's avatar
Riri Novita committed
2615 2616
                    let resReal = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/cash_flow/master_budget/export_master_budget?submission_id=${submissionID}&company_id=${company.company_id}&year=${periode.periode}&revision=${report[2]}&report_id=${report[4]}&download_file_report_id=${downloadedFileReportId}&currency_id=${defaultCurrency.id}`
                    let resNull = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/cash_flow/master_budget/export_master_budget?submission_id=&&company_id=${company.company_id}&year=${periode.periode}&revision=${report[2]}&report_id=${report[4]}&download_file_report_id=${downloadedFileReportId}&currency_id=${defaultCurrency.id}`
qorri_di's avatar
qorri_di committed
2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629

                    let res = await fetch(
                        submissionID == null ? resNull : resReal
                    )
                    if (res.size > 0) {
                        let url = window.URL.createObjectURL(res);
                        let a = document.createElement('a');
                        a.href = url;
                    }
                    if (res.status === 200) {
                        result = [...result, res];
                    }
                } else {
Riri Novita's avatar
Riri Novita committed
2630 2631
                    let resReal = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/master_budget/export_master_budget?submission_id=${submissionID}&report_id=${report[4]}&company_id=${company.company_id}&year=${periode.periode}&revision=${report[2]}&download_file_report_id=${downloadedFileReportId}&currency_id=${defaultCurrency.id}`
                    let resNull = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/master_budget/export_master_budget?submission_id=&report_id=${report[4]}&company_id=${company.company_id}&year=${periode.periode}&revision=${report[2]}&download_file_report_id=${downloadedFileReportId}&currency_id=${defaultCurrency.id}`
qorri_di's avatar
qorri_di committed
2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646

                    let res = await fetch(
                        submissionID == null ? resNull : resReal
                    )
                    if (res.size > 0) {
                        let url = window.URL.createObjectURL(res);
                        let a = document.createElement('a');
                        a.href = url;
                    }
                    if (res.status === 200) {
                        result = [...result, res];
                    }
                }
            }

Riri Novita's avatar
Riri Novita committed
2647
            // console.log('ini result', result);
qorri_di's avatar
qorri_di committed
2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690
            // every untuk cek ke setiap result di dalam array
            if (result.every((e) => e.status == 200)) {
                this.handleZip();
            }
            // Promise untuk ngumpulin semua result yg statusnya 200
            // const result = await Promise.all(selectReport.map(async (items) => {
            //     let datas = data.findIndex((val) => val[4] == items)
            //     let report = data[datas]
            //     if (items === 6) {
            //         let resReal = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/cash_flow/master_budget/export_master_budget?submission_id=${submissionID}&&company_id=${company.company_id}&&year=${periode.periode}&&revision=${report[2]}&&report_id=${report[4]}&&download_file_report_id=${downloadedFileReportId}`
            //         let resNull = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/cash_flow/master_budget/export_master_budget?submission_id=&&company_id=${company.company_id}&&year=${periode.periode}&&revision=${report[2]}&&report_id=${report[4]}&&download_file_report_id=${downloadedFileReportId}`
            //         // console.log('cash_flow start', Date.now())
            //         let res = await fetch(
            //             this.props.submissionID == null ? resNull : resReal
            //         )
            //         // console.log('cash_flow end', Date.now())
            //         // console.log(res);
            //         if (res.status === 200) {
            //             // this.setState({ arrayReport: [...this.state.arrayReport, items] })
            //             return res;
            //         }
            //     } else {
            //         let resReal = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/master_budget/export_master_budget?submission_id=${submissionID}&&report_id=${report[4]}&&company_id=${company.company_id}&&year=${periode.periode}&&revision=${report[2]}&&download_file_report_id=${downloadedFileReportId}`
            //         let resNull = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/master_budget/export_master_budget?submission_id=&&report_id=${report[4]}&&company_id=${company.company_id}&&year=${periode.periode}&&revision=${report[2]}&&download_file_report_id=${downloadedFileReportId}`

            //         // console.log('master_budget start', Date.now())
            //         let res = await fetch(
            //             this.props.submissionID == null ? resNull : resReal
            //         )
            //         // console.log('master_budget end', Date.now())
            //         // console.log(res);
            //         if (res.status === 200) {
            //             // this.setState({ arrayReport: [...this.state.arrayReport, items] })
            //             return res;
            //         }
            //     }

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

    async handleZip() {
Riri Novita's avatar
Riri Novita committed
2691
        // console.log('mulai zip')
qorri_di's avatar
qorri_di committed
2692
        api.create().createZipReport(this.state.downloadedFileReportId).then((response) => {
Riri Novita's avatar
Riri Novita committed
2693
            console.log(response)
qorri_di's avatar
qorri_di committed
2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        this.setState({ arrayReport: [] })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
            } else {
                // this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error'})
                alert(response.problem)
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
2718
    render() {
d.arizona's avatar
d.arizona committed
2719 2720
        const handleMaxDate = () => {
            let handleDate = Number(moment(this.state.maxDateRevision).format('YYYYMMDD')) - Number(moment(this.state.minDateRevision).format('YYYYMMDD'))
Deni Rinaldi's avatar
Deni Rinaldi committed
2721
            return handleDate < 0 ? moment(this.state.minDateRevision).format('YYYY/MM/DD') : moment(this.state.maxDateRevision).format('YYYY/MM/DD')
d.arizona's avatar
d.arizona committed
2722
        }
2723
        const columns = ["#", "Report Type",
Deni Rinaldi's avatar
Deni Rinaldi committed
2724
            {
2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740
                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 => {
d.arizona's avatar
d.arizona committed
2741
                                                // // // console.log(event.target)
2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757
                                                updateValue(event.target.value)
                                                this.handleChange(event.target.value, tableMeta)
                                            }}
                                            autoWidth
                                        >
                                            {list.map((item, index) =>
                                                <MenuItem key={index} value={item}>{item}</MenuItem>
                                            )}
                                        </Select>
                                    }
                                />
                            </div >
                        );
                    }
                }
            }, {
Deni Rinaldi's avatar
Deni Rinaldi committed
2758 2759 2760 2761 2762
                name: "Status",
                options: {
                    customBodyRender: (val, tableMeta) => {
                        return (
                            <div style={{ display: 'flex' }}>
2763
                                {val === "submitted" || val === "approved" ?
Deni Rinaldi's avatar
Deni Rinaldi committed
2764
                                    <span>COMPLETED</span> :
Deni Rinaldi's avatar
Deni Rinaldi committed
2765
                                    val === "draft" ?
Deni Rinaldi's avatar
Deni Rinaldi committed
2766
                                        <span>DRAFT</span> :
Deni Rinaldi's avatar
Deni Rinaldi committed
2767 2768 2769 2770
                                        val === "incomplete" ?
                                            <span>INCOMPLETE</span> :
                                            val === "revision" ?
                                                <span>REVISION</span> :
d.arizona's avatar
d.arizona committed
2771
                                                val === "approval_process" ?
Deni Rinaldi's avatar
Deni Rinaldi committed
2772 2773 2774 2775 2776 2777 2778 2779
                                                    <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 }} />
Deni Rinaldi's avatar
Deni Rinaldi committed
2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794
                                }
                            </div >
                        );
                    }
                }
            },
            {
                name: "Action",
                options: {
                    customBodyRender: (val, tableMeta) => {
                        return (
                            <div style={{ display: 'flex' }}>
                                <button
                                    style={{
                                        backgroundColor: 'transparent',
d.arizona's avatar
d.arizona committed
2795
                                        cursor: tableMeta.rowData[5] ? 'pointer' : 'default',
Deni Rinaldi's avatar
Deni Rinaldi committed
2796 2797
                                        borderColor: 'transparent'
                                    }}
Deni Rinaldi's avatar
Deni Rinaldi committed
2798
                                    onClick={() =>
d.arizona's avatar
d.arizona committed
2799
                                        tableMeta.rowData[5] == true ?
2800 2801
                                            this.clickDetail(tableMeta.rowData[1], tableMeta.rowData[4], tableMeta.rowData[2], tableMeta.rowData[3])
                                            : null
2802
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
2803
                                >
Deni Rinaldi's avatar
Deni Rinaldi committed
2804
                                    {/* {this.state.isApprover == true ?
a.bairuha's avatar
a.bairuha committed
2805 2806 2807
                                        (tableMeta.rowData[5] ? '#5198ea' : 'GrayText') :
                                        (this.state.lastRevision == 0 ? (tableMeta.rowData[5] ? '#5198ea' : 'GrayText') :
                                        (tableMeta.rowData[3] !== 'submitted' ? '#5198ea' : 'GrayText'))} */}
d.arizona's avatar
d.arizona committed
2808
                                    <Typography style={{ color: tableMeta.rowData[5] ? '#5198ea' : 'GrayText', fontSize: 12, }}>Detail</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
2809 2810 2811 2812 2813
                                </button>
                            </div >
                        );
                    }
                }
qorri_di's avatar
qorri_di committed
2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829
            }, {
                name: "Download",
                options: {
                    customBodyRender: (val, tableMeta) => {
                        // console.log(tableMeta);
                        return (
                            <div style={{ display: 'flex' }}>
                                <CustomCheckbox
                                    checked={this.handleItemChecked(tableMeta)}
                                    onChange={() => tableMeta.rowData[5] == true ? this.handleItemClick(tableMeta) : null}
                                    disabled={tableMeta.rowData[5] == true ? false : true}
                                />
                            </div >
                        );
                    }
                }
2830 2831 2832 2833 2834 2835
            }, {
                name: "",
                options: { display: false }
            }, {
                name: "",
                options: { display: false }
Deni Rinaldi's avatar
Deni Rinaldi committed
2836
            }]
Deni Rinaldi's avatar
Deni Rinaldi committed
2837 2838 2839 2840

        const columnsHistory = [
            "Name", "Status", "Remarks", "Revision Item", "Date"
        ]
Deni Rinaldi's avatar
Deni Rinaldi committed
2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856

        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={
Deni Rinaldi's avatar
Deni Rinaldi committed
2857 2858 2859
                                        <Checkbox
                                            checked={this.state.detailRevisiCheck.findIndex((val) => val.report_id == tableMeta.rowData[0]) == -1 ? false : true}
                                            onClick={() => handleCheckRevision(tableMeta.rowData)} />
Deni Rinaldi's avatar
Deni Rinaldi committed
2860 2861 2862 2863 2864 2865
                                    }
                                />
                            </div >
                        );
                    }
                }
d.arizona's avatar
d.arizona committed
2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884
            }, "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) => {
d.arizona's avatar
d.arizona committed
2885
                                                // // // console.log(event.target.value)
d.arizona's avatar
d.arizona committed
2886 2887
                                                // updateValue(event.target.value)
                                                handleChangeText(event.target.value, tableMeta)
d.arizona's avatar
d.arizona committed
2888
                                                // // // console.log(dataTable2)
d.arizona's avatar
d.arizona committed
2889 2890
                                            }}
                                        />}
Deni Rinaldi's avatar
Deni Rinaldi committed
2891
                                />
d.arizona's avatar
d.arizona committed
2892 2893 2894 2895
                            </div>
                        )
                    }
                }
d.arizona's avatar
d.arizona committed
2896 2897 2898
            }, {
                name: "",
                options: { display: false }
d.arizona's avatar
d.arizona committed
2899
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
2900 2901
        ]

d.arizona's avatar
d.arizona committed
2902 2903 2904 2905 2906 2907 2908 2909 2910 2911
        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
            }

Deni Rinaldi's avatar
Deni Rinaldi committed
2912
            this.setState({ dataTableRevision, detailRevisiCheck })
d.arizona's avatar
d.arizona committed
2913 2914 2915 2916 2917 2918
        }

        const handleCheckRevision = (value) => {
            let detailRevisiCheck = this.state.detailRevisiCheck
            let payload = {
                report_id: value[0],
d.arizona's avatar
d.arizona committed
2919 2920
                remarks: value[2],
                number: value[3]
d.arizona's avatar
d.arizona committed
2921
            }
d.arizona's avatar
d.arizona committed
2922
            let indexDataRevisi = this.state.dataTableRevision.findIndex((val) => val[3] == value[3])
Deni Rinaldi's avatar
Deni Rinaldi committed
2923
            let indexId = detailRevisiCheck.sort((a, b) => a.number - b.number).findIndex((val) => val.number == value[3])
d.arizona's avatar
d.arizona committed
2924
            // // console.log(indexId)
d.arizona's avatar
d.arizona committed
2925
            if (indexId == -1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2926
                this.state.dataTableRevision.map((item, index) => {
d.arizona's avatar
d.arizona committed
2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938
                    if (index > indexDataRevisi) {
                        let indexIds = detailRevisiCheck.findIndex((val) => val.number == item[3])
                        if (indexIds == -1) {
                            let payload2 = {
                                report_id: item[0],
                                remarks: item[2],
                                number: item[3]
                            }
                            detailRevisiCheck.push(payload2)
                        }
                    }
                })
d.arizona's avatar
d.arizona committed
2939 2940
                detailRevisiCheck.push(payload)
            } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
2941

d.arizona's avatar
d.arizona committed
2942
                let x = 0
Deni Rinaldi's avatar
Deni Rinaldi committed
2943
                detailRevisiCheck.sort((a, b) => a.number - b.number).map((item, index) => {
d.arizona's avatar
d.arizona committed
2944 2945 2946 2947 2948
                    if (item.number < value[3]) {
                        x += 1
                    }
                })
                if (x < 1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2949
                    this.state.dataTableRevision.map((item, index) => {
d.arizona's avatar
d.arizona committed
2950 2951 2952 2953 2954 2955 2956 2957 2958
                        if (index > indexDataRevisi) {
                            let indexIdz = detailRevisiCheck.findIndex((val) => val.number == item[3])
                            if (indexIdz !== -1) {
                                detailRevisiCheck.splice(indexIdz, 1)
                            }
                        }
                    })
                    detailRevisiCheck.splice(indexId, 1)
                }
d.arizona's avatar
d.arizona committed
2959
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
2960
            this.setState({ detailRevisiCheck: detailRevisiCheck.sort((a, b) => a.number - b.number) })
d.arizona's avatar
d.arizona committed
2961
            // // console.log(detailRevisiCheck)
d.arizona's avatar
d.arizona committed
2962 2963
        }

Deni Rinaldi's avatar
Deni Rinaldi committed
2964 2965 2966 2967 2968 2969 2970 2971
        const options = {
            filter: false,
            sort: false,
            responsive: "scroll",
            print: false,
            download: false,
            selectableRows: false,
            viewColumns: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2972
            pagination: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2973 2974
            search: false
        }
d.arizona's avatar
d.arizona committed
2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987
        const optionsHistory = {
            filter: false,
            sort: false,
            responsive: "scroll",
            print: false,
            download: false,
            selectableRows: false,
            viewColumns: false,
            pagination: true,
            search: false,
            rowsPerPage: 5
        }

Deni Rinaldi's avatar
Deni Rinaldi committed
2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998
        const optionsRevision = {
            filter: false,
            sort: false,
            responsive: "scroll",
            print: false,
            download: false,
            selectableRows: false,
            viewColumns: false,
            pagination: false,
            search: false
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
2999
        const loadingComponent = (
idlanirined's avatar
idlanirined committed
3000
            <div style={{ position: 'fixed', zIndex: 110, top: 0, left: 0, width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', background: 'rgba(255,255,255,0.8)' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3001 3002 3003 3004 3005 3006 3007 3008
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
            </div>
        );
Deni Rinaldi's avatar
Deni Rinaldi committed
3009
        return (
d.arizona's avatar
d.arizona committed
3010
            <div style={{ flex: 1, backgroundColor: '#f8f8f8' }} >
Deni Rinaldi's avatar
Deni Rinaldi committed
3011 3012 3013 3014 3015
                <Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
                    <Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
                        {this.state.messageAlert}
                    </Alert>
                </Snackbar>
Deni Rinaldi's avatar
Deni Rinaldi committed
3016
                {this.state.loading && loadingComponent}
3017 3018 3019
                {this.state.visibleBudgetTahunan && (
                    <div>
                        <div className={"main-color"} style={{ height: 78, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3020
                            <Typography style={{ fontSize: '16px', color: 'white' }}>Master Budget & CAT Submission</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
3021
                        </div>
3022 3023 3024
                        <div style={{ padding: 20, width: '100%' }}>
                            <Paper style={{ paddingTop: 10 }}>
                                <div style={{ borderBottom: 'solid 1px #c4c4c4' }} >
3025
                                    <Typography style={{ fontSize: '12px', color: '#4b4b4b', margin: 10 }}>Master Budget</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
3026
                                </div>
3027
                                <div style={{ padding: 20 }}>
Riri Novita's avatar
Riri Novita committed
3028 3029
                                    <div style={{ display: "flex" }}>
                                        <div style={{ marginRight: 50 }}>
Riri Novita's avatar
Riri Novita committed
3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049
                                            <Autocomplete
                                                {...this.state.listPeriode}
                                                id="periode"
                                                onChange={(event, newInputValue) => this.setState({ periode: newInputValue }, () => {
                                                    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>
Riri Novita's avatar
Riri Novita committed
3050
                                        <div style={{ width: 255 }}>
Riri Novita's avatar
Riri Novita committed
3051
                                            <Autocomplete
Riri Novita's avatar
Riri Novita committed
3052 3053 3054 3055 3056
                                                id="tipe"
                                                disableClearable
                                                options={this.state.currency}
                                                getOptionLabel={(option) => option.value}
                                                value={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3057 3058 3059 3060
                                                // onChange={(event, newInputValue) => this.setState({ defaultCurrency: newInputValue })}
                                                onChange={(event, newInputValue) => this.setState({ defaultCurrency: newInputValue }, () => {
                                                    this.getRevision()
                                                })}
Riri Novita's avatar
Riri Novita committed
3061 3062 3063 3064
                                                renderInput={(params) =>
                                                    <TextField
                                                        {...params}
                                                        variant="standard"
Riri Novita's avatar
Riri Novita committed
3065
                                                        label="Currency"
Riri Novita's avatar
Riri Novita committed
3066 3067 3068 3069 3070 3071 3072 3073 3074
                                                        margin="normal"
                                                        style={{ marginTop: 6 }}
                                                    // InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
                                                    // InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
                                                    />
                                                }

                                            />
                                            {/* <Autocomplete
Riri Novita's avatar
Riri Novita committed
3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089
                                                options={this.state.dataCurrency}
                                                getOptionLabel={(option) => option.value}
                                                onChange={(event, newInputValue) => this.setState({ currency: newInputValue })}
                                                renderInput={(params) => (
                                                    <TextField
                                                        {...params}
                                                        variant="standard"
                                                        label="Currency"
                                                        margin="normal"
                                                        style={{ marginTop: 0 }}
                                                        InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
                                                        InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
                                                    />
                                                )}
                                                value={this.state.currency == null ? "IDR" : this.state.currency}
Riri Novita's avatar
Riri Novita committed
3090
                                            /> */}
Riri Novita's avatar
Riri Novita committed
3091
                                        </div>
3092
                                    </div>
Riri Novita's avatar
Riri Novita committed
3093

3094
                                    <div style={{ marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3095 3096 3097
                                        <Autocomplete
                                            {...this.state.listCompany}
                                            id="company"
idlanirined's avatar
idlanirined committed
3098
                                            disabled={this.state.listCompany === null ? true : this.state.intent === 'Home' ? true : false}
3099
                                            onChange={(event, newInputValue) => this.setState({ company: newInputValue }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
3100
                                                this.setState({ visibleTableHistory: false })
qorri_di's avatar
qorri_di committed
3101
                                                // this.getLastPeriod()
Riri Novita's avatar
Riri Novita committed
3102
                                                this.getCurrency(newInputValue.company_id)
qorri_di's avatar
qorri_di committed
3103
                                                this.getRevision()
3104
                                            })}
Deni Rinaldi's avatar
Deni Rinaldi committed
3105 3106 3107 3108 3109
                                            disableClearable
                                            style={{ width: 250 }}
                                            renderInput={(params) => <TextField {...params} label="Company" margin="normal" style={{ marginTop: 7 }} />}
                                            value={this.state.company}
                                        />
3110 3111
                                    </div>
                                    <div style={{ marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3112
                                        {/* <Autocomplete
3113 3114 3115 3116 3117 3118
                                            {...this.state.listRevision}
                                            id="revision"
                                            onChange={(event, newInputValue) => this.setState({ revision: newInputValue }, () => {
                                                this.getReport()
                                                this.getReportAttachment()
                                            })}
Deni Rinaldi's avatar
Deni Rinaldi committed
3119
                                            disabled={true}
3120 3121 3122 3123
                                            disableClearable
                                            style={{ width: 250 }}
                                            renderInput={(params) => <TextField {...params} label="Revision" margin="normal" style={{ marginTop: 7 }} />}
                                            value={this.state.revision}
Deni Rinaldi's avatar
Deni Rinaldi committed
3124 3125
                                        /> */}
                                        <TextField disabled={true} label="Revision" margin="normal" style={{ marginTop: 7, width: 250 }} value={this.state.lastRevision} />
3126 3127 3128
                                    </div>

                                    <div style={{ marginTop: 20 }}>
qorri_di's avatar
qorri_di committed
3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160
                                        <div style={{ display: 'flex', justifyContent: 'flex-end', margin: '24px 5px' }}>
                                            <button
                                                className="button"
                                                type="button"
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    outline: 'none',
                                                    marginRight: 20
                                                }}
                                                onClick={() => this.handleSelectAll(this.state.dataTable)}
                                            >
                                                <div style={{ backgroundColor: '#fff', width: 100, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #354960' }}>
                                                    <Typography style={{ fontSize: '11px', color: '#354960', textAlign: 'center' }}>Check All</Typography>
                                                </div>
                                            </button>
                                            <button
                                                type="button"
                                                disabled={this.state.buttonError}
                                                onClick={() => this.state.selectReport.length > 0 ? this.handleDownloadReport(this.state.dataTable) : alert("Anda harus memilih report yang ingin di download terlebih dahulu!")}
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    borderColor: 'transparent',
                                                    outline: 'none',
                                                }}
                                            >
                                                <div style={{ backgroundColor: '#354960', width: 100, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                                    <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Download</Typography>
                                                </div>
                                            </button>
                                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3161 3162 3163 3164 3165 3166 3167
                                        <MuiThemeProvider theme={getMuiTheme()}>
                                            <MUIDataTable
                                                data={this.state.dataTable}
                                                columns={columns}
                                                options={options}
                                            />
                                        </MuiThemeProvider>
3168 3169 3170 3171 3172
                                    </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
3173
                                        {!this.state.isApprover && (this.state.lastStatus === 'SUBMIT' || this.state.lastStatus === 'REVISION') && (
Deni Rinaldi's avatar
Deni Rinaldi committed
3174 3175 3176 3177
                                            <div style={{ width: '50%' }}>
                                                <button
                                                    style={{
                                                        backgroundColor: 'transparent',
Deni Rinaldi's avatar
Deni Rinaldi committed
3178
                                                        cursor: this.state.isSubmit === false ? 'default' : 'pointer',
Deni Rinaldi's avatar
Deni Rinaldi committed
3179 3180 3181
                                                        borderColor: 'transparent',
                                                        outline: 'none'
                                                    }}
Deni Rinaldi's avatar
Deni Rinaldi committed
3182
                                                    onClick={() => this.state.isSubmit === false ? null : this.setState({ visibleUpload: true })}
Deni Rinaldi's avatar
Deni Rinaldi committed
3183
                                                >
Deni Rinaldi's avatar
Deni Rinaldi committed
3184
                                                    <Typography style={{ fontSize: '16px', color: this.state.isSubmit === false ? 'GrayText' : '#5198ea' }}>Upload File</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
3185 3186 3187
                                                </button>
                                            </div>
                                        )}
3188 3189 3190
                                    </div>
                                    <div style={{ display: 'flex', marginTop: 10 }}>
                                        <div style={{ width: '50%', paddingLeft: 20 }}>
3191
                                            {this.state.listAttachment.length > 0 ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3192
                                                this.state.listAttachment.map((item, index) => {
3193
                                                    return (
Deni Rinaldi's avatar
Deni Rinaldi committed
3194
                                                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3195
                                                            <Typography style={{ fontSize: '13px', color: '#4b4b4b', width: 25 }}>{index + 1}. </Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209

                                                            <button
                                                                style={{
                                                                    backgroundColor: 'transparent',
                                                                    cursor: 'pointer',
                                                                    borderColor: 'transparent',
                                                                    outline: 'none',
                                                                    display: 'grid'
                                                                }}
                                                                onClick={() => {
                                                                    this.downloadAttachment(item.attachment_url, item.attachment_name)
                                                                }}
                                                            >
                                                                <div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3210
                                                                    <Typography style={{ fontSize: '13px', color: '#5198ea' }}> {item.attachment_name}</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
3211 3212 3213
                                                                </div>
                                                            </button>
                                                        </div>
3214 3215 3216 3217
                                                    )
                                                })
                                                : null
                                            }
3218
                                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3219
                                        {!this.state.isApprover && (this.state.lastStatus === 'SUBMIT' || this.state.lastStatus === 'REVISION') && (
Deni Rinaldi's avatar
Deni Rinaldi committed
3220
                                            <div style={{ width: '50%' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3221
                                                {
Deni Rinaldi's avatar
Deni Rinaldi committed
3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239
                                                    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
Deni Rinaldi's avatar
Deni Rinaldi committed
3240 3241 3242
                                                }
                                            </div>
                                        )}
3243
                                    </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3244
                                    {this.state.checkApprover === true ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3245
                                        this.state.lastStatus === 'WAITING FOR REVIEW' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3246
                                            <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3247 3248
                                                <span>{this.state.lastStatus}</span>
                                            </div> : this.state.lastStatus === 'WAITING FOR YOUR APPROVAL' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3249
                                                <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3250
                                                    <span>{this.state.lastStatus}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
3251 3252 3253
                                                </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>
Deni Rinaldi's avatar
Deni Rinaldi committed
3254 3255 3256 3257
                                                    </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
Deni Rinaldi's avatar
Deni Rinaldi committed
3258 3259
                                        :
                                        this.state.lastStatus === 'SUBMITTED' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3260
                                            <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3261 3262 3263
                                                <span>{this.state.lastStatus}</span>
                                            </div> :
                                            this.state.lastStatus === 'WAITING FOR APPROVAL' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3264
                                                <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
d.arizona's avatar
d.arizona committed
3265
                                                    <span>{`${this.state.lastStatus} - ${this.state.pic}`}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
3266 3267
                                                </div> :
                                                this.state.lastStatus === 'REVISION' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3268
                                                    <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3269 3270 3271
                                                        <span>NEED REVISION</span>
                                                    </div> :
                                                    this.state.lastStatus === 'APPROVED' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3272
                                                        <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3273 3274 3275
                                                            <span>APPROVED</span>
                                                        </div> : null
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
3276 3277 3278 3279 3280 3281
                                    {this.state.visibleTableHistory && (
                                        <div style={{ marginTop: 20 }}>
                                            <MuiThemeProvider theme={getMuiTheme()}>
                                                <MUIDataTable
                                                    data={this.state.dataTableHistory}
                                                    columns={columnsHistory}
d.arizona's avatar
d.arizona committed
3282
                                                    options={optionsHistory}
Deni Rinaldi's avatar
Deni Rinaldi committed
3283 3284 3285 3286
                                                />
                                            </MuiThemeProvider>
                                        </div>
                                    )}
Deni Rinaldi's avatar
Deni Rinaldi committed
3287
                                </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3288
                                {this.state.isAdmin && this.state.lastStatus == 'APPROVED' ?
Dida Adams Arizona's avatar
Dida Adams Arizona committed
3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320
                                    <div className="grid grid-2x" style={{ borderTop: 'solid 1px #c4c4c4', padding: 10, backgroundColor: '#f5f5f5', width: '100%', }}>
                                        <div className="col-1" />
                                        <div className="col-2" style={{ display: 'flex', justifyContent: 'flex-end', maxWidth: '100%' }}>
                                            <button
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    outline: 'none',
                                                    marginRight: 20
                                                }}
                                                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>
                                            {/* <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>
Deni Rinaldi's avatar
Deni Rinaldi committed
3321
                                    :
3322 3323 3324 3325
                                    this.state.isAdmin && (this.state.lastStatus == 'WAITING FOR YOUR APPROVAL' || this.state.lastStatus == 'WAITING FOR APPROVAL') ?
                                        <div className="grid grid-2x" style={{ borderTop: 'solid 1px #c4c4c4', padding: 10, backgroundColor: '#f5f5f5', width: '100%', }}>
                                            <div className="col-1" />
                                            <div className="col-2" style={{ display: 'flex', justifyContent: 'flex-end', maxWidth: '100%' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3326 3327 3328 3329 3330 3331 3332
                                                <button
                                                    style={{
                                                        backgroundColor: 'transparent',
                                                        cursor: 'pointer',
                                                        borderColor: 'transparent',
                                                        outline: 'none',
                                                    }}
3333
                                                    onClick={() => this.handleApproveAdmin()}
Deni Rinaldi's avatar
Deni Rinaldi committed
3334
                                                >
Deni Rinaldi's avatar
Deni Rinaldi committed
3335
                                                    <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
3336
                                                        <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Approve</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
3337 3338
                                                    </div>
                                                </button>
3339 3340
                                            </div>
                                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3341
                                        :
3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394
                                        this.state.checkApprover === true ?
                                            this.state.lastStatus === 'WAITING FOR REVIEW' ?
                                                <div style={{ borderTop: 'solid 1px #c4c4c4', padding: 10, backgroundColor: '#f5f5f5', width: '100%', display: 'flex', justifyContent: 'flex-end' }} >
                                                    <button
                                                        style={{
                                                            backgroundColor: 'transparent',
                                                            cursor: 'pointer',
                                                            borderColor: 'transparent',
                                                            outline: 'none',
                                                        }}
                                                        onClick={() =>
                                                            this.approvalSubmission('review')
                                                        }
                                                    >
                                                        <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                                            <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Review</Typography>
                                                        </div>
                                                    </button>
                                                </div> : (this.state.lastStatus === 'WAITING FOR YOUR APPROVAL' && this.state.btnApprove) ?
                                                    <div className="grid grid-2x" style={{ borderTop: 'solid 1px #c4c4c4', padding: 10, backgroundColor: '#f5f5f5', width: '100%', }}>
                                                        <div className="col-1" />
                                                        <div className="col-2" style={{ display: 'flex', justifyContent: 'flex-end', maxWidth: '100%' }}>
                                                            <button
                                                                style={{
                                                                    backgroundColor: 'transparent',
                                                                    cursor: 'pointer',
                                                                    borderColor: 'transparent',
                                                                    outline: 'none',
                                                                    marginRight: 20
                                                                }}
                                                                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>
                                                            <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 ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3395 3396 3397 3398 3399 3400 3401 3402
                                                <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',
                                                        }}
3403
                                                        onClick={() => this.validate()}
Deni Rinaldi's avatar
Deni Rinaldi committed
3404
                                                    >
3405 3406
                                                        <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>
Deni Rinaldi's avatar
Deni Rinaldi committed
3407 3408
                                                        </div>
                                                    </button>
3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425
                                                </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
Deni Rinaldi's avatar
Deni Rinaldi committed
3426
                                }
3427 3428
                            </Paper>

Deni Rinaldi's avatar
Deni Rinaldi committed
3429
                        </div>
3430
                    </div>
idlanirined's avatar
idlanirined committed
3431 3432
                )
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
3433

idlanirined's avatar
idlanirined committed
3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451
                {
                    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>
3452 3453
                                    </div>
                                </div>
idlanirined's avatar
idlanirined committed
3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464
                                <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)}
                                />
3465 3466
                            </div>
                        </div>
idlanirined's avatar
idlanirined committed
3467 3468
                    )
                }
3469

idlanirined's avatar
idlanirined committed
3470 3471 3472 3473 3474 3475 3476 3477
                {
                    this.state.visibleBS && (
                        <BalanceSheet
                            open={this.props.open}
                            report_id={this.state.report_id}
                            height={this.props.height}
                            width={this.props.width}
                            company={this.state.company}
Riri Novita's avatar
Riri Novita committed
3478
                            defaultCurrency={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3479
                            currency={this.state.currency}
idlanirined's avatar
idlanirined committed
3480 3481 3482 3483 3484 3485 3486
                            revision={this.state.revisionTable}
                            periode={this.state.periode.periode}
                            submissionID={this.state.submissionID}
                            saveToMasterBudget={this.saveToMasterBudget.bind(this)}
                            onClickClose={() => this.setState({ visibleBS: false, visibleBudgetTahunan: true })}
                            getReport={this.getSubmission.bind(this)}
                            isApprover={this.state.isApprover}
syadziy's avatar
syadziy committed
3487
                            truelyApprover={this.state.truelyApprover}
idlanirined's avatar
idlanirined committed
3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501
                            lastStatus={this.state.lastStatus}
                            prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
                            status={this.state.status}
                        />
                    )
                }
                {
                    this.state.visiblePL && (
                        <ProfitLoss
                            open={this.props.open}
                            report_id={this.state.report_id}
                            height={this.props.height}
                            width={this.props.width}
                            company={this.state.company}
Riri Novita's avatar
Riri Novita committed
3502
                            defaultCurrency={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3503
                            currency={this.state.currency}
idlanirined's avatar
idlanirined committed
3504 3505 3506 3507 3508 3509 3510 3511
                            revision={this.state.revisionTable}
                            periode={this.state.periode.periode}
                            submissionID={this.state.submissionID}
                            saveToMasterBudget={this.saveToMasterBudget.bind(this)}
                            onClickClose={() => this.setState({ visiblePL: false, visibleBudgetTahunan: true })}
                            getReport={this.getSubmission.bind(this)}
                            status={this.state.status}
                            isApprover={this.state.isApprover}
syadziy's avatar
syadziy committed
3512
                            truelyApprover={this.state.truelyApprover}
idlanirined's avatar
idlanirined committed
3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525
                            lastStatus={this.state.lastStatus}
                            prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
                        />
                    )
                }
                {
                    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}
Riri Novita's avatar
Riri Novita committed
3526
                            defaultCurrency={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3527
                            currency={this.state.currency}
idlanirined's avatar
idlanirined committed
3528 3529 3530 3531 3532 3533 3534 3535
                            revision={this.state.revisionTable}
                            periode={this.state.periode.periode}
                            submissionID={this.state.submissionID}
                            saveToMasterBudget={this.saveToMasterBudget.bind(this)}
                            onClickClose={() => this.setState({ visibleTP: false, visibleBudgetTahunan: true })}
                            getReport={this.getSubmission.bind(this)}
                            status={this.state.status}
                            isApprover={this.state.isApprover}
syadziy's avatar
syadziy committed
3536
                            truelyApprover={this.state.truelyApprover}
idlanirined's avatar
idlanirined committed
3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549
                            lastStatus={this.state.lastStatus}
                            prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
                        />
                    )
                }
                {
                    this.state.visibleFAM && (
                        <FixedAssetsMovement
                            open={this.props.open}
                            report_id={this.state.report_id}
                            height={this.props.height}
                            width={this.props.width}
                            company={this.state.company}
Riri Novita's avatar
Riri Novita committed
3550
                            defaultCurrency={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3551
                            currency={this.state.currency}
idlanirined's avatar
idlanirined committed
3552 3553 3554 3555 3556 3557 3558 3559
                            revision={this.state.revisionTable}
                            periode={this.state.periode.periode}
                            submissionID={this.state.submissionID}
                            saveToMasterBudget={this.saveToMasterBudget.bind(this)}
                            onClickClose={() => this.setState({ visibleFAM: false, visibleBudgetTahunan: true })}
                            getReport={this.getSubmission.bind(this)}
                            status={this.state.status}
                            isApprover={this.state.isApprover}
syadziy's avatar
syadziy committed
3560
                            truelyApprover={this.state.truelyApprover}
idlanirined's avatar
idlanirined committed
3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573
                            lastStatus={this.state.lastStatus}
                            prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
                        />
                    )
                }
                {
                    this.state.visibleCAT && (
                        <CorporateAnnualTarget
                            open={this.props.open}
                            report_id={this.state.report_id}
                            height={this.props.height}
                            width={this.props.width}
                            company={this.state.company}
Riri Novita's avatar
Riri Novita committed
3574
                            defaultCurrency={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3575
                            currency={this.state.currency}
idlanirined's avatar
idlanirined committed
3576 3577 3578 3579 3580 3581 3582
                            revision={this.state.revisionTable}
                            periode={this.state.periode.periode}
                            submissionID={this.state.submissionID}
                            saveToMasterBudget={this.saveToMasterBudget.bind(this)}
                            onClickClose={() => this.setState({ visibleCAT: false, visibleBudgetTahunan: true })}
                            getReport={this.getSubmission.bind(this)}
                            isApprover={this.state.isApprover}
syadziy's avatar
syadziy committed
3583
                            truelyApprover={this.state.truelyApprover}
idlanirined's avatar
idlanirined committed
3584
                            status={this.state.status}
d.arizona's avatar
d.arizona committed
3585
                            // status={'not-yet'}
idlanirined's avatar
idlanirined committed
3586
                            lastStatus={this.state.lastStatus}
d.arizona's avatar
d.arizona committed
3587 3588
                            // lastStatus={'SUBMIT'}
                            // prevRevision={false}
idlanirined's avatar
idlanirined committed
3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600
                            prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
                        />
                    )
                }
                {
                    this.state.visibleCF && (
                        <CashFlow
                            open={this.props.open}
                            report_id={this.state.report_id}
                            height={this.props.height}
                            width={this.props.width}
                            company={this.state.company}
Riri Novita's avatar
Riri Novita committed
3601
                            defaultCurrency={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3602
                            currency={this.state.currency}
idlanirined's avatar
idlanirined committed
3603 3604 3605 3606 3607 3608 3609
                            revision={this.state.revisionTable}
                            periode={this.state.periode.periode}
                            submissionID={this.state.submissionID}
                            saveToMasterBudget={this.saveToMasterBudget.bind(this)}
                            onClickClose={() => this.setState({ visibleCF: false, visibleBudgetTahunan: true })}
                            getReport={this.getSubmission.bind(this)}
                            isApprover={this.state.isApprover}
syadziy's avatar
syadziy committed
3610
                            truelyApprover={this.state.truelyApprover}
idlanirined's avatar
idlanirined committed
3611 3612 3613
                            status={this.state.status}
                            lastStatus={this.state.lastStatus}
                            prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
d.arizona's avatar
d.arizona committed
3614
                            // PLBSFAMSubmitted={false}
3615
                            PLBSFAMSubmitted={this.state.lastStatus == 'APPROVED' ? true : false}
d.arizona's avatar
d.arizona committed
3616
                            createCashFlow={this.createCashFlow.bind(this)}
idlanirined's avatar
idlanirined committed
3617 3618 3619
                        />
                    )
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
3620

idlanirined's avatar
idlanirined committed
3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638
                {
                    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>
Deni Rinaldi's avatar
Deni Rinaldi committed
3639 3640
                                    </div>
                                </div>
idlanirined's avatar
idlanirined committed
3641 3642 3643 3644 3645 3646 3647 3648
                                <div className="border-bottom" style={{ padding: 20 }}>
                                    <span>You ask your subsidiary to make a revision</span>
                                    <div style={{ marginTop: 20 }}>
                                        <MuiThemeProvider theme={getMuiTheme()}>
                                            <MUIDataTable
                                                data={this.state.dataTableRevision}
                                                columns={columnRevisi}
                                                options={optionsRevision}
Deni Rinaldi's avatar
Deni Rinaldi committed
3649
                                            />
idlanirined's avatar
idlanirined committed
3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676
                                        </MuiThemeProvider>
                                    </div>
                                    <div style={{ marginTop: 20 }}>
                                        <span>Timing duration you give for revision:</span>
                                        <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 20 }}>
                                            <div>
                                                <DatePicker
                                                    margin="normal"
                                                    id="startDate"
                                                    label="Valid From"
                                                    format="dd-MM-yyyy"
                                                    onChange={(e) => this.setState({ minDateRevision: moment(e).format('YYYY/MM/DD') }, () => this.setState({ maxDateRevision: handleMaxDate() }))}
                                                    value={moment(this.state.minDateRevision).format('YYYY/MM/DD')}
                                                    KeyboardButtonProps={{
                                                        'aria-label': 'change date',
                                                    }}
                                                    inputProps={{
                                                        style: {
                                                            fontSize: 11
                                                        }
                                                    }}
                                                    InputLabelProps={{
                                                        style: {
                                                            fontSize: 11,
                                                            color: '#7e8085'
                                                        }
                                                    }}
Deni Rinaldi's avatar
Deni Rinaldi committed
3677

idlanirined's avatar
idlanirined committed
3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708
                                                    style={{ padding: 0, margin: 0, width: '100%' }}
                                                />
                                            </div>
                                            <span style={{ alignSelf: 'center' }}>Until</span>
                                            <div>
                                                <DatePicker
                                                    margin="normal"
                                                    id="startDate"
                                                    label="Valid To"
                                                    format="dd-MM-yyyy"
                                                    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')}
                                                    KeyboardButtonProps={{
                                                        'aria-label': 'change date',
                                                    }}
                                                    inputProps={{
                                                        style: {
                                                            fontSize: 11
                                                        }
                                                    }}
                                                    InputLabelProps={{
                                                        style: {
                                                            fontSize: 11,
                                                            color: '#7e8085'
                                                        }
                                                    }}

                                                    style={{ padding: 0, margin: 0, width: '100%' }}
                                                />
                                            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3709 3710 3711
                                        </div>
                                    </div>
                                </div>
idlanirined's avatar
idlanirined committed
3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732
                                <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"
                                            onClick={() => this.validateRevision()}
                                        >
                                            <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>
Deni Rinaldi's avatar
Deni Rinaldi committed
3733 3734 3735
                                </div>
                            </div>
                        </div>
idlanirined's avatar
idlanirined committed
3736 3737
                    )
                }
3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788

                {this.state.visibleApproveSuperadmin && (
                    <div className="test app-popup-show">
                        <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
                            <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
                                <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                                    <div className="popup-title">
                                        <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Superadmin Approve</span>
                                    </div>
                                </div>
                                <div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
                                    <button
                                        type="button"
                                        className="btn btn-circle btn-white"
                                        onClick={() => this.setState({ visibleApproveSuperadmin: false })}
                                    >
                                        <img src={Images.close} />
                                    </button>
                                </div>
                            </div>
                            <div className="border-bottom" style={{ padding: 20 }}>
                                <span>Choose approver you want</span>
                                <div style={{ marginTop: 20 }}>
                                    <Autocomplete
                                        {...this.state.listApprover}
                                        id="periode"
                                        onChange={(event, newInputValue) => this.setState({ approver: newInputValue })}
                                        disabled={false}
                                        disableClearable
                                        style={{ width: 250 }}
                                        renderInput={(params) =>
                                            <TextField {...params} label="Approver" margin="normal" style={{ marginTop: 7 }}
                                            />}
                                        value={this.state.approver}
                                    />
                                </div>
                            </div>
                            <div className="border-top grid grid-2x" style={{ height: 56, backgroundColor: '#f5f5f5', paddingLeft: 20, paddingRight: 20 }}>
                                <div className="column-1" style={{ alignSelf: 'center' }}>
                                    <button
                                        type="button"
                                        onClick={() => this.setState({ visibleApproveSuperadmin: false })}
                                    >
                                        <div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                            <span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
                                        </div>
                                    </button>
                                </div>
                                <div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
                                    <button
                                        type="button"
d.arizona's avatar
d.arizona committed
3789
                                        onClick={() => this.state.approver == null ? this.setState({ alert: true, messageAlert: 'Approver Cannot be Empty', tipeAlert: 'error' }) : this.setHeaderTokenSuperadmin('approve')}
3790 3791 3792 3793 3794 3795 3796 3797 3798 3799
                                    >
                                        <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                            <span style={{ color: '#fff', fontSize: 11 }}>Confirm  Approve</span>
                                        </div>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                )}
qorri_di's avatar
qorri_di committed
3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828

                {this.state.popupDownload && (
                    <div className="test app-popup-show">
                        <div className="popup-content border-radius" style={{ background: '#D9D9D9', borderRadius: 10, width: 609, height: 276 }}>
                            <div>
                                <div style={{ justifyContent: 'center', fontSize: 20, color: '#33508B', margin: '70px 20px' }}>Download Master Budget {this.state.company.company_name} {this.state.periode.periode} In Progress, silahkan cek status dan unduh report di menu <b>Download Report</b></div>
                                <div style={{ display: 'flex', justifyContent: 'flex-end' }}>
                                    <button
                                        className="button"
                                        type="button"
                                        style={{
                                            background: '#F6F7F9',
                                            cursor: 'pointer',
                                            border: '1px solid #3549609e',
                                            outline: 'none',
                                            marginRight: 20,
                                            borderRadius: 3
                                        }}
                                        onClick={() => this.setState({ popupDownload: false })}
                                    >
                                        <div style={{ backgroundColor: '#fff', width: 105, height: 30, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #3549609e' }}>
                                            <Typography style={{ fontSize: '15px', color: '#354960', textAlign: 'center' }}>Close</Typography>
                                        </div>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                )}
Riri Novita's avatar
Riri Novita committed
3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853

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