BudgetTahunan.js 208 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
        })
    }

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

                        })
Deni Rinaldi's avatar
Deni Rinaldi committed
711
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
712 713 714
                } 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
715
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Deni Rinaldi's avatar
Deni Rinaldi committed
716 717 718 719 720 721 722 723 724 725
                            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
726 727 728
        })
    }

d.arizona's avatar
d.arizona committed
729 730 731 732 733 734
    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
735
            "currency_id": this.state.defaultCurrency.id,
d.arizona's avatar
d.arizona committed
736 737 738
            "submission_id": this.state.submissionID
        }
        api.create().getDetailReportCF(payload).then(response => {
739
            // console.log(response);
d.arizona's avatar
d.arizona committed
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 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
            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
820
                // console.log(dataTable)
d.arizona's avatar
d.arizona committed
821
                this.setState({ dbCF: dataTable }, () => {
d.arizona's avatar
d.arizona committed
822
                    this.olahDataCashFlow(this.state.dbCF, type)
d.arizona's avatar
d.arizona committed
823
                })
Riri Novita's avatar
Riri Novita committed
824 825
            } else {
                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
826
                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
827 828 829 830 831 832
                        setTimeout(() => {
                            localStorage.removeItem(Constant.TOKEN)
                            window.location.reload();
                        }, 1000);
                    }
                })
d.arizona's avatar
d.arizona committed
833 834 835 836 837 838 839 840 841 842 843 844 845 846
            }
        })
    }

    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
847
            if (item !== "" && item !== '@') {
d.arizona's avatar
d.arizona committed
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
                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
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
                            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
883 884 885 886 887 888 889
                            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
890 891 892 893 894 895
                                    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
896 897 898 899 900 901 902 903 904
                                }
                            }

                            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
905 906 907 908 909 910
                                    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
911 912 913 914 915 916 917 918 919 920 921 922
                                }
                            }

                            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
923 924 925 926 927 928
                                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
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 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
                            }
                        }
                    } 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
1119 1120 1121 1122 1123 1124 1125 1126
        // 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)
        // }

1127
        total = R.equals(total, NaN) ? "0.0" : Number(total).toFixed(1)
d.arizona's avatar
d.arizona committed
1128 1129 1130 1131 1132 1133 1134 1135
        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
1136
        total = this.handleValueFormula(index, dataTable2[index][column], tableMeta, column, periode, dataTable2[index][25])
d.arizona's avatar
d.arizona committed
1137 1138 1139 1140 1141
        // }
        return total
    }

    olahDataCashFlow(dbCF, type) {
d.arizona's avatar
d.arizona committed
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
        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
1157 1158 1159 1160 1161
                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
1162
        this.setState({ dbCF }, () => {
d.arizona's avatar
d.arizona committed
1163 1164 1165 1166 1167 1168
            this.payloadCF(type)
        })
    }

    payloadCF(type) {
        let listCF = []
d.arizona's avatar
d.arizona committed
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
        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
1190
        this.setState({ dbCF: listCF }, () => {
d.arizona's avatar
d.arizona committed
1191
            this.olahDataCashFlowOneMore(listCF, type)
d.arizona's avatar
d.arizona committed
1192 1193 1194 1195
        })
    }

    olahDataCashFlowOneMore(list, type) {
Riri Novita's avatar
Riri Novita committed
1196
        // console.log(list)
d.arizona's avatar
d.arizona committed
1197 1198
        let listCF = []
        list.map((item, index) => {
d.arizona's avatar
d.arizona committed
1199 1200
            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
1201
                item[7].value = this.handleValueFormula(index, item[7], item, 7)
qorri_di's avatar
qorri_di committed
1202
                // }  
d.arizona's avatar
d.arizona committed
1203

d.arizona's avatar
d.arizona committed
1204
                // if (item[8].value == "" || item[8].value == 0 || item[8].value == "0.0") {
d.arizona's avatar
d.arizona committed
1205
                item[8].value = this.handleValueFormula(index, item[8], item, 8)
qorri_di's avatar
qorri_di committed
1206
                // } 
d.arizona's avatar
d.arizona committed
1207

d.arizona's avatar
d.arizona committed
1208
                // if (item[9].value == "" || item[9].value == 0 || item[9].value == "0.0") {
d.arizona's avatar
d.arizona committed
1209
                item[9].value = this.handleValueFormula(index, item[9], item, 9)
qorri_di's avatar
qorri_di committed
1210
                // } 
d.arizona's avatar
d.arizona committed
1211

d.arizona's avatar
d.arizona committed
1212
                // if (item[10].value == "" || item[10].value == 0 || item[10].value == "0.0") {
d.arizona's avatar
d.arizona committed
1213
                item[10].value = this.handleValueFormula(index, item[10], item, 10)
qorri_di's avatar
qorri_di committed
1214
                // } 
d.arizona's avatar
d.arizona committed
1215

d.arizona's avatar
d.arizona committed
1216
                // if (item[11].value == "" || item[11].value == 0 || item[11].value == "0.0") {
d.arizona's avatar
d.arizona committed
1217
                item[11].value = this.handleValueFormula(index, item[11], item, 11)
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[12].value == "" || item[12].value == 0 || item[12].value == "0.0") {
d.arizona's avatar
d.arizona committed
1221
                item[12].value = this.handleValueFormula(index, item[12], item, 12)
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[13].value == "" || item[13].value == 0 || item[13].value == "0.0") {
d.arizona's avatar
d.arizona committed
1225
                item[13].value = this.handleValueFormula(index, item[13], item, 13)
d.arizona's avatar
d.arizona committed
1226
                // }
d.arizona's avatar
d.arizona committed
1227

d.arizona's avatar
d.arizona committed
1228
                // if (item[14].value == "" || item[14].value == 0 || item[14].value == "0.0") {
d.arizona's avatar
d.arizona committed
1229
                item[14].value = this.handleValueFormula(index, item[14], item, 14)
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[15].value == "" || item[15].value == 0 || item[15].value == "0.0") {
d.arizona's avatar
d.arizona committed
1233
                item[15].value = this.handleValueFormula(index, item[15], item, 15)
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[16].value == "" || item[16].value == 0 || item[16].value == "0.0") {
d.arizona's avatar
d.arizona committed
1237
                item[16].value = this.handleValueFormula(index, item[16], item, 16)
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[17].value == "" || item[17].value == 0 || item[17].value == "0.0") {
d.arizona's avatar
d.arizona committed
1241
                item[17].value = this.handleValueFormula(index, item[17], item, 17)
qorri_di's avatar
qorri_di committed
1242
                // } 
d.arizona's avatar
d.arizona committed
1243

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

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

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

d.arizona's avatar
d.arizona committed
1254
                // if (item[21] == "" || item[21] == 0 || item[21] == "0.0") {
d.arizona's avatar
d.arizona committed
1255
                item[21] = this.handleForecast(index, item, `${Number(this.state.periode.periode) + 2}`, 21)
qorri_di's avatar
qorri_di committed
1256
                // } 
d.arizona's avatar
d.arizona committed
1257
            }
d.arizona's avatar
d.arizona committed
1258

d.arizona's avatar
d.arizona committed
1259 1260 1261 1262 1263 1264 1265

            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
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
                    "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
1281 1282 1283 1284 1285 1286 1287
                    "kpi_type": "",
                    "max_ach": "",
                    "pic": "",
                    "strategic": "",
                    "total_actual_before": "",
                    "uom": "",
                    "weight": ""
d.arizona's avatar
d.arizona committed
1288
                }
d.arizona's avatar
d.arizona committed
1289
            )
d.arizona's avatar
d.arizona committed
1290

d.arizona's avatar
d.arizona committed
1291 1292
        })

Riri Novita's avatar
Riri Novita committed
1293
        // console.log(listCF)
d.arizona's avatar
d.arizona committed
1294
        this.setState({ dbCF: listCF }, () => {
1295 1296
            // if (this.state.submissionID != null) {
            //     this.createCashFlow()
d.arizona's avatar
d.arizona committed
1297
            // }
d.arizona's avatar
d.arizona committed
1298 1299
            // if (type != undefined) {
            //     if (type == 'BS' || type == 'FAM' || type == 'PL') {
Riri Novita's avatar
Riri Novita committed
1300
            // console.log('tarik sis')
d.arizona's avatar
d.arizona committed
1301
            // this.createCashFlow()
d.arizona's avatar
d.arizona committed
1302 1303
            //     }
            // }
d.arizona's avatar
d.arizona committed
1304 1305 1306
        })
    }

d.arizona's avatar
d.arizona committed
1307
    createCashFlow(payload) {
d.arizona's avatar
d.arizona committed
1308
        api.create().createReportCF(payload).then((res) => {
1309
            console.log(res)
1310 1311 1312
            // this.getSubmission()
            if (res.data) {
                if (res.data.status === "success") {
1313
                    this.setState({ visibleCF: false, visibleBudgetTahunan: true })
1314 1315
                    this.getSubmission()
                } else {
1316 1317 1318 1319 1320
                    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 })
                    }
1321 1322
                }
            }
d.arizona's avatar
d.arizona committed
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
            // 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()
1334 1335 1336 1337 1338 1339 1340
            //         document.body.style.overflow = 'unset';
            //     })
            // }
        })
    }

    getPL(type) {
d.arizona's avatar
d.arizona committed
1341 1342
        let PLID = null
        let payloadID = {
1343
            "periode": this.state.periode.periode,
d.arizona's avatar
d.arizona committed
1344
            "company_id": this.state.company.company_id
1345
        }
d.arizona's avatar
d.arizona committed
1346 1347
        console.log(payloadID);
        api.create().getPLID(payloadID).then(response => {
Riri Novita's avatar
Riri Novita committed
1348
            // console.log(response);
d.arizona's avatar
d.arizona committed
1349
            if (response) {
d.arizona's avatar
d.arizona committed
1350
                PLID = response.data.data == null ? null : response.data.data.profit_loss_id
d.arizona's avatar
d.arizona committed
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
            } 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
1361
                    "currency_id": this.state.defaultCurrency.id,
d.arizona's avatar
d.arizona committed
1362 1363
                    "months": 0,
                    "quarter": 0,
1364
                }
d.arizona's avatar
d.arizona committed
1365 1366 1367 1368 1369
                api.create().getHierarkiCreateReportPLMB(payload).then(response => {
                    // console.log(response);
                    let dataTable = []
                    if (response.data) {
                        // let dataTable = []
Riri Novita's avatar
Riri Novita committed
1370
                        // console.log(response)
d.arizona's avatar
d.arizona committed
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
                        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
1399 1400
                                item.profit_detail.forecast_formula == null ? [] : item.profit_detail.forecast_formula,
                                item.profit_detail.notes
d.arizona's avatar
d.arizona committed
1401
                            ])
d.arizona's avatar
d.arizona committed
1402

d.arizona's avatar
d.arizona committed
1403 1404 1405 1406 1407 1408 1409
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
1410
                        }
d.arizona's avatar
d.arizona committed
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437
                        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
1438 1439
                                item.profit_detail.forecast_formula == null ? [] : item.profit_detail.forecast_formula,
                                item.profit_detail.notes
d.arizona's avatar
d.arizona committed
1440 1441 1442 1443 1444 1445 1446 1447 1448
                            ])
                            if (item.children !== null) {
                                if (item.children.length > 0) {
                                    item.children.map((items, indexs) => {
                                        handlePushChild(items)
                                    })
                                }
                            }
                        })
d.arizona's avatar
d.arizona committed
1449
                        // console.log(dataTable)
d.arizona's avatar
d.arizona committed
1450
                        this.setState({ dbPL: dataTable }, () => {
d.arizona's avatar
d.arizona committed
1451
                            this.olahDataPL(this.state.dbPL, type)
d.arizona's avatar
d.arizona committed
1452 1453
                        })
                    } else {
1454
                        this.setState({ dbPL: [], previewTable: false, previewDownload: false })
1455
                    }
d.arizona's avatar
d.arizona committed
1456 1457


1458
                })
d.arizona's avatar
d.arizona committed
1459
            })
1460
        })
d.arizona's avatar
d.arizona committed
1461 1462


1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507
    }

    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
1508 1509
                            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)
1510 1511

                            if (indexID !== -1) {
d.arizona's avatar
d.arizona committed
1512
                                let valuezz = tableMeta[data].formula[indexID].value
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565
                                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
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
        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
1597
                })
1598 1599 1600 1601 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 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

                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
1662 1663 1664 1665 1666 1667 1668
        // 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)
        // }
1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683
        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
1684
            total = this.handleValueFormulaDBPL(dataTable2[index][column], tableMeta[column], tableMeta, column, periode, dataTable2[index][25])
1685 1686 1687 1688 1689 1690
        }

        return total
    }

    olahDataPL(dbPL, type) {
d.arizona's avatar
d.arizona committed
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704
        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)
1705 1706 1707 1708
                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
1709
        this.setState({ dbPL }, () => {
1710 1711 1712 1713 1714 1715
            this.payloadPL(type)
        })
    }

    payloadPL(type) {
        let listPL = []
d.arizona's avatar
d.arizona committed
1716
        // console.log(this.state.dbPL)
d.arizona's avatar
d.arizona committed
1717
        this.state.dbPL.map((item, index) => {
1718 1719
            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
1720
                item[7].value = this.handleValueFormulaDBPL(index, item[7], item, 7)
qorri_di's avatar
qorri_di committed
1721
                // }  
d.arizona's avatar
d.arizona committed
1722

1723
                // if (item[8].value == "" || item[8].value == 0 || item[8].value == "0.0") {
d.arizona's avatar
d.arizona committed
1724
                item[8].value = this.handleValueFormulaDBPL(index, item[8], item, 8)
qorri_di's avatar
qorri_di committed
1725
                // } 
d.arizona's avatar
d.arizona committed
1726

1727
                // if (item[9].value == "" || item[9].value == 0 || item[9].value == "0.0") {
d.arizona's avatar
d.arizona committed
1728
                item[9].value = this.handleValueFormulaDBPL(index, item[9], item, 9)
qorri_di's avatar
qorri_di committed
1729
                // } 
d.arizona's avatar
d.arizona committed
1730

1731
                // if (item[10].value == "" || item[10].value == 0 || item[10].value == "0.0") {
d.arizona's avatar
d.arizona committed
1732
                item[10].value = this.handleValueFormulaDBPL(index, item[10], item, 10)
qorri_di's avatar
qorri_di committed
1733
                // } 
d.arizona's avatar
d.arizona committed
1734

1735
                // if (item[11].value == "" || item[11].value == 0 || item[11].value == "0.0") {
d.arizona's avatar
d.arizona committed
1736
                item[11].value = this.handleValueFormulaDBPL(index, item[11], item, 11)
qorri_di's avatar
qorri_di committed
1737
                // } 
d.arizona's avatar
d.arizona committed
1738

1739
                // if (item[12].value == "" || item[12].value == 0 || item[12].value == "0.0") {
d.arizona's avatar
d.arizona committed
1740
                item[12].value = this.handleValueFormulaDBPL(index, item[12], item, 12)
qorri_di's avatar
qorri_di committed
1741
                // } 
d.arizona's avatar
d.arizona committed
1742

1743
                // if (item[13].value == "" || item[13].value == 0 || item[13].value == "0.0") {
d.arizona's avatar
d.arizona committed
1744
                item[13].value = this.handleValueFormulaDBPL(index, item[13], item, 13)
1745
                // }
d.arizona's avatar
d.arizona committed
1746

1747
                // if (item[14].value == "" || item[14].value == 0 || item[14].value == "0.0") {
d.arizona's avatar
d.arizona committed
1748
                item[14].value = this.handleValueFormulaDBPL(index, item[14], item, 14)
qorri_di's avatar
qorri_di committed
1749
                // } 
d.arizona's avatar
d.arizona committed
1750

1751
                // if (item[15].value == "" || item[15].value == 0 || item[15].value == "0.0") {
d.arizona's avatar
d.arizona committed
1752
                item[15].value = this.handleValueFormulaDBPL(index, item[15], item, 15)
qorri_di's avatar
qorri_di committed
1753
                // } 
d.arizona's avatar
d.arizona committed
1754

1755
                // if (item[16].value == "" || item[16].value == 0 || item[16].value == "0.0") {
d.arizona's avatar
d.arizona committed
1756
                item[16].value = this.handleValueFormulaDBPL(index, item[16], item, 16)
qorri_di's avatar
qorri_di committed
1757
                // } 
d.arizona's avatar
d.arizona committed
1758

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

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

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

1771
                // if (item[21] == "" || item[21] == 0 || item[21] == "0.0") {
d.arizona's avatar
d.arizona committed
1772
                item[21] = this.handleForecastDBPL(index, item, `${Number(this.state.periode.periode) + 2}`, 21)
qorri_di's avatar
qorri_di committed
1773
                // } 
1774
            }
d.arizona's avatar
d.arizona committed
1775

1776 1777 1778 1779

            listPL.push(
                {
                    "item_report_id": item[1],
d.arizona's avatar
d.arizona committed
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791
                    "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)),
1792
                    "total_current_year": String(item[19]),
d.arizona's avatar
d.arizona committed
1793 1794
                    "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
1795
                    "notes": String(item[26]),
d.arizona's avatar
d.arizona committed
1796
                }
1797
            )
d.arizona's avatar
d.arizona committed
1798

1799 1800
        })

d.arizona's avatar
d.arizona committed
1801
        // console.log(listPL)
d.arizona's avatar
d.arizona committed
1802
        this.setState({ dbPL: listPL }, () => {
1803 1804 1805
            // if (this.state.submissionID != null) {
            //     this.createDBPL()
            // }
d.arizona's avatar
d.arizona committed
1806 1807
            if (type != undefined) {
                if (type == 'PL') {
Riri Novita's avatar
Riri Novita committed
1808
                    // console.log('tarik sis')
1809
                    this.createDBPL()
d.arizona's avatar
d.arizona committed
1810 1811
                }
            }
1812 1813 1814 1815 1816
        })
    }

    createDBPL() {
        let payload = {
d.arizona's avatar
d.arizona committed
1817
            // "submission_id": this.state.submissionID,
1818 1819
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode,
d.arizona's avatar
d.arizona committed
1820
            "report_id": 28,
1821
            "status": "submitted",
d.arizona's avatar
d.arizona committed
1822
            "profit_loss_id": this.state.PLID,
Riri Novita's avatar
Riri Novita committed
1823
            "currency_id": this.state.defaultCurrency.id,
1824 1825 1826 1827
            "profit_loss_mb": this.state.dbPL,
            "months": 0,
        }
        // console.log(this.state.dbCF)
d.arizona's avatar
d.arizona committed
1828
        // console.log(JSON.stringify(payload))
1829
        api.create().createReportPLMB(payload).then((res) => {
Riri Novita's avatar
Riri Novita committed
1830
            // console.log(res)
d.arizona's avatar
d.arizona committed
1831
            this.setState({ loading: false })
1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842
            // 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()
1843 1844 1845 1846 1847 1848 1849
            //         document.body.style.overflow = 'unset';
            //     })
            // }
        })
    }

    getFR(type) {
Riri Novita's avatar
Riri Novita committed
1850
        // console.log("get FR");
1851 1852 1853 1854 1855
        let FRID = null
        let payloadID = {
            "periode": this.state.periode.periode,
            "company_id": this.state.company.company_id
        }
Riri Novita's avatar
Riri Novita committed
1856
        // console.log(payloadID);
1857
        api.create().getFRID(payloadID).then(response => {
Riri Novita's avatar
Riri Novita committed
1858
            // console.log(response);
1859
            if (response) {
d.arizona's avatar
d.arizona committed
1860
                FRID = response.data.data == null ? null : response.data.data.ratio_id
1861 1862 1863 1864 1865 1866 1867 1868 1869
            } 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
1870
                    "currency_id": this.state.defaultCurrency.id,
d.arizona's avatar
d.arizona committed
1871
                    "submission_id": this.state.submissionID,
1872 1873 1874 1875 1876 1877
                }
                api.create().getHierarkiCreateReportFRMB(payload).then(response => {
                    // console.log(response);
                    let dataTable = []
                    if (response.data) {
                        // let dataTable = []
Riri Novita's avatar
Riri Novita committed
1878
                        // console.log(response)
1879 1880
                        let res = response.data.data
                        const handlePushChild = (item) => {
d.arizona's avatar
d.arizona committed
1881
                            if (item.description == 'Return on Invested Capital - YTD (ROIC)') {
Riri Novita's avatar
Riri Novita committed
1882
                                // console.log(item.ratio.january)
d.arizona's avatar
d.arizona committed
1883
                            }
1884 1885 1886 1887 1888 1889 1890 1891
                            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
1892
                                // "",
1893
                                // 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
1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907
                                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),
1908
                            ])
d.arizona's avatar
d.arizona committed
1909

1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926
                            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
1927
                                // "",
1928
                                // 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
1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942
                                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),
1943 1944 1945 1946 1947 1948 1949 1950 1951 1952
                            ])
                            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
1953
                            // console.log(this.state.dbFR)
d.arizona's avatar
d.arizona committed
1954
                            this.olahDataFR(this.state.dbFR, type)
1955 1956
                        })
                    } else {
d.arizona's avatar
d.arizona committed
1957
                        this.setState({ dbFR: [], previewTable: false, loading: false, previewDownload: false })
1958
                    }
d.arizona's avatar
d.arizona committed
1959 1960


1961 1962 1963
                })
            })
        })
d.arizona's avatar
d.arizona committed
1964 1965


1966 1967 1968 1969 1970 1971 1972
    }

    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
1973
            total = Number(dataTable2[35][6 + month])
1974 1975
        } else {
            for (let index = 0; index < month; index++) {
d.arizona's avatar
d.arizona committed
1976
                total += Number(dataTable2[35][7 + index])
1977 1978
                // console.log(index);
            }
d.arizona's avatar
d.arizona committed
1979
            total = total / month
1980 1981
        }
        let hasil = Number(value) / total
d.arizona's avatar
d.arizona committed
1982 1983 1984
        // console.log(value)
        // console.log(total)
        // console.log(hasil, value, total);
d.arizona's avatar
d.arizona committed
1985
        return Number(hasil).toFixed(2)
1986 1987 1988 1989
    }

    olahDataFR(dbFR, type) {
        // let totalCY = 0
d.arizona's avatar
d.arizona committed
1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006
        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)
2007
                    // 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
2008
                }
2009 2010
            }
        })
d.arizona's avatar
d.arizona committed
2011
        this.setState({ dbFR }, () => {
2012 2013 2014 2015 2016 2017
            this.payloadFR(type)
        })
    }

    payloadFR(type) {
        let listFR = []
d.arizona's avatar
d.arizona committed
2018
        // console.log(this.state.dbFR)
2019
        let totalCY = 0
d.arizona's avatar
d.arizona committed
2020
        this.state.dbFR.map((item, index) => {
2021
            if (item[0] != 4 || item[0] != 1) {
d.arizona's avatar
d.arizona committed
2022
                if (item[5] === "Return on Invested Capital - YTD (ROIC)") {
d.arizona's avatar
d.arizona committed
2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036
                    // 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
2037
                }
d.arizona's avatar
d.arizona committed
2038
                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])
2039 2040 2041 2042 2043
            }

            listFR.push(
                {
                    "item_report_id": item[1],
d.arizona's avatar
d.arizona committed
2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059
                    "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]),
                }
2060
            )
d.arizona's avatar
d.arizona committed
2061

2062 2063
        })

Riri Novita's avatar
Riri Novita committed
2064 2065
        // console.log(listFR)
        // console.log('subOD', this.state.submissionID)
d.arizona's avatar
d.arizona committed
2066
        this.setState({ dbFR: listFR }, () => {
2067 2068 2069 2070 2071 2072 2073
            if (this.state.submissionID != null) {
                this.createDBFR()
            }
        })
    }

    createDBFR() {
Riri Novita's avatar
Riri Novita committed
2074
        // console.log("create FR");
2075 2076 2077 2078 2079 2080 2081
        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
2082
            "currency_id": this.state.defaultCurrency.id,
2083 2084 2085 2086
            "ratio_mb": this.state.dbFR,
            "months": 0,
        }
        // console.log(this.state.dbCF)
d.arizona's avatar
d.arizona committed
2087
        // console.log(JSON.stringify(payload))
2088
        api.create().createReportFRMB(payload).then((res) => {
Riri Novita's avatar
Riri Novita committed
2089
            // console.log(res)
2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100
            // 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
2101 2102 2103 2104 2105 2106
            //         document.body.style.overflow = 'unset';
            //     })
            // }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
2107 2108
    historyApproval() {
        let body = {
Deni Rinaldi's avatar
Deni Rinaldi committed
2109 2110
            "company_id": this.state.company.company_id,
            "periode": this.state.periode.periode
Deni Rinaldi's avatar
Deni Rinaldi committed
2111 2112
        }
        api.create().historyApproval(body).then(response => {
d.arizona's avatar
d.arizona committed
2113
            // // // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
2114 2115
            if (response.data.data.length > 0) {
                let dataTableHistory = response.data.data.map(item => {
d.arizona's avatar
d.arizona committed
2116 2117 2118
                    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
2119
                        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
2120 2121 2122
                    } else {
                        status_approv = String(item.status_approval)
                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
2123 2124
                    return [
                        item.pic,
d.arizona's avatar
d.arizona committed
2125
                        status_approv,
Deni Rinaldi's avatar
Deni Rinaldi committed
2126 2127 2128 2129 2130
                        item.remarks,
                        item.item_revision,
                        item.history_approval_date
                    ]
                })
Deni Rinaldi's avatar
Deni Rinaldi committed
2131
                this.setState({ dataTableHistory, visibleTableHistory: true })
Deni Rinaldi's avatar
Deni Rinaldi committed
2132 2133 2134 2135
            }
        })
    }

d.arizona's avatar
d.arizona committed
2136
    async setHeaderTokenSuperadmin(type) {
2137
        let realToken = await localStorage.getItem(Constant.TOKEN)
d.arizona's avatar
d.arizona committed
2138
        api.create().getIdToken(this.state.approver.userId).then((response) => {
Riri Novita's avatar
Riri Novita committed
2139
            // console.log(response.data.data.token)
d.arizona's avatar
d.arizona committed
2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154
            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
2155
        this.setState({ loading: true }, () => {
idlanirined's avatar
idlanirined committed
2156 2157
            document.body.style.overflow = 'hidden';
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2158
        let body = {
Deni Rinaldi's avatar
Deni Rinaldi committed
2159
            "approval_id": this.state.approverID,
Deni Rinaldi's avatar
Deni Rinaldi committed
2160
            "status": type,
d.arizona's avatar
d.arizona committed
2161
            "detail": this.state.detailRevisiCheck,
2162 2163
            "is_superadmin": this.state.isAdmin,
            "currency_id": this.state.defaultCurrency.id,
Deni Rinaldi's avatar
Deni Rinaldi committed
2164
        }
d.arizona's avatar
d.arizona committed
2165 2166
        let payload = {
            "company_id": this.state.company.company_id,
d.arizona's avatar
d.arizona committed
2167
            "periode": this.state.periode.periode,
d.arizona's avatar
d.arizona committed
2168 2169 2170
            "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
2171
        // console.log(payload)
d.arizona's avatar
d.arizona committed
2172
        // // console.log(this.props.location);
Riri Novita's avatar
Riri Novita committed
2173
        // console.log(body)
2174 2175
        setTimeout(() => {
            api.create().approvalSubmission(body).then((res) => {
Riri Novita's avatar
Riri Novita committed
2176
                // console.log(res)
2177 2178
                // this.setState({ loading: false }, () => {
                // })
Faisal Hamdi's avatar
Faisal Hamdi committed
2179
                if (this.state.isAdmin && type == 'approve') {
2180
                    localStorage.setItem(Constant.TOKEN, realToken)
Faisal Hamdi's avatar
Faisal Hamdi committed
2181
                    this.setState({ visibleApproveSuperadmin: false })
2182 2183 2184 2185 2186 2187 2188 2189 2190
                }
                setTimeout(() => {
                    if (type == 'revision') {
                        api.create().createPeriodeRevision(payload).then((res))
                    }
                    this.getSubmission()
                }, 400);
            })
        }, 200);
Deni Rinaldi's avatar
Deni Rinaldi committed
2191 2192
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
2193
    clickDetail(item, id, revision, status) {
idlanirined's avatar
idlanirined committed
2194 2195 2196 2197 2198 2199
        let items = ''
        if (item === 'Corporate Annual Target') {
            items = 'CAT'
        } else {
            items = item
        }
d.arizona's avatar
d.arizona committed
2200
        let PLBSFAMSubmitted = 0
d.arizona's avatar
d.arizona committed
2201
        // // // console.log(this.state.dataForRevision);
Deni Rinaldi's avatar
Deni Rinaldi committed
2202
        this.state.dataForRevision.map(i => {
idlanirined's avatar
idlanirined committed
2203
            if (i.report_name === items) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2204 2205 2206 2207 2208 2209
                if (i.revision !== revision) {
                    this.setState({ prevRevision: true })
                } else {
                    this.setState({ prevRevision: false })
                }
            }
d.arizona's avatar
d.arizona committed
2210
            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
2211 2212 2213 2214
                if (String(i.current_status).toLocaleLowerCase() == "submitted") {
                    PLBSFAMSubmitted += 1
                }
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
2215
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2216 2217 2218
        this.setState({
            report_id: id,
            revisionTable: revision,
Deni Rinaldi's avatar
Deni Rinaldi committed
2219
            status: status
Deni Rinaldi's avatar
Deni Rinaldi committed
2220 2221 2222 2223 2224 2225 2226 2227 2228
        }, () => {
            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
2229
                    visibleCF: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2230 2231 2232 2233 2234 2235 2236 2237
                })
            } else if (item === 'Profit Loss') {
                this.setState({
                    visibleBudgetTahunan: false,
                    visibleBS: false,
                    visiblePL: true,
                    visibleCAT: false,
                    visibleFAM: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2238 2239
                    visibleTP: false,
                    visibleCF: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2240 2241 2242 2243 2244 2245 2246 2247
                })
            } else if (item === 'Tax Planning') {
                this.setState({
                    visibleBudgetTahunan: false,
                    visibleBS: false,
                    visiblePL: false,
                    visibleCAT: false,
                    visibleFAM: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2248 2249
                    visibleTP: true,
                    visibleCF: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2250 2251 2252 2253 2254 2255 2256 2257
                })
            } 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
2258 2259
                    visibleTP: false,
                    visibleCF: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2260
                })
idlanirined's avatar
idlanirined committed
2261
            } else if (item === 'Corporate Annual Target') {
Deni Rinaldi's avatar
Deni Rinaldi committed
2262 2263 2264 2265 2266 2267
                this.setState({
                    visibleBudgetTahunan: false,
                    visibleBS: false,
                    visiblePL: false,
                    visibleCAT: true,
                    visibleFAM: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2268 2269 2270
                    visibleTP: false,
                    visibleCF: false,
                })
Deni Rinaldi's avatar
Deni Rinaldi committed
2271
            } else if (item === "Cash Flow") {
Deni Rinaldi's avatar
Deni Rinaldi committed
2272 2273 2274 2275 2276 2277 2278 2279
                this.setState({
                    visibleBudgetTahunan: false,
                    visibleBS: false,
                    visiblePL: false,
                    visibleCAT: false,
                    visibleFAM: false,
                    visibleTP: false,
                    visibleCF: true,
d.arizona's avatar
d.arizona committed
2280
                    PLBSFAMSubmitted: PLBSFAMSubmitted == 3 ? true : false
Deni Rinaldi's avatar
Deni Rinaldi committed
2281 2282 2283
                })
            }
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2284 2285
    }

2286 2287 2288 2289 2290
    handleChange(value, tableMeta) {
        let data = this.state.dataTable
        data[tableMeta.rowIndex][tableMeta.columnIndex] = value
    }

2291 2292 2293
    fileHandler = (event) => {
        let fileObj = event
        ExcelRenderer(fileObj, (err, resp) => {
d.arizona's avatar
d.arizona committed
2294
            // // // console.log(resp)
2295
            if (err) {
d.arizona's avatar
d.arizona committed
2296
                // // // console.log(err);
2297 2298 2299
            }
            else {
                const formData = new FormData();
Deni Rinaldi's avatar
Deni Rinaldi committed
2300
                formData.append("revision", Number(this.state.lastRevision));
2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313
                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
2314
                        this.getSubmission()
2315 2316 2317
                    })
                }
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
2318 2319 2320 2321 2322
        })
    }

    deleteAttachment(item) {
        api.create().deleteAttachment(item.attachment_id).then(response => {
d.arizona's avatar
d.arizona committed
2323
            // // // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
2324 2325
            if (response.data) {
                if (response.data.status === "success") {
Deni Rinaldi's avatar
Deni Rinaldi committed
2326
                    this.getSubmission()
Deni Rinaldi's avatar
Deni Rinaldi committed
2327 2328
                }
            }
2329 2330
        })
    }
Deni Rinaldi's avatar
Deni Rinaldi committed
2331

Deni Rinaldi's avatar
Deni Rinaldi committed
2332 2333 2334 2335
    closeAlert() {
        this.setState({ alert: false })
    }

d.arizona's avatar
d.arizona committed
2336
    saveToMasterBudget(data, type) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2337
        this.setState({ loading: true }, () => {
idlanirined's avatar
idlanirined committed
2338 2339
            document.body.style.overflow = 'hidden';
        })
2340
        console.log(type);
Riri Novita's avatar
Riri Novita committed
2341
        // // console.log(JSON.stringify(data));
Deni Rinaldi's avatar
Deni Rinaldi committed
2342
        api.create('UPLOAD').createSubmitReport(data).then(response => {
Riri Novita's avatar
Riri Novita committed
2343
            console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
2344
            if (response.data) {
d.arizona's avatar
d.arizona committed
2345 2346
                if (response.ok) {
                    if (response.data.status === 'success') {
Riri Novita's avatar
Riri Novita committed
2347
                        if (type === "PL" || type === "DraftPL") {
Riri Novita's avatar
Riri Novita committed
2348
                            this.setState({ visiblePL: false, visibleBudgetTahunan: true, loading: false })
Riri Novita's avatar
Riri Novita committed
2349
                        } else if (type === "TP" || type === "DraftTP") {
Riri Novita's avatar
Riri Novita committed
2350
                            this.setState({ visibleTP: false, visibleBudgetTahunan: true,loading: false })
Riri Novita's avatar
Riri Novita committed
2351
                        } else if (type === "BS" || type === "DraftBS") {
Riri Novita's avatar
Riri Novita committed
2352
                            this.setState({ visibleBS: false, visibleBudgetTahunan: true, loading: false })
Riri Novita's avatar
Riri Novita committed
2353
                        } else if (type === "FAM" || type === "DraftFAM") {
Riri Novita's avatar
Riri Novita committed
2354
                            this.setState({ visibleFAM: false, visibleBudgetTahunan: true, loading: false })
Riri Novita's avatar
Riri Novita committed
2355
                        } else if (type === "CAT" || type === "DraftCAT") {
Riri Novita's avatar
Riri Novita committed
2356
                            this.setState({ visibleCAT: false, visibleBudgetTahunan: true, loading: false })
2357
                        } else {
Riri Novita's avatar
Riri Novita committed
2358
                            this.setState({ visibleBudgetTahunan: true, visiblePL: false, visibleTP: false, visibleBS: false, visibleFAM: false, visibleCAT: false, loading: false })
2359
                        }
d.arizona's avatar
d.arizona committed
2360
                        this.getSubmission(type)
d.arizona's avatar
d.arizona committed
2361
                    } else {
2362 2363 2364 2365 2366 2367 2368 2369
                        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
2370
                        // })
d.arizona's avatar
d.arizona committed
2371
                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
2372
                } else {
d.arizona's avatar
d.arizona committed
2373
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
2374
                        this.getSubmission()
idlanirined's avatar
idlanirined committed
2375
                        document.body.style.overflow = 'unset';
d.arizona's avatar
d.arizona committed
2376
                    })
Deni Rinaldi's avatar
Deni Rinaldi committed
2377
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
2378
            } else {
d.arizona's avatar
d.arizona committed
2379
                this.setState({ alert: true, messageAlert: 'Error saving data. Please try again', tipeAlert: 'error', loading: false }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
2380
                    this.getSubmission()
idlanirined's avatar
idlanirined committed
2381
                    document.body.style.overflow = 'unset';
Deni Rinaldi's avatar
Deni Rinaldi committed
2382
                })
Deni Rinaldi's avatar
Deni Rinaldi committed
2383 2384
            }
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2385 2386
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
2387 2388 2389
    async downloadAttachment(fileurl, name) {
        let length = name.split(".").length
        let fileType = name.split(".")[length - 1]
d.arizona's avatar
d.arizona committed
2390
        // // // console.log(fileType);
faisalhamdi's avatar
faisalhamdi committed
2391
        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
2392
        // // // console.log(url);
Deni Rinaldi's avatar
Deni Rinaldi committed
2393
        let res = await fetch(
faisalhamdi's avatar
faisalhamdi committed
2394
            `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/master_budget/download_attachment?fileName=${fileurl}&&fileType=${fileType}`
Deni Rinaldi's avatar
Deni Rinaldi committed
2395 2396
        )
        res = await res.blob()
Deni Rinaldi's avatar
Deni Rinaldi committed
2397
        this.setState({ loading: false }, () => {
idlanirined's avatar
idlanirined committed
2398 2399
            document.body.style.overflow = 'unset';
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2400 2401 2402 2403
        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
2404
            a.download = 'Master Budget Attachment.xlsx';
Deni Rinaldi's avatar
Deni Rinaldi committed
2405 2406 2407 2408
            a.click();
        }
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
2409
    validate() {
Deni Rinaldi's avatar
Deni Rinaldi committed
2410
        this.setState({ loading: true }, () => {
idlanirined's avatar
idlanirined committed
2411 2412
            document.body.style.overflow = 'hidden';
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2413
        let array = []
Deni Rinaldi's avatar
Deni Rinaldi committed
2414
        let canSubmit = true
Deni Rinaldi's avatar
Deni Rinaldi committed
2415
        this.state.dataTable.map(item => {
idlanirined's avatar
idlanirined committed
2416 2417
            // if (item[1] !== 'Cash Flow') {
            if (item[3] !== "submitted" && item[3] !== 'approved') {
d.arizona's avatar
d.arizona committed
2418
                canSubmit = false
idlanirined's avatar
idlanirined committed
2419
                array.push(item[3])
Deni Rinaldi's avatar
Deni Rinaldi committed
2420
            }
idlanirined's avatar
idlanirined committed
2421
            // }
Deni Rinaldi's avatar
Deni Rinaldi committed
2422 2423 2424 2425 2426
            // 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
2427
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
2428 2429 2430 2431
        if (canSubmit === true) {
            let body = {
                submission_id: this.state.submissionID
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
2432
            api.create().submitMasterBudget(body).then(response => {
d.arizona's avatar
d.arizona committed
2433
                // // // console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
2434
                if (response.data) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2435
                    if (response.data.status === "success") {
Deni Rinaldi's avatar
Deni Rinaldi committed
2436
                        this.getSubmission()
Deni Rinaldi's avatar
Deni Rinaldi committed
2437 2438 2439
                    }
                }
            })
Deni Rinaldi's avatar
Deni Rinaldi committed
2440
        } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
2441
            this.setState({ alert: true, messageAlert: 'Data Is Not Complete', tipeAlert: 'warning', loading: false }, () => {
idlanirined's avatar
idlanirined committed
2442 2443
                document.body.style.overflow = 'unset';
            })
Deni Rinaldi's avatar
Deni Rinaldi committed
2444
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
2445
        // if (array.includes("not-yet" || "draft")) {
d.arizona's avatar
d.arizona committed
2446
        //     // // console.log('gagal');
Deni Rinaldi's avatar
Deni Rinaldi committed
2447
        // } else {
d.arizona's avatar
d.arizona committed
2448
        //     // // console.log('masuk');
Deni Rinaldi's avatar
Deni Rinaldi committed
2449 2450
        // }

Deni Rinaldi's avatar
Deni Rinaldi committed
2451
    }
Deni Rinaldi's avatar
Deni Rinaldi committed
2452

d.arizona's avatar
d.arizona committed
2453
    validateRevision() {
d.arizona's avatar
d.arizona committed
2454
        // this.scrollToMyRef()
d.arizona's avatar
d.arizona committed
2455 2456
        let arrayRevisi = this.state.detailRevisiCheck
        let remarksKosong = 0
Deni Rinaldi's avatar
Deni Rinaldi committed
2457
        arrayRevisi.map((item, index) => {
d.arizona's avatar
d.arizona committed
2458 2459 2460 2461
            if (item.remarks == "") {
                remarksKosong += 1
            }
        })
d.arizona's avatar
d.arizona committed
2462
        // // console.log(arrayRevisi)
d.arizona's avatar
d.arizona committed
2463
        if (arrayRevisi.length == 0 || remarksKosong > 0) {
d.arizona's avatar
d.arizona committed
2464 2465 2466 2467 2468 2469
            this.setState({ alert: true, messageAlert: 'Remarks Cannot be Empty', tipeAlert: 'error' })
        } else {
            this.setState({ visibleRevision: false }, () => this.approvalSubmission('revision'))
        }
    }

2470 2471 2472 2473
    handleApproveAdmin() {
        this.setState({ visibleApproveSuperadmin: true })
    }

qorri_di's avatar
qorri_di committed
2474
    handleSelectAll(data) {
Riri Novita's avatar
Riri Novita committed
2475
        // console.log(this.state.isCheckAll);
qorri_di's avatar
qorri_di committed
2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491
        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
2492
            // console.log(checkAll);
qorri_di's avatar
qorri_di committed
2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511
            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
2512
        // console.log(selectReport);
qorri_di's avatar
qorri_di committed
2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524
    }

    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
2525
        // console.log(payload);
qorri_di's avatar
qorri_di committed
2526
        api.create().createDownloadFile(payload).then((response) => {
Riri Novita's avatar
Riri Novita committed
2527
            // console.log(response)
qorri_di's avatar
qorri_di committed
2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562
            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
2563
        let { selectReport, submissionID, company, periode, month, downloadedFileReportId, defaultCurrency } = this.state
qorri_di's avatar
qorri_di committed
2564 2565
        if (selectReport.length > 0) {
            let result = []
Riri Novita's avatar
Riri Novita committed
2566
            // console.log('mulai hit')
qorri_di's avatar
qorri_di committed
2567 2568 2569 2570
            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
2571 2572
                    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
2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585

                    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
2586 2587
                    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
2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602

                    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
2603
            // console.log('ini result', result);
qorri_di's avatar
qorri_di committed
2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646
            // 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
2647
        // console.log('mulai zip')
qorri_di's avatar
qorri_di committed
2648
        api.create().createZipReport(this.state.downloadedFileReportId).then((response) => {
Riri Novita's avatar
Riri Novita committed
2649
            console.log(response)
qorri_di's avatar
qorri_di committed
2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673
            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
2674
    render() {
d.arizona's avatar
d.arizona committed
2675 2676
        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
2677
            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
2678
        }
2679
        const columns = ["#", "Report Type",
Deni Rinaldi's avatar
Deni Rinaldi committed
2680
            {
2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696
                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
2697
                                                // // // console.log(event.target)
2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713
                                                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
2714 2715 2716 2717 2718
                name: "Status",
                options: {
                    customBodyRender: (val, tableMeta) => {
                        return (
                            <div style={{ display: 'flex' }}>
2719
                                {val === "submitted" || val === "approved" ?
Deni Rinaldi's avatar
Deni Rinaldi committed
2720
                                    <span>COMPLETED</span> :
Deni Rinaldi's avatar
Deni Rinaldi committed
2721
                                    val === "draft" ?
Deni Rinaldi's avatar
Deni Rinaldi committed
2722
                                        <span>DRAFT</span> :
Deni Rinaldi's avatar
Deni Rinaldi committed
2723 2724 2725 2726
                                        val === "incomplete" ?
                                            <span>INCOMPLETE</span> :
                                            val === "revision" ?
                                                <span>REVISION</span> :
d.arizona's avatar
d.arizona committed
2727
                                                val === "approval_process" ?
Deni Rinaldi's avatar
Deni Rinaldi committed
2728 2729 2730 2731 2732 2733 2734 2735
                                                    <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
2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750
                                }
                            </div >
                        );
                    }
                }
            },
            {
                name: "Action",
                options: {
                    customBodyRender: (val, tableMeta) => {
                        return (
                            <div style={{ display: 'flex' }}>
                                <button
                                    style={{
                                        backgroundColor: 'transparent',
d.arizona's avatar
d.arizona committed
2751
                                        cursor: tableMeta.rowData[5] ? 'pointer' : 'default',
Deni Rinaldi's avatar
Deni Rinaldi committed
2752 2753
                                        borderColor: 'transparent'
                                    }}
Deni Rinaldi's avatar
Deni Rinaldi committed
2754
                                    onClick={() =>
d.arizona's avatar
d.arizona committed
2755
                                        tableMeta.rowData[5] == true ?
2756 2757
                                            this.clickDetail(tableMeta.rowData[1], tableMeta.rowData[4], tableMeta.rowData[2], tableMeta.rowData[3])
                                            : null
2758
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
2759
                                >
Deni Rinaldi's avatar
Deni Rinaldi committed
2760
                                    {/* {this.state.isApprover == true ?
a.bairuha's avatar
a.bairuha committed
2761 2762 2763
                                        (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
2764
                                    <Typography style={{ color: tableMeta.rowData[5] ? '#5198ea' : 'GrayText', fontSize: 12, }}>Detail</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
2765 2766 2767 2768 2769
                                </button>
                            </div >
                        );
                    }
                }
qorri_di's avatar
qorri_di committed
2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785
            }, {
                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 >
                        );
                    }
                }
2786 2787 2788 2789 2790 2791
            }, {
                name: "",
                options: { display: false }
            }, {
                name: "",
                options: { display: false }
Deni Rinaldi's avatar
Deni Rinaldi committed
2792
            }]
Deni Rinaldi's avatar
Deni Rinaldi committed
2793 2794 2795 2796

        const columnsHistory = [
            "Name", "Status", "Remarks", "Revision Item", "Date"
        ]
Deni Rinaldi's avatar
Deni Rinaldi committed
2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812

        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
2813 2814 2815
                                        <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
2816 2817 2818 2819 2820 2821
                                    }
                                />
                            </div >
                        );
                    }
                }
d.arizona's avatar
d.arizona committed
2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840
            }, "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
2841
                                                // // // console.log(event.target.value)
d.arizona's avatar
d.arizona committed
2842 2843
                                                // updateValue(event.target.value)
                                                handleChangeText(event.target.value, tableMeta)
d.arizona's avatar
d.arizona committed
2844
                                                // // // console.log(dataTable2)
d.arizona's avatar
d.arizona committed
2845 2846
                                            }}
                                        />}
Deni Rinaldi's avatar
Deni Rinaldi committed
2847
                                />
d.arizona's avatar
d.arizona committed
2848 2849 2850 2851
                            </div>
                        )
                    }
                }
d.arizona's avatar
d.arizona committed
2852 2853 2854
            }, {
                name: "",
                options: { display: false }
d.arizona's avatar
d.arizona committed
2855
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
2856 2857
        ]

d.arizona's avatar
d.arizona committed
2858 2859 2860 2861 2862 2863 2864 2865 2866 2867
        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
2868
            this.setState({ dataTableRevision, detailRevisiCheck })
d.arizona's avatar
d.arizona committed
2869 2870 2871 2872 2873 2874
        }

        const handleCheckRevision = (value) => {
            let detailRevisiCheck = this.state.detailRevisiCheck
            let payload = {
                report_id: value[0],
d.arizona's avatar
d.arizona committed
2875 2876
                remarks: value[2],
                number: value[3]
d.arizona's avatar
d.arizona committed
2877
            }
d.arizona's avatar
d.arizona committed
2878
            let indexDataRevisi = this.state.dataTableRevision.findIndex((val) => val[3] == value[3])
Deni Rinaldi's avatar
Deni Rinaldi committed
2879
            let indexId = detailRevisiCheck.sort((a, b) => a.number - b.number).findIndex((val) => val.number == value[3])
d.arizona's avatar
d.arizona committed
2880
            // // console.log(indexId)
d.arizona's avatar
d.arizona committed
2881
            if (indexId == -1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2882
                this.state.dataTableRevision.map((item, index) => {
d.arizona's avatar
d.arizona committed
2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894
                    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
2895 2896
                detailRevisiCheck.push(payload)
            } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
2897

d.arizona's avatar
d.arizona committed
2898
                let x = 0
Deni Rinaldi's avatar
Deni Rinaldi committed
2899
                detailRevisiCheck.sort((a, b) => a.number - b.number).map((item, index) => {
d.arizona's avatar
d.arizona committed
2900 2901 2902 2903 2904
                    if (item.number < value[3]) {
                        x += 1
                    }
                })
                if (x < 1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2905
                    this.state.dataTableRevision.map((item, index) => {
d.arizona's avatar
d.arizona committed
2906 2907 2908 2909 2910 2911 2912 2913 2914
                        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
2915
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
2916
            this.setState({ detailRevisiCheck: detailRevisiCheck.sort((a, b) => a.number - b.number) })
d.arizona's avatar
d.arizona committed
2917
            // // console.log(detailRevisiCheck)
d.arizona's avatar
d.arizona committed
2918 2919
        }

Deni Rinaldi's avatar
Deni Rinaldi committed
2920 2921 2922 2923 2924 2925 2926 2927
        const options = {
            filter: false,
            sort: false,
            responsive: "scroll",
            print: false,
            download: false,
            selectableRows: false,
            viewColumns: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2928
            pagination: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
2929 2930
            search: false
        }
d.arizona's avatar
d.arizona committed
2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943
        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
2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954
        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
2955
        const loadingComponent = (
idlanirined's avatar
idlanirined committed
2956
            <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
2957 2958 2959 2960 2961 2962 2963 2964
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
            </div>
        );
Deni Rinaldi's avatar
Deni Rinaldi committed
2965
        return (
d.arizona's avatar
d.arizona committed
2966
            <div style={{ flex: 1, backgroundColor: '#f8f8f8' }} >
Deni Rinaldi's avatar
Deni Rinaldi committed
2967 2968 2969 2970 2971
                <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
2972
                {this.state.loading && loadingComponent}
2973 2974 2975
                {this.state.visibleBudgetTahunan && (
                    <div>
                        <div className={"main-color"} style={{ height: 78, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
2976
                            <Typography style={{ fontSize: '16px', color: 'white' }}>Master Budget & CAT Submission</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
2977
                        </div>
2978 2979 2980
                        <div style={{ padding: 20, width: '100%' }}>
                            <Paper style={{ paddingTop: 10 }}>
                                <div style={{ borderBottom: 'solid 1px #c4c4c4' }} >
2981
                                    <Typography style={{ fontSize: '12px', color: '#4b4b4b', margin: 10 }}>Master Budget</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
2982
                                </div>
2983
                                <div style={{ padding: 20 }}>
Riri Novita's avatar
Riri Novita committed
2984 2985
                                    <div style={{ display: "flex" }}>
                                        <div style={{ marginRight: 50 }}>
Riri Novita's avatar
Riri Novita committed
2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005
                                            <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
3006
                                        <div style={{ width: 255 }}>
Riri Novita's avatar
Riri Novita committed
3007
                                            <Autocomplete
Riri Novita's avatar
Riri Novita committed
3008 3009 3010 3011 3012
                                                id="tipe"
                                                disableClearable
                                                options={this.state.currency}
                                                getOptionLabel={(option) => option.value}
                                                value={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3013 3014 3015 3016
                                                // onChange={(event, newInputValue) => this.setState({ defaultCurrency: newInputValue })}
                                                onChange={(event, newInputValue) => this.setState({ defaultCurrency: newInputValue }, () => {
                                                    this.getRevision()
                                                })}
Riri Novita's avatar
Riri Novita committed
3017 3018 3019 3020
                                                renderInput={(params) =>
                                                    <TextField
                                                        {...params}
                                                        variant="standard"
Riri Novita's avatar
Riri Novita committed
3021
                                                        label="Currency"
Riri Novita's avatar
Riri Novita committed
3022 3023 3024 3025 3026 3027 3028 3029 3030
                                                        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
3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045
                                                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
3046
                                            /> */}
Riri Novita's avatar
Riri Novita committed
3047
                                        </div>
3048
                                    </div>
Riri Novita's avatar
Riri Novita committed
3049

3050
                                    <div style={{ marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3051 3052 3053
                                        <Autocomplete
                                            {...this.state.listCompany}
                                            id="company"
idlanirined's avatar
idlanirined committed
3054
                                            disabled={this.state.listCompany === null ? true : this.state.intent === 'Home' ? true : false}
3055
                                            onChange={(event, newInputValue) => this.setState({ company: newInputValue }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
3056
                                                this.setState({ visibleTableHistory: false })
qorri_di's avatar
qorri_di committed
3057
                                                // this.getLastPeriod()
Riri Novita's avatar
Riri Novita committed
3058
                                                this.getCurrency(newInputValue.company_id)
qorri_di's avatar
qorri_di committed
3059
                                                this.getRevision()
3060
                                            })}
Deni Rinaldi's avatar
Deni Rinaldi committed
3061 3062 3063 3064 3065
                                            disableClearable
                                            style={{ width: 250 }}
                                            renderInput={(params) => <TextField {...params} label="Company" margin="normal" style={{ marginTop: 7 }} />}
                                            value={this.state.company}
                                        />
3066 3067
                                    </div>
                                    <div style={{ marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3068
                                        {/* <Autocomplete
3069 3070 3071 3072 3073 3074
                                            {...this.state.listRevision}
                                            id="revision"
                                            onChange={(event, newInputValue) => this.setState({ revision: newInputValue }, () => {
                                                this.getReport()
                                                this.getReportAttachment()
                                            })}
Deni Rinaldi's avatar
Deni Rinaldi committed
3075
                                            disabled={true}
3076 3077 3078 3079
                                            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
3080 3081
                                        /> */}
                                        <TextField disabled={true} label="Revision" margin="normal" style={{ marginTop: 7, width: 250 }} value={this.state.lastRevision} />
3082 3083 3084
                                    </div>

                                    <div style={{ marginTop: 20 }}>
qorri_di's avatar
qorri_di committed
3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116
                                        <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
3117 3118 3119 3120 3121 3122 3123
                                        <MuiThemeProvider theme={getMuiTheme()}>
                                            <MUIDataTable
                                                data={this.state.dataTable}
                                                columns={columns}
                                                options={options}
                                            />
                                        </MuiThemeProvider>
3124 3125 3126 3127 3128
                                    </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
3129
                                        {!this.state.isApprover && (this.state.lastStatus === 'SUBMIT' || this.state.lastStatus === 'REVISION') && (
Deni Rinaldi's avatar
Deni Rinaldi committed
3130 3131 3132 3133
                                            <div style={{ width: '50%' }}>
                                                <button
                                                    style={{
                                                        backgroundColor: 'transparent',
Deni Rinaldi's avatar
Deni Rinaldi committed
3134
                                                        cursor: this.state.isSubmit === false ? 'default' : 'pointer',
Deni Rinaldi's avatar
Deni Rinaldi committed
3135 3136 3137
                                                        borderColor: 'transparent',
                                                        outline: 'none'
                                                    }}
Deni Rinaldi's avatar
Deni Rinaldi committed
3138
                                                    onClick={() => this.state.isSubmit === false ? null : this.setState({ visibleUpload: true })}
Deni Rinaldi's avatar
Deni Rinaldi committed
3139
                                                >
Deni Rinaldi's avatar
Deni Rinaldi committed
3140
                                                    <Typography style={{ fontSize: '16px', color: this.state.isSubmit === false ? 'GrayText' : '#5198ea' }}>Upload File</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
3141 3142 3143
                                                </button>
                                            </div>
                                        )}
3144 3145 3146
                                    </div>
                                    <div style={{ display: 'flex', marginTop: 10 }}>
                                        <div style={{ width: '50%', paddingLeft: 20 }}>
3147
                                            {this.state.listAttachment.length > 0 ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3148
                                                this.state.listAttachment.map((item, index) => {
3149
                                                    return (
Deni Rinaldi's avatar
Deni Rinaldi committed
3150
                                                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3151
                                                            <Typography style={{ fontSize: '13px', color: '#4b4b4b', width: 25 }}>{index + 1}. </Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165

                                                            <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
3166
                                                                    <Typography style={{ fontSize: '13px', color: '#5198ea' }}> {item.attachment_name}</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
3167 3168 3169
                                                                </div>
                                                            </button>
                                                        </div>
3170 3171 3172 3173
                                                    )
                                                })
                                                : null
                                            }
3174
                                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3175
                                        {!this.state.isApprover && (this.state.lastStatus === 'SUBMIT' || this.state.lastStatus === 'REVISION') && (
Deni Rinaldi's avatar
Deni Rinaldi committed
3176
                                            <div style={{ width: '50%' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3177
                                                {
Deni Rinaldi's avatar
Deni Rinaldi committed
3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195
                                                    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
3196 3197 3198
                                                }
                                            </div>
                                        )}
3199
                                    </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3200
                                    {this.state.checkApprover === true ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3201
                                        this.state.lastStatus === 'WAITING FOR REVIEW' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3202
                                            <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3203 3204
                                                <span>{this.state.lastStatus}</span>
                                            </div> : this.state.lastStatus === 'WAITING FOR YOUR APPROVAL' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3205
                                                <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3206
                                                    <span>{this.state.lastStatus}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
3207 3208 3209
                                                </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
3210 3211 3212 3213
                                                    </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
3214 3215
                                        :
                                        this.state.lastStatus === 'SUBMITTED' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3216
                                            <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3217 3218 3219
                                                <span>{this.state.lastStatus}</span>
                                            </div> :
                                            this.state.lastStatus === 'WAITING FOR APPROVAL' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3220
                                                <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
d.arizona's avatar
d.arizona committed
3221
                                                    <span>{`${this.state.lastStatus} - ${this.state.pic}`}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
3222 3223
                                                </div> :
                                                this.state.lastStatus === 'REVISION' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3224
                                                    <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3225 3226 3227
                                                        <span>NEED REVISION</span>
                                                    </div> :
                                                    this.state.lastStatus === 'APPROVED' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3228
                                                        <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3229 3230 3231
                                                            <span>APPROVED</span>
                                                        </div> : null
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
3232 3233 3234 3235 3236 3237
                                    {this.state.visibleTableHistory && (
                                        <div style={{ marginTop: 20 }}>
                                            <MuiThemeProvider theme={getMuiTheme()}>
                                                <MUIDataTable
                                                    data={this.state.dataTableHistory}
                                                    columns={columnsHistory}
d.arizona's avatar
d.arizona committed
3238
                                                    options={optionsHistory}
Deni Rinaldi's avatar
Deni Rinaldi committed
3239 3240 3241 3242
                                                />
                                            </MuiThemeProvider>
                                        </div>
                                    )}
Deni Rinaldi's avatar
Deni Rinaldi committed
3243
                                </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3244
                                {this.state.isAdmin && this.state.lastStatus == 'APPROVED' ?
Dida Adams Arizona's avatar
Dida Adams Arizona committed
3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276
                                    <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
3277
                                    :
3278 3279 3280 3281
                                    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
3282 3283 3284 3285 3286 3287 3288
                                                <button
                                                    style={{
                                                        backgroundColor: 'transparent',
                                                        cursor: 'pointer',
                                                        borderColor: 'transparent',
                                                        outline: 'none',
                                                    }}
3289
                                                    onClick={() => this.handleApproveAdmin()}
Deni Rinaldi's avatar
Deni Rinaldi committed
3290
                                                >
Deni Rinaldi's avatar
Deni Rinaldi committed
3291
                                                    <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
3292
                                                        <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Approve</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
3293 3294
                                                    </div>
                                                </button>
3295 3296
                                            </div>
                                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3297
                                        :
3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350
                                        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
3351 3352 3353 3354 3355 3356 3357 3358
                                                <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',
                                                        }}
3359
                                                        onClick={() => this.validate()}
Deni Rinaldi's avatar
Deni Rinaldi committed
3360
                                                    >
3361 3362
                                                        <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
3363 3364
                                                        </div>
                                                    </button>
3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381
                                                </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
3382
                                }
3383 3384
                            </Paper>

Deni Rinaldi's avatar
Deni Rinaldi committed
3385
                        </div>
3386
                    </div>
idlanirined's avatar
idlanirined committed
3387 3388
                )
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
3389

idlanirined's avatar
idlanirined committed
3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407
                {
                    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>
3408 3409
                                    </div>
                                </div>
idlanirined's avatar
idlanirined committed
3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420
                                <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)}
                                />
3421 3422
                            </div>
                        </div>
idlanirined's avatar
idlanirined committed
3423 3424
                    )
                }
3425

idlanirined's avatar
idlanirined committed
3426 3427 3428 3429 3430 3431 3432 3433
                {
                    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
3434
                            defaultCurrency={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3435
                            currency={this.state.currency}
idlanirined's avatar
idlanirined committed
3436 3437 3438 3439 3440 3441 3442
                            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
3443
                            truelyApprover={this.state.truelyApprover}
idlanirined's avatar
idlanirined committed
3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457
                            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
3458
                            defaultCurrency={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3459
                            currency={this.state.currency}
idlanirined's avatar
idlanirined committed
3460 3461 3462 3463 3464 3465 3466 3467
                            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
3468
                            truelyApprover={this.state.truelyApprover}
idlanirined's avatar
idlanirined committed
3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481
                            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
3482
                            defaultCurrency={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3483
                            currency={this.state.currency}
idlanirined's avatar
idlanirined committed
3484 3485 3486 3487 3488 3489 3490 3491
                            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
3492
                            truelyApprover={this.state.truelyApprover}
idlanirined's avatar
idlanirined committed
3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505
                            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
3506
                            defaultCurrency={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3507
                            currency={this.state.currency}
idlanirined's avatar
idlanirined committed
3508 3509 3510 3511 3512 3513 3514 3515
                            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
3516
                            truelyApprover={this.state.truelyApprover}
idlanirined's avatar
idlanirined committed
3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529
                            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
3530
                            defaultCurrency={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3531
                            currency={this.state.currency}
idlanirined's avatar
idlanirined committed
3532 3533 3534 3535 3536 3537 3538
                            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
3539
                            truelyApprover={this.state.truelyApprover}
idlanirined's avatar
idlanirined committed
3540
                            status={this.state.status}
d.arizona's avatar
d.arizona committed
3541
                            // status={'not-yet'}
idlanirined's avatar
idlanirined committed
3542
                            lastStatus={this.state.lastStatus}
d.arizona's avatar
d.arizona committed
3543 3544
                            // lastStatus={'SUBMIT'}
                            // prevRevision={false}
idlanirined's avatar
idlanirined committed
3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556
                            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
3557
                            defaultCurrency={this.state.defaultCurrency}
Riri Novita's avatar
Riri Novita committed
3558
                            currency={this.state.currency}
idlanirined's avatar
idlanirined committed
3559 3560 3561 3562 3563 3564 3565
                            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
3566
                            truelyApprover={this.state.truelyApprover}
idlanirined's avatar
idlanirined committed
3567 3568 3569
                            status={this.state.status}
                            lastStatus={this.state.lastStatus}
                            prevRevision={this.state.isSubmit ? this.state.prevRevision : true}
d.arizona's avatar
d.arizona committed
3570
                            // PLBSFAMSubmitted={false}
3571
                            PLBSFAMSubmitted={this.state.lastStatus == 'APPROVED' ? true : false}
d.arizona's avatar
d.arizona committed
3572
                            createCashFlow={this.createCashFlow.bind(this)}
idlanirined's avatar
idlanirined committed
3573 3574 3575
                        />
                    )
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
3576

idlanirined's avatar
idlanirined committed
3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594
                {
                    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
3595 3596
                                    </div>
                                </div>
idlanirined's avatar
idlanirined committed
3597 3598 3599 3600 3601 3602 3603 3604
                                <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
3605
                                            />
idlanirined's avatar
idlanirined committed
3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632
                                        </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
3633

idlanirined's avatar
idlanirined committed
3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664
                                                    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
3665 3666 3667
                                        </div>
                                    </div>
                                </div>
idlanirined's avatar
idlanirined committed
3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688
                                <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
3689 3690 3691
                                </div>
                            </div>
                        </div>
idlanirined's avatar
idlanirined committed
3692 3693
                    )
                }
3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744

                {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
3745
                                        onClick={() => this.state.approver == null ? this.setState({ alert: true, messageAlert: 'Approver Cannot be Empty', tipeAlert: 'error' }) : this.setHeaderTokenSuperadmin('approve')}
3746 3747 3748 3749 3750 3751 3752 3753 3754 3755
                                    >
                                        <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
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

                {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
3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809

                {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
                                        }}
3810
                                        onClick={() => this.setState({ visibleAlertSave: false, loading: false })}
Riri Novita's avatar
Riri Novita committed
3811 3812 3813 3814 3815 3816 3817 3818 3819 3820
                                    >
                                        <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
3821 3822 3823 3824
            </div >
        );
    }
}