BudgetTahunan.js 209 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,
                    };
Riri Novita's avatar
Riri Novita committed
555
                    // ubah code dibawah ini jika mau mengubah default periode jadi tahun saat ini
Riri Novita's avatar
Riri Novita committed
556 557
                    // let periode = (this.state.lastPeriod == "" ? String(Number(currentYear)) : this.state.lastPeriod)
                    let periode = String(Number(currentYear))
Deni Rinaldi's avatar
Deni Rinaldi committed
558
                    let index = data.sort((a, b) => a - b).findIndex((val) => val === periode)
d.arizona's avatar
d.arizona committed
559
                    // // console.log(this.props.location.state.rawData)
Riri Novita's avatar
Riri Novita committed
560 561 562
                    // console.log(this.state.lastPeriod)
                    // console.log(periode)
                    // console.log(index)
d.arizona's avatar
d.arizona committed
563 564
                    // console.log(periodeData)
                    // // // console.log(index)
Riri Novita's avatar
Riri Novita committed
565
                    console.log(this.state.isApprover);
Deni Rinaldi's avatar
Deni Rinaldi committed
566
                    this.setState({ listPeriode: defaultProps, periode: index === -1 ? periodeData[0] : periodeData[index] }, () => {
r.kurnia's avatar
r.kurnia committed
567
                        if (this.state.isApprover === true) {
Deni Rinaldi's avatar
Deni Rinaldi committed
568 569 570
                            this.getCompanySubmitted()
                        } else {
                            this.getRevision()
Riri Novita's avatar
Riri Novita committed
571
                            this.getCurrency(this.state.company.company_id)
Deni Rinaldi's avatar
Deni Rinaldi committed
572
                        }
573 574 575 576 577 578 579
                    })
                }
            }
        })
    }

    getRevision() {
qorri_di's avatar
qorri_di committed
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 610 611
        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
612
                } else {
qorri_di's avatar
qorri_di committed
613
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listRevision: null, revision: null })
Deni Rinaldi's avatar
Deni Rinaldi committed
614
                }
qorri_di's avatar
qorri_di committed
615
            })
Deni Rinaldi's avatar
Deni Rinaldi committed
616 617 618
        })
    }

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

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

d.arizona's avatar
d.arizona committed
731 732 733 734 735 736
    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
737
            "currency_id": this.state.defaultCurrency.id,
d.arizona's avatar
d.arizona committed
738 739 740
            "submission_id": this.state.submissionID
        }
        api.create().getDetailReportCF(payload).then(response => {
741
            // console.log(response);
d.arizona's avatar
d.arizona committed
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 820 821
            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
822
                // console.log(dataTable)
d.arizona's avatar
d.arizona committed
823
                this.setState({ dbCF: dataTable }, () => {
d.arizona's avatar
d.arizona committed
824
                    this.olahDataCashFlow(this.state.dbCF, type)
d.arizona's avatar
d.arizona committed
825
                })
Riri Novita's avatar
Riri Novita committed
826 827
            } else {
                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
828
                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Riri Novita's avatar
Riri Novita committed
829 830 831 832 833 834
                        setTimeout(() => {
                            localStorage.removeItem(Constant.TOKEN)
                            window.location.reload();
                        }, 1000);
                    }
                })
d.arizona's avatar
d.arizona committed
835 836 837 838 839 840 841 842 843 844 845 846 847 848
            }
        })
    }

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

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

                            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
925 926 927 928 929 930
                                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
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 1119 1120
                            }
                        }
                    } 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
1121 1122 1123 1124 1125 1126 1127 1128
        // 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)
        // }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

d.arizona's avatar
d.arizona committed
1261 1262 1263 1264 1265 1266 1267

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

d.arizona's avatar
d.arizona committed
1293 1294
        })

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

1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
    createCashFlow(payload) {
        api.create().createReportCF(payload).then((res) => {
            console.log(res)
            // this.getSubmission()
            if (res.data) {
                if (res.data.status === "success") {
                    this.setState({ visibleCF: false, visibleBudgetTahunan: true })
                    this.getSubmission()
                } else {
                    if (res.data.message == "Please Set Up Rate Currency First") {
                        this.setState({ visibleAlertSave: true })
Riri Novita's avatar
Riri Novita committed
1320
                    } else {
1321
                        this.setState({ alert: true, messageAlert: res.data.message, tipeAlert: 'warning', loading: false })
Riri Novita's avatar
Riri Novita committed
1322 1323
                    }
                }
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339
            }
            // if (response.data) {
            //     if (response.data.status === "success") {
            //         this.props.saveToMonthlyReport()
            //     } else {
            //         this.setState({ loading: false }, () => {
            //             this.props.saveToMonthlyReport()
            //         })
            //     }
            // } else {
            //     this.setState({ loading: false }, () => {
            //         // this.getSubmission()
            //         document.body.style.overflow = 'unset';
            //     })
            // }
        })
1340 1341
    }

1342
    getPL(type) {
d.arizona's avatar
d.arizona committed
1343 1344
        let PLID = null
        let payloadID = {
1345
            "periode": this.state.periode.periode,
d.arizona's avatar
d.arizona committed
1346
            "company_id": this.state.company.company_id
1347
        }
d.arizona's avatar
d.arizona committed
1348 1349
        console.log(payloadID);
        api.create().getPLID(payloadID).then(response => {
Riri Novita's avatar
Riri Novita committed
1350
            // console.log(response);
d.arizona's avatar
d.arizona committed
1351
            if (response) {
d.arizona's avatar
d.arizona committed
1352
                PLID = response.data.data == null ? null : response.data.data.profit_loss_id
d.arizona's avatar
d.arizona committed
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362
            } 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
1363
                    "currency_id": this.state.defaultCurrency.id,
d.arizona's avatar
d.arizona committed
1364 1365
                    "months": 0,
                    "quarter": 0,
1366
                }
d.arizona's avatar
d.arizona committed
1367 1368 1369 1370 1371
                api.create().getHierarkiCreateReportPLMB(payload).then(response => {
                    // console.log(response);
                    let dataTable = []
                    if (response.data) {
                        // let dataTable = []
Riri Novita's avatar
Riri Novita committed
1372
                        // console.log(response)
d.arizona's avatar
d.arizona committed
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 1399 1400
                        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
1401 1402
                                item.profit_detail.forecast_formula == null ? [] : item.profit_detail.forecast_formula,
                                item.profit_detail.notes
d.arizona's avatar
d.arizona committed
1403
                            ])
d.arizona's avatar
d.arizona committed
1404

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


1460
                })
d.arizona's avatar
d.arizona committed
1461
            })
1462
        })
d.arizona's avatar
d.arizona committed
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 1508 1509
    }

    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
1510 1511
                            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)
1512 1513

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

1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598
        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
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 1662 1663

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

        return total
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1778 1779 1780 1781

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

1801 1802
        })

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

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

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

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


1963 1964 1965
                })
            })
        })
d.arizona's avatar
d.arizona committed
1966 1967


1968 1969 1970 1971 1972 1973 1974
    }

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

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

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

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

2064 2065
        })

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

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

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

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

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

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

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

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

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

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

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

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

Deni Rinaldi's avatar
Deni Rinaldi committed
2453
    }
Deni Rinaldi's avatar
Deni Rinaldi committed
2454

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

2472 2473 2474 2475
    handleApproveAdmin() {
        this.setState({ visibleApproveSuperadmin: true })
    }

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

    handleDownloadReport(tableMeta) {
Riri Novita's avatar
Riri Novita committed
2518
        let { selectReport, company, periode, month, defaultCurrency } = this.state
qorri_di's avatar
qorri_di committed
2519 2520 2521 2522 2523 2524
        let payload = {
            "company_id": company.company_id,
            "year": periode.periode,
            "report_id": selectReport,
            "month": "",
            "quartal": "",
Riri Novita's avatar
Riri Novita committed
2525
            "type_report_name": "Master Budget",
Riri Novita's avatar
Riri Novita committed
2526
            "currency_id": defaultCurrency.id
qorri_di's avatar
qorri_di committed
2527
        }
Riri Novita's avatar
Riri Novita committed
2528
        // console.log(payload);
qorri_di's avatar
qorri_di committed
2529
        api.create().createDownloadFile(payload).then((response) => {
Riri Novita's avatar
Riri Novita committed
2530
            // console.log(response)
qorri_di's avatar
qorri_di committed
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 2563 2564 2565
            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
2566
        let { selectReport, submissionID, company, periode, month, downloadedFileReportId, defaultCurrency } = this.state
qorri_di's avatar
qorri_di committed
2567 2568
        if (selectReport.length > 0) {
            let result = []
Riri Novita's avatar
Riri Novita committed
2569
            // console.log('mulai hit')
qorri_di's avatar
qorri_di committed
2570 2571 2572 2573
            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
2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590
                    try {
                        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}`

                        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];
                        }
                    } catch (error) {
                        alert(error)
qorri_di's avatar
qorri_di committed
2591
                    }
Riri Novita's avatar
Riri Novita committed
2592

qorri_di's avatar
qorri_di committed
2593
                } else {
Riri Novita's avatar
Riri Novita committed
2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610
                    try {
                        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}`

                        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];
                        }
                    } catch (error) {
                        alert(error)
qorri_di's avatar
qorri_di committed
2611 2612 2613 2614
                    }
                }
            }

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

        const columnsHistory = [
            "Name", "Status", "Remarks", "Revision Item", "Date"
        ]
Deni Rinaldi's avatar
Deni Rinaldi committed
2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824

        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
2825 2826 2827
                                        <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
2828 2829 2830 2831 2832 2833
                                    }
                                />
                            </div >
                        );
                    }
                }
d.arizona's avatar
d.arizona committed
2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852
            }, "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
2853
                                                // // // console.log(event.target.value)
d.arizona's avatar
d.arizona committed
2854 2855
                                                // updateValue(event.target.value)
                                                handleChangeText(event.target.value, tableMeta)
d.arizona's avatar
d.arizona committed
2856
                                                // // // console.log(dataTable2)
d.arizona's avatar
d.arizona committed
2857 2858
                                            }}
                                        />}
Deni Rinaldi's avatar
Deni Rinaldi committed
2859
                                />
d.arizona's avatar
d.arizona committed
2860 2861 2862 2863
                            </div>
                        )
                    }
                }
d.arizona's avatar
d.arizona committed
2864 2865 2866
            }, {
                name: "",
                options: { display: false }
d.arizona's avatar
d.arizona committed
2867
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
2868 2869
        ]

d.arizona's avatar
d.arizona committed
2870 2871 2872 2873 2874 2875 2876 2877 2878 2879
        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
2880
            this.setState({ dataTableRevision, detailRevisiCheck })
d.arizona's avatar
d.arizona committed
2881 2882 2883 2884 2885 2886
        }

        const handleCheckRevision = (value) => {
            let detailRevisiCheck = this.state.detailRevisiCheck
            let payload = {
                report_id: value[0],
d.arizona's avatar
d.arizona committed
2887 2888
                remarks: value[2],
                number: value[3]
d.arizona's avatar
d.arizona committed
2889
            }
d.arizona's avatar
d.arizona committed
2890
            let indexDataRevisi = this.state.dataTableRevision.findIndex((val) => val[3] == value[3])
Deni Rinaldi's avatar
Deni Rinaldi committed
2891
            let indexId = detailRevisiCheck.sort((a, b) => a.number - b.number).findIndex((val) => val.number == value[3])
d.arizona's avatar
d.arizona committed
2892
            // // console.log(indexId)
d.arizona's avatar
d.arizona committed
2893
            if (indexId == -1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2894
                this.state.dataTableRevision.map((item, index) => {
d.arizona's avatar
d.arizona committed
2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906
                    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
2907 2908
                detailRevisiCheck.push(payload)
            } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
2909

d.arizona's avatar
d.arizona committed
2910
                let x = 0
Deni Rinaldi's avatar
Deni Rinaldi committed
2911
                detailRevisiCheck.sort((a, b) => a.number - b.number).map((item, index) => {
d.arizona's avatar
d.arizona committed
2912 2913 2914 2915 2916
                    if (item.number < value[3]) {
                        x += 1
                    }
                })
                if (x < 1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
2917
                    this.state.dataTableRevision.map((item, index) => {
d.arizona's avatar
d.arizona committed
2918 2919 2920 2921 2922 2923 2924 2925 2926
                        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
2927
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
2928
            this.setState({ detailRevisiCheck: detailRevisiCheck.sort((a, b) => a.number - b.number) })
d.arizona's avatar
d.arizona committed
2929
            // // console.log(detailRevisiCheck)
d.arizona's avatar
d.arizona committed
2930 2931
        }

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

3062
                                    <div style={{ marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3063 3064 3065
                                        <Autocomplete
                                            {...this.state.listCompany}
                                            id="company"
idlanirined's avatar
idlanirined committed
3066
                                            disabled={this.state.listCompany === null ? true : this.state.intent === 'Home' ? true : false}
3067
                                            onChange={(event, newInputValue) => this.setState({ company: newInputValue }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
3068
                                                this.setState({ visibleTableHistory: false })
Riri Novita's avatar
Riri Novita committed
3069
                                                this.getLastPeriod()
Riri Novita's avatar
Riri Novita committed
3070
                                                this.getCurrency(newInputValue.company_id)
qorri_di's avatar
qorri_di committed
3071
                                                this.getRevision()
3072
                                            })}
Deni Rinaldi's avatar
Deni Rinaldi committed
3073 3074 3075 3076 3077
                                            disableClearable
                                            style={{ width: 250 }}
                                            renderInput={(params) => <TextField {...params} label="Company" margin="normal" style={{ marginTop: 7 }} />}
                                            value={this.state.company}
                                        />
3078 3079
                                    </div>
                                    <div style={{ marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3080
                                        {/* <Autocomplete
3081 3082 3083 3084 3085 3086
                                            {...this.state.listRevision}
                                            id="revision"
                                            onChange={(event, newInputValue) => this.setState({ revision: newInputValue }, () => {
                                                this.getReport()
                                                this.getReportAttachment()
                                            })}
Deni Rinaldi's avatar
Deni Rinaldi committed
3087
                                            disabled={true}
3088 3089 3090 3091
                                            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
3092 3093
                                        /> */}
                                        <TextField disabled={true} label="Revision" margin="normal" style={{ marginTop: 7, width: 250 }} value={this.state.lastRevision} />
3094 3095 3096
                                    </div>

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

                                                            <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
3178
                                                                    <Typography style={{ fontSize: '13px', color: '#5198ea' }}> {item.attachment_name}</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
3179 3180 3181
                                                                </div>
                                                            </button>
                                                        </div>
3182 3183 3184 3185
                                                    )
                                                })
                                                : null
                                            }
3186
                                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3187
                                        {!this.state.isApprover && (this.state.lastStatus === 'SUBMIT' || this.state.lastStatus === 'REVISION') && (
Deni Rinaldi's avatar
Deni Rinaldi committed
3188
                                            <div style={{ width: '50%' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3189
                                                {
Deni Rinaldi's avatar
Deni Rinaldi committed
3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207
                                                    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
3208 3209 3210
                                                }
                                            </div>
                                        )}
3211
                                    </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3212
                                    {this.state.checkApprover === true ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3213
                                        this.state.lastStatus === 'WAITING FOR REVIEW' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3214
                                            <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3215 3216
                                                <span>{this.state.lastStatus}</span>
                                            </div> : this.state.lastStatus === 'WAITING FOR YOUR APPROVAL' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3217
                                                <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3218
                                                    <span>{this.state.lastStatus}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
3219 3220 3221
                                                </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
3222 3223 3224 3225
                                                    </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
3226 3227
                                        :
                                        this.state.lastStatus === 'SUBMITTED' ?
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>{this.state.lastStatus}</span>
                                            </div> :
                                            this.state.lastStatus === 'WAITING FOR APPROVAL' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3232
                                                <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
d.arizona's avatar
d.arizona committed
3233
                                                    <span>{`${this.state.lastStatus} - ${this.state.pic}`}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
3234 3235
                                                </div> :
                                                this.state.lastStatus === 'REVISION' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3236
                                                    <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3237 3238 3239
                                                        <span>NEED REVISION</span>
                                                    </div> :
                                                    this.state.lastStatus === 'APPROVED' ?
Deni Rinaldi's avatar
Deni Rinaldi committed
3240
                                                        <div style={{ width: '100%', padding: '10px 20px', backgroundColor: 'yellow', textAlign: 'center', marginTop: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
3241 3242 3243
                                                            <span>APPROVED</span>
                                                        </div> : null
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
3244 3245 3246 3247 3248 3249
                                    {this.state.visibleTableHistory && (
                                        <div style={{ marginTop: 20 }}>
                                            <MuiThemeProvider theme={getMuiTheme()}>
                                                <MUIDataTable
                                                    data={this.state.dataTableHistory}
                                                    columns={columnsHistory}
d.arizona's avatar
d.arizona committed
3250
                                                    options={optionsHistory}
Deni Rinaldi's avatar
Deni Rinaldi committed
3251 3252 3253 3254
                                                />
                                            </MuiThemeProvider>
                                        </div>
                                    )}
Deni Rinaldi's avatar
Deni Rinaldi committed
3255
                                </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
3256
                                {this.state.isAdmin && this.state.lastStatus == 'APPROVED' ?
Dida Adams Arizona's avatar
Dida Adams Arizona committed
3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288
                                    <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
3289
                                    :
3290 3291 3292 3293
                                    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
3294 3295 3296 3297 3298 3299 3300
                                                <button
                                                    style={{
                                                        backgroundColor: 'transparent',
                                                        cursor: 'pointer',
                                                        borderColor: 'transparent',
                                                        outline: 'none',
                                                    }}
3301
                                                    onClick={() => this.handleApproveAdmin()}
Deni Rinaldi's avatar
Deni Rinaldi committed
3302
                                                >
Deni Rinaldi's avatar
Deni Rinaldi committed
3303
                                                    <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
3304
                                                        <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Approve</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
3305 3306
                                                    </div>
                                                </button>
3307 3308
                                            </div>
                                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
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 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362
                                        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
3363 3364 3365 3366 3367 3368 3369 3370
                                                <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',
                                                        }}
3371
                                                        onClick={() => this.validate()}
Deni Rinaldi's avatar
Deni Rinaldi committed
3372
                                                    >
3373 3374
                                                        <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
3375 3376
                                                        </div>
                                                    </button>
3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393
                                                </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
3394
                                }
3395 3396
                            </Paper>

Deni Rinaldi's avatar
Deni Rinaldi committed
3397
                        </div>
3398
                    </div>
idlanirined's avatar
idlanirined committed
3399 3400
                )
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
3401

idlanirined's avatar
idlanirined committed
3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419
                {
                    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>
3420 3421
                                    </div>
                                </div>
idlanirined's avatar
idlanirined committed
3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432
                                <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)}
                                />
3433 3434
                            </div>
                        </div>
idlanirined's avatar
idlanirined committed
3435 3436
                    )
                }
3437

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

idlanirined's avatar
idlanirined committed
3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606
                {
                    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
3607 3608
                                    </div>
                                </div>
idlanirined's avatar
idlanirined committed
3609 3610 3611 3612 3613 3614 3615 3616
                                <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
3617
                                            />
idlanirined's avatar
idlanirined committed
3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644
                                        </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
3645

idlanirined's avatar
idlanirined committed
3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676
                                                    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
3677 3678 3679
                                        </div>
                                    </div>
                                </div>
idlanirined's avatar
idlanirined committed
3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700
                                <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
3701 3702 3703
                                </div>
                            </div>
                        </div>
idlanirined's avatar
idlanirined committed
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 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756

                {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
3757
                                        onClick={() => this.state.approver == null ? this.setState({ alert: true, messageAlert: 'Approver Cannot be Empty', tipeAlert: 'error' }) : this.setHeaderTokenSuperadmin('approve')}
3758 3759 3760 3761 3762 3763 3764 3765 3766 3767
                                    >
                                        <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
3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796

                {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
3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821

                {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
                                        }}
3822
                                        onClick={() => this.setState({ visibleAlertSave: false, loading: false })}
Riri Novita's avatar
Riri Novita committed
3823 3824 3825 3826 3827 3828 3829 3830 3831 3832
                                    >
                                        <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
3833 3834 3835
            </div >
        );
    }
Riri Novita's avatar
Riri Novita committed
3836
}