ListOfCreditFacilitiesMR.js 108 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 { createMuiTheme, FormControlLabel, MuiThemeProvider, Paper, TableCell, Tooltip, Typography, withStyles, Input, ThemeProvider, TextareaAutosize } from '@material-ui/core'
Deni Rinaldi's avatar
Deni Rinaldi committed
3 4 5
import MUIDataTable from 'mui-datatables';
import Images from '../../assets/Images';
import api from '../../api';
faisalhamdi's avatar
faisalhamdi committed
6
import NumberFormat from 'react-number-format';
d.arizona's avatar
d.arizona committed
7 8 9 10 11 12 13 14
import Constant from '../../library/Constant';
import { titleCase } from '../../library/Utils';
import { Autocomplete } from '@material-ui/lab';
import { PropagateLoader } from 'react-spinners';
import ReactTooltip from 'react-tooltip';
import { DatePicker } from '@material-ui/pickers';
import { format } from 'date-fns';
import { BorderStyle } from '@material-ui/icons';
Riri Novita's avatar
Riri Novita committed
15
import { includes, update } from 'ramda';
d.arizona's avatar
d.arizona committed
16 17 18 19 20
import Snackbar from '@material-ui/core/Snackbar';
import MuiAlert from '@material-ui/lab/Alert';
import { makeStyles } from '@material-ui/core/styles';
import UploadFile from "../../library/Upload";
import { ExcelRenderer } from 'react-excel-renderer';
Riri Novita's avatar
Riri Novita committed
21
import { fixNumber, roundMath } from "../../library/Utils";
Riri Novita's avatar
Riri Novita committed
22 23
import LOCF from './LOCFMR';
import LOV from './LOVMR';
fahrur huzain's avatar
fahrur huzain committed
24
import PopUpValidationLOV from '../../library/PopUpValidationLOV';
d.arizona's avatar
d.arizona committed
25

Riri Novita's avatar
Riri Novita committed
26 27 28 29 30 31
const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);

// function Alert(props) {
//     return <MuiAlert elevation={6} variant="filled" {...props} />;
// }
d.arizona's avatar
d.arizona committed
32 33

const useStyles = makeStyles((theme) => ({
34 35 36 37 38
    root: {
        width: '100%',
        '& > * + *': {
            marginTop: theme.spacing(2),
        },
d.arizona's avatar
d.arizona committed
39 40
    },
}));
Deni Rinaldi's avatar
Deni Rinaldi committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

const LightTooltip = withStyles((theme) => ({
    tooltip: {
        backgroundColor: theme.palette.common.white,
        color: 'rgba(0, 0, 0, 0.87)',
        boxShadow: theme.shadows[1],
        fontSize: 11,
    },
}))(Tooltip);
var ct = require("../../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable3());
const options = ct.customOptionsFixedColumn();

const style = {
    position: "sticky",
    left: 0,
    background: "white",
    zIndex: 101,
};

const style2 = {
    position: "sticky",
    background: "white",
    zIndex: 100,
    top: 0
};
Deni Rinaldi's avatar
Deni Rinaldi committed
67

d.arizona's avatar
d.arizona committed
68 69 70 71 72 73 74 75 76 77 78 79 80
const theme = createMuiTheme({
    overrides: {
        // Style sheet name ⚛️
        MuiInputBase: {
            input: {
                color: '#5198ea',
                marginTop: -10,
                textAlign: 'center'
            }
        }
    },
});

d.arizona's avatar
d.arizona committed
81 82 83 84 85 86 87 88 89 90 91 92
const theme2 = createMuiTheme({
    overrides: {
        // Style sheet name ⚛️
        MuiInputBase: {
            input: {
                color: '#5198ea',
                textAlign: 'center'
            }
        }
    },
});

d.arizona's avatar
d.arizona committed
93 94 95 96 97 98 99 100 101 102 103 104
const theme3 = createMuiTheme({
    overrides: {
        // Style sheet name ⚛️
        MuiInputBase: {
            input: {
                color: '#black',
                textAlign: 'center'
            }
        }
    },
});

Deni Rinaldi's avatar
Deni Rinaldi committed
105
export default class ListOfCreditFacilities extends Component {
Deni Rinaldi's avatar
Deni Rinaldi committed
106 107 108 109
    constructor(props) {
        super(props)
        this.state = {
            dataTable: [],
Riri Novita's avatar
Riri Novita committed
110 111
            dataTableLOV: [],
            dataTableLOCF: [],
Riri Novita's avatar
Riri Novita committed
112
            datas: null,
Riri Novita's avatar
Riri Novita committed
113 114
            lastArrayLOCF: null,
            lastArrayLOV: null,
d.arizona's avatar
d.arizona committed
115 116 117
            bankNameList: [],
            typeOfCreditList: [],
            loading: false,
Riri Novita's avatar
Riri Novita committed
118
            loadingChild: false,
d.arizona's avatar
d.arizona committed
119
            dataTableRatio: [],
d.arizona's avatar
d.arizona committed
120
            currentDate: format(new Date(), 'yyyy-MM-dd'),
d.arizona's avatar
d.arizona committed
121
            totalOutStand: 0,
Riri Novita's avatar
Riri Novita committed
122 123
            diffLOCF: 0,
            perBSLOCF: 0,
Riri Novita's avatar
Riri Novita committed
124
            totalLoanLOCF: 0,
Riri Novita's avatar
Riri Novita committed
125 126
            diffLOV: 0,
            perBSLOV: 0,
Riri Novita's avatar
Riri Novita committed
127
            totalLoanLOV: 0,
d.arizona's avatar
d.arizona committed
128 129
            snekbar: false,
            snekbarMsg: '',
Riri Novita's avatar
Riri Novita committed
130 131
            visibleParent: true,
            buttonError: false,
d.arizona's avatar
d.arizona committed
132
            saveDraft: true,
d.arizona's avatar
d.arizona committed
133
            saveComp: true,
Riri Novita's avatar
Riri Novita committed
134
            saveCompLOV: true,
d.arizona's avatar
d.arizona committed
135
            get_for: 'view',
faisalhamdi's avatar
faisalhamdi committed
136
            updateBy: [],
d.arizona's avatar
d.arizona committed
137
            notes: "",
d.arizona's avatar
d.arizona committed
138
            viewOnly: true,
d.arizona's avatar
d.arizona committed
139
            dataDelete: [],
140 141
            saveTambahan: true,
            defaultCurrencyUpload: this.props.defaultCurrency,
Riri Novita's avatar
Riri Novita committed
142
            visibleAlertSave: false,
Riri Novita's avatar
Riri Novita committed
143 144 145
            alert: false,
            tipeAlert: '',
            messageAlert: '',
fahrur huzain's avatar
fahrur huzain committed
146
            emptyData: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
147 148
        }
    }
Deni Rinaldi's avatar
Deni Rinaldi committed
149

Deni Rinaldi's avatar
Deni Rinaldi committed
150
    componentDidMount() {
Riri Novita's avatar
Riri Novita committed
151
        // this.getperBSLOCF()
Riri Novita's avatar
Riri Novita committed
152 153
        // this.getBankData()
        // this.getTypeOfCredit()
d.arizona's avatar
d.arizona committed
154
        this.getSubmission()
d.arizona's avatar
d.arizona committed
155
        this.getLatestUpdate()
156
        this.handleViewOnly()
Riri Novita's avatar
Riri Novita committed
157 158
    }

d.arizona's avatar
d.arizona committed
159
    handleGetFor(type) {
160
        this.setState({ get_for: type }, () => {
Riri Novita's avatar
Riri Novita committed
161
            // this.getperBSLOCF()
Riri Novita's avatar
Riri Novita committed
162 163 164 165
            // this.getBankData()
            // this.getTypeOfCredit()
            // this.getSubmission()
            // this.getLatestUpdate()
d.arizona's avatar
d.arizona committed
166 167 168
        })
    }

Riri Novita's avatar
Riri Novita committed
169
    dataTableForChild(data, array, params, type, visibleView, updateData) {
Riri Novita's avatar
Riri Novita committed
170 171
        // console.log(visibleView);
        // console.log(type);
Riri Novita's avatar
Riri Novita committed
172 173
        switch (params) {
            case "LOV":
Riri Novita's avatar
Riri Novita committed
174
                console.log(data);
Riri Novita's avatar
Riri Novita committed
175
                this.setState({ dataTableLOV: data, diffLOV: array[16], totalLoanLOV: array[17], perBSLOV: array[18], tambahLOV: type, visibleParent: visibleView == undefined ? true : visibleView, updateData: updateData })
Riri Novita's avatar
Riri Novita committed
176 177
                break;
            case "LOCF":
Riri Novita's avatar
Riri Novita committed
178
                this.setState({ dataTableLOCF: data, diffLOCF: array[47], totalLoanLOCF: array[48], perBSLOCF: array[49], tambah: type, visibleParent: visibleView == undefined ? true : visibleView, updateDataLOCF: updateData })
Riri Novita's avatar
Riri Novita committed
179 180 181 182 183 184
                break
            default:
                break;
        }
    }

d.arizona's avatar
d.arizona committed
185 186 187 188
    handleViewOnly() {
        let checkApprover = false
        let checkLastStatus = false
        let checkStatus = false
d.arizona's avatar
d.arizona committed
189
        let checkPrevRev = false
d.arizona's avatar
d.arizona committed
190 191 192 193 194 195

        if (this.props.isApprover) {
            checkApprover = true
        } else {
            checkApprover = false
        }
196

d.arizona's avatar
d.arizona committed
197 198 199 200
        if (this.props.lastStatus == 'SUBMIT' || this.props.lastStatus == 'REVISION') {
            checkLastStatus = true
        } else {
            checkLastStatus = false
201 202
        }

d.arizona's avatar
d.arizona committed
203 204 205 206 207
        if (this.props.prevRevision) {
            checkPrevRev = true
        } else {
            checkPrevRev = false
        }
208

d.arizona's avatar
d.arizona committed
209 210 211 212 213 214
        if (this.props.status === 'revision' || this.props.status === 'not-yet' || this.props.status === 'draft' || this.props.status === 'submitted') {
            checkStatus = true
        } else {
            checkStatus = false
        }

215
        this.setState({ viewOnly: !checkApprover && checkLastStatus && checkStatus && checkPrevRev })
d.arizona's avatar
d.arizona committed
216
        // this.setState({viewOnly: true})
d.arizona's avatar
d.arizona committed
217 218
    }

d.arizona's avatar
d.arizona committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232
    getLatestUpdate() {
        let payload = {
            "report_id": this.props.report_id,
            "revision": Number(this.props.revision),
            "periode": this.props.periode,
            "company_id": this.props.company.company_id,
            "monthly_report_id": this.props.monthlyReportId,
            "months": this.props.month.month_id
        }
        // console.log(payload)
        api.create().getLastestUpdateMR(payload).then(response => {
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({
faisalhamdi's avatar
faisalhamdi committed
233
                        updateBy: response.data.data.detail === null ? [] : response.data.data.detail,
d.arizona's avatar
d.arizona committed
234 235 236 237
                        notes: response.data.data.notes_update === null ? "" : response.data.data.notes_update
                    })
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, typeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
238
                        if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
d.arizona's avatar
d.arizona committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252
                            setTimeout(() => {
                                localStorage.removeItem(Constant.TOKEN)
                                window.location.reload();
                            }, 1000);
                        }
                    })
                }
            } else {
                // console.log('brrrrrrrr')
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
            }
        })
    }

d.arizona's avatar
d.arizona committed
253

254

d.arizona's avatar
d.arizona committed
255
    deleteReport() {
256
        let payload = { "item_report_id": this.state.dataDelete, "periode": this.props.periode, "months": this.props.month.month_id }
d.arizona's avatar
d.arizona committed
257 258 259 260 261

        if (this.state.dataDelete.length > 0) {
            api.create().deleteAllItemReportLOCF(payload).then((response) => {
                console.log(response)
            })
262
        }
d.arizona's avatar
d.arizona committed
263 264
    }

Riri Novita's avatar
Riri Novita committed
265 266
    getSubmission() {
        this.setState({ loading: true })
267
        let payload = {
Riri Novita's avatar
Riri Novita committed
268 269 270
            "company_id": this.props.company.company_id,
            "periode": this.props.periode,
            "is_approver": true
271
        }
Riri Novita's avatar
Riri Novita committed
272
        api.create().getSubmission(payload).then(response => {
d.arizona's avatar
d.arizona committed
273
            console.log(response)
Riri Novita's avatar
Riri Novita committed
274 275 276 277 278 279 280
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({
                        submissionID: response.data.data.submission_id,
                        lastRevision: response.data.data.last_revision,
                    }, () => {
                        // this.getDataRatio()
Riri Novita's avatar
Riri Novita committed
281

Riri Novita's avatar
Riri Novita committed
282 283
                    })
                } else {
Riri Novita's avatar
Riri Novita committed
284
                    this.setState({ submissionID: null, loading: false })
Riri Novita's avatar
Riri Novita committed
285 286
                }
            }
d.arizona's avatar
d.arizona committed
287
        })
Riri Novita's avatar
Riri Novita committed
288
    }
d.arizona's avatar
d.arizona committed
289

290
    backToMonthlyReportLOCF(type) {
Riri Novita's avatar
Riri Novita committed
291
        console.log('masoook LOCF');
Riri Novita's avatar
Riri Novita committed
292
        let dataTable2 = (this.state.dataTablelocf !== undefined && this.state.tambah == 'upload') ? this.state.dataTablelocf : (this.state.dataTablelocf == undefined || this.state.tambah == 'tambah' || this.state.tambah == 'upload') ? this.state.dataTableLOCF : this.state.dataTablelocf
d.arizona's avatar
d.arizona committed
293
        let data = []
d.arizona's avatar
d.arizona committed
294
        let error = false
Riri Novita's avatar
Riri Novita committed
295 296 297
        // this.deleteReport()
        console.log(dataTable2);
        dataTable2.map(i => {
d.arizona's avatar
d.arizona committed
298
            if (i[0] == 3) {
Riri Novita's avatar
Riri Novita committed
299
                if (i[6] == null || i[7] == null || i[8] == "" || i[10] == "" || i[11] == "" || i[12] == "") {
d.arizona's avatar
d.arizona committed
300 301
                    error = true
                }
Riri Novita's avatar
Riri Novita committed
302

Riri Novita's avatar
Riri Novita committed
303
                if (i[7].value == 'Others' && i[19] == '') {
d.arizona's avatar
d.arizona committed
304 305
                    error = true
                }
Riri Novita's avatar
Riri Novita committed
306
                let tgl = String(i[10]).split('-')
d.arizona's avatar
d.arizona committed
307
                let checkUndifined = tgl.findIndex((val) => val == undefined)
308 309 310 311 312 313 314
                if (this.props.defaultCurrency.id == 2) {
                    data.push({
                        "item_report_id": i[1],
                        "borrower_comp_name": i[5],
                        "bank_name": i[6] == null ? [6] : i[6].value,
                        "type_of_credit": i[7] == null ? i[7] : i[7].value,
                        "remarks": i[8],
Riri Novita's avatar
Riri Novita committed
315
                        "remarks2": i[9] == null ? i[9] : i[9].value,
Riri Novita's avatar
Riri Novita committed
316
                        // "loan_maturity_date": i[9],
Riri Novita's avatar
Riri Novita committed
317
                        "loan_maturity_date": i[10] == undefined || i[10] == "null" || i[10] == null ? "" : (String(tgl[2]).length <= 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[10])),
Riri Novita's avatar
Riri Novita committed
318
                        // "loan_maturity_date":  i[9] !== undefined || i[9] !== "null" || i[9] !== null? (String(tgl[2]).length <= 2? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[9])) : "",
Riri Novita's avatar
Riri Novita committed
319 320 321 322 323 324 325 326
                        "interest": i[11] == "" ? "0.00" : i[11],
                        "currency": i[12],
                        "loan_plafond_amount_ori": Number(i[13]) == "" ? "0.0" : Number(i[13]),
                        "loan_plafond_amount_idr": Number(i[14]) == "" ? "0.0" : Number(i[14]),
                        "out_loan_ki_amount_ori": Number(i[15]) == "" ? "0.0" : Number(i[15]),
                        "out_loan_ki_amount_idr": Number(i[16]) == "" ? "0.0" : Number(i[16]),
                        "out_loan_kmk_amount_ori": Number(i[17]) == "" ? "0.0" : Number(i[17]),
                        "out_loan_kmk_amount_idr": Number(i[18]) == "" ? "0.0" : Number(i[18]),
327
                        // "mtd_vs_previous_month": i[18],
Riri Novita's avatar
Riri Novita committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
                        "out_loan_other_type": i[19],
                        "out_loan_other_amount_ori": Number(i[20]) == "" ? "0.0" : Number(i[20]),
                        "out_loan_other_amount_idr": Number(i[21]) == "" ? "0.0" : Number(i[21]),
                        "total_out_loan_ori": Number(i[22]) == "" ? "0.0" : Number(i[22]),
                        "total_out_loan_idr": Number(i[23]) == "" ? "0.0" : Number(i[23]),
                        "remaining_plafond_ori": Number(i[24]) == "" ? "0.0" : Number(i[24]),
                        "remaining_plafond_idr": Number(i[25]) == "" ? "0.0" : Number(i[25]),
                        "current_ratio_financial": Number(i[26]) == "" ? "0.00" : Number(i[26]),
                        "current_ratio_current": Number(i[27]) == "" ? "0.00" : Number(i[27]),
                        "der_financial": Number(i[28]) == "" ? "0.00" : Number(i[28]),
                        "der_current": Number(i[29]) == "" ? "0.00" : Number(i[29]),
                        "debt_to_ebitda_financial": Number(i[30]) == "" ? "0.00" : Number(i[30]),
                        "debt_to_ebitda_current": Number(i[31]) == "" ? "0.00" : Number(i[31]),
                        "ebitda_to_interest_financial": Number(i[32]) == "" ? "0.00" : Number(i[32]),
                        "ebitda_to_interest_current": Number(i[33]) == "" ? "0.00" : Number(i[33]),
                        "other_ratio1_ratio_name": i[34],
                        "other_ratio1_financial": Number(i[35]) == "" ? "0.00" : Number(i[35]),
                        "other_ratio1_current": Number(i[36]) == "" ? "0.00" : Number(i[36]),
                        "other_ratio2_ratio_name": i[37],
                        "other_ratio2_financial": Number(i[38]) == "" ? "0.00" : Number(i[38]),
                        "other_ratio2_current": Number(i[39]) == "" ? "0.00" : Number(i[39]),
                        "other_ratio3_ratio_name": i[40],
                        "other_ratio3_financial": Number(i[41]) == "" ? "0.00" : Number(i[41]),
                        "other_ratio3_current": Number(i[42]) == "" ? "0.00" : Number(i[42]),
                        "other_ratio4_ratio_name": i[43],
                        "other_ratio4_financial": Number(i[44]) == "" ? "0.00" : Number(i[44]),
                        "other_ratio4_current": Number(i[45]) == "" ? "0.00" : Number(i[45]),
                        "notes": i[46],
356 357 358 359 360 361 362 363
                    })
                } else {
                    data.push({
                        "item_report_id": i[1],
                        "borrower_comp_name": i[5],
                        "bank_name": i[6] == null ? [6] : i[6].value,
                        "type_of_credit": i[7] == null ? i[7] : i[7].value,
                        "remarks": i[8],
Riri Novita's avatar
Riri Novita committed
364
                        "remarks2": i[9] == null ? i[9] : i[9].value,
Riri Novita's avatar
Riri Novita committed
365
                        // "loan_maturity_date": i[9],
Riri Novita's avatar
Riri Novita committed
366
                        "loan_maturity_date": i[10] == undefined || i[10] == "null" || i[10] == null ? "" : (String(tgl[2]).length <= 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[10])),
Riri Novita's avatar
Riri Novita committed
367
                        // "loan_maturity_date":  i[9] !== undefined || i[9] !== "null" || i[9] !== null? (String(tgl[2]).length <= 2? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[9])) : "",
Riri Novita's avatar
Riri Novita committed
368 369 370 371 372 373 374 375
                        "interest": i[11] == "" ? "0.00" : i[11],
                        "currency": i[12],
                        "loan_plafond_amount_ori": Number(i[13]) == "" ? "0.0" : Number(i[13]),
                        "loan_plafond_amount_idr": Number(i[14]) == "" ? "0.0" : Number(i[14]),
                        "out_loan_ki_amount_ori": Number(i[15]) == "" ? "0.0" : Number(i[15]),
                        "out_loan_ki_amount_idr": Number(i[16]) == "" ? "0.0" : Number(i[16]),
                        "out_loan_kmk_amount_ori": Number(i[17]) == "" ? "0.0" : Number(i[17]),
                        "out_loan_kmk_amount_idr": Number(i[18]) == "" ? "0.0" : Number(i[18]),
376
                        // "mtd_vs_previous_month": i[18],
Riri Novita's avatar
Riri Novita committed
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
                        "out_loan_other_type": i[19],
                        "out_loan_other_amount_ori": Number(i[20]) == "" ? "0.0" : Number(i[20]),
                        "out_loan_other_amount_idr": Number(i[21]) == "" ? "0.0" : Number(i[21]),
                        "total_out_loan_ori": Number(i[22]) == "" ? "0.0" : Number(i[22]),
                        "total_out_loan_idr": Number(i[23]) == "" ? "0.0" : Number(i[23]),
                        "remaining_plafond_ori": Number(i[24]) == "" ? "0.0" : Number(i[24]),
                        "remaining_plafond_idr": Number(i[25]) == "" ? "0.0" : Number(i[25]),
                        "current_ratio_financial": Number(i[26]) == "" ? "0.00" : Number(i[26]),
                        "current_ratio_current": Number(i[27]) == "" ? "0.00" : Number(i[27]),
                        "der_financial": Number(i[28]) == "" ? "0.00" : Number(i[28]),
                        "der_current": Number(i[29]) == "" ? "0.00" : Number(i[29]),
                        "debt_to_ebitda_financial": Number(i[30]) == "" ? "0.00" : Number(i[30]),
                        "debt_to_ebitda_current": Number(i[31]) == "" ? "0.00" : Number(i[31]),
                        "ebitda_to_interest_financial": Number(i[32]) == "" ? "0.00" : Number(i[32]),
                        "ebitda_to_interest_current": Number(i[33]) == "" ? "0.00" : Number(i[33]),
                        "other_ratio1_ratio_name": i[34],
                        "other_ratio1_financial": Number(i[35]) == "" ? "0.00" : Number(i[35]),
                        "other_ratio1_current": Number(i[36]) == "" ? "0.00" : Number(i[36]),
                        "other_ratio2_ratio_name": i[37],
                        "other_ratio2_financial": Number(i[38]) == "" ? "0.00" : Number(i[38]),
                        "other_ratio2_current": Number(i[39]) == "" ? "0.00" : Number(i[39]),
                        "other_ratio3_ratio_name": i[40],
                        "other_ratio3_financial": Number(i[41]) == "" ? "0.00" : Number(i[41]),
                        "other_ratio3_current": Number(i[42]) == "" ? "0.00" : Number(i[42]),
                        "other_ratio4_ratio_name": i[43],
                        "other_ratio4_financial": Number(i[44]) == "" ? "0.00" : Number(i[44]),
                        "other_ratio4_current": Number(i[45]) == "" ? "0.00" : Number(i[45]),
                        "notes": i[46],
405 406 407
                    })
                }

d.arizona's avatar
d.arizona committed
408 409
            }
        })
Riri Novita's avatar
Riri Novita committed
410
        let body = {
d.arizona's avatar
d.arizona committed
411 412 413 414 415 416
            "monthly_report_id": this.props.monthlyReportId,
            "company_id": this.props.company.company_id,
            "periode": this.props.periode,
            "report_id": this.props.report_id,
            "status": type,
            "months": this.props.month.month_id,
417
            "currency_id": this.props.defaultCurrency.id,
d.arizona's avatar
d.arizona committed
418
            "locf": data,
Riri Novita's avatar
Riri Novita committed
419 420 421
            "per_bs": this.state.perBSLOCF,
            "diff": this.state.diffLOCF,
            "total_loan": this.state.totalLoanLOCF
Riri Novita's avatar
Riri Novita committed
422 423
        }
        console.log(body);
Riri Novita's avatar
Riri Novita committed
424
        console.log(error);
Riri Novita's avatar
Riri Novita committed
425
        if (error && type == 'submitted') {
Riri Novita's avatar
Riri Novita committed
426
            this.setState({ handleDoubleClick: 0, saveDraft: false, saveComp: true, loadingChild: false, snekbar: true, snekbarMsg: 'Data Incomplete', handleDoubleClick: 0 })
Riri Novita's avatar
Riri Novita committed
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
        } else {
            api.create('UPLOAD').createMonthlyReportLOCF(body).then(response => {
                console.log(response);
                if (response.data) {
                    if (response.ok) {
                        if (response.data.status === "success") {
                            this.backToMonthlyReportLOV(type)
                        } else {
                            if (response.data?.message == "Please Set Up Rate Currency First") {
                                this.setState({ visibleAlertSave: true })
                            } else {
                                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                        setTimeout(() => {
                                            localStorage.removeItem(Constant.TOKEN)
                                            window.location.reload();
                                        }, 1000);
                                    }
                                })
                            }
                            // alert(response.data.status)
                        }
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false, handleDoubleClick: 0 })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false, handleDoubleClick: 0 })
                }
                this.setState({ handleDoubleClick: 0 })
            })
d.arizona's avatar
d.arizona committed
457
        }
Riri Novita's avatar
Riri Novita committed
458
    }
Riri Novita's avatar
Riri Novita committed
459

Riri Novita's avatar
Riri Novita committed
460 461
    backToMonthlyReportLOV(type) {
        console.log('masoook LOV');
Riri Novita's avatar
Riri Novita committed
462
        let dataTable2 = []
Riri Novita's avatar
Riri Novita committed
463 464 465
        let data = []
        let error = false
        // this.deleteReport()
Riri Novita's avatar
Riri Novita committed
466 467 468 469 470 471 472 473 474 475 476 477
        if (this.state.dataTablelov !== undefined && this.state.tambahLOV == undefined) {
            dataTable2 = this.state.dataTablelov
        } else {
            dataTable2 = this.state.dataTableLOV
            this.setState({ updateTambah: true, updateData: false })
            if (this.state.tambahLOV = 'tambah' && this.state.updateData == false) {
                dataTable2 = this.state.dataTablelov
            } else {
                dataTable2 = this.state.dataTableLOV
            }

        }
Riri Novita's avatar
Riri Novita committed
478 479 480
        console.log(dataTable2);
        dataTable2.map(i => {
            if (i[0] == 3) {
Riri Novita's avatar
Riri Novita committed
481 482
                if (i[6] == null || i[7] == null || i[9] == "" || i[10] == "" || i[11] == "" || i[12] == "") {
                    console.log('masuk sini');
Riri Novita's avatar
Riri Novita committed
483 484
                    error = true
                }
Riri Novita's avatar
Riri Novita committed
485
                console.log(i[7]?.value);
Riri Novita's avatar
Riri Novita committed
486

487
                if ((i[7].value == 'Government bonds' && i[8] == '') || (i[7].value == 'Stocks' && i[8] == '') || (i[7].value == 'Mutual funds' && i[8] == '') || (i[7].value == 'Investment in associate' && i[8] == '') || (i[7].value == 'Investment in joint venture' && i[8] == '') || (i[7].value == 'Investment in subsidiary' && i[8] == '') || (i[7].value == 'Corporate bonds' && i[8] == '') || (i[7].value == 'Others' && i[8] == '')) {
Riri Novita's avatar
Riri Novita committed
488
                    error = true
489 490
                } else {
                    error = false
Riri Novita's avatar
Riri Novita committed
491 492 493 494 495 496 497 498 499 500 501 502 503
                }
                let tgl = String(i[9]).split('-')
                let checkUndifined = tgl.findIndex((val) => val == undefined)
                if (this.props.defaultCurrency.id == 2) {
                    data.push({
                        "item_report_id": i[1],
                        "company_name": i[5],
                        "institution_name": i[6],
                        "type_of_investment": i[7] == null ? i[7] : i[7].value,
                        "remarks": i[8],
                        "placement_date": i[9] == undefined || i[9] == "null" || i[9] == null ? "" : (String(tgl[2]).length <= 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[9])),
                        "tenor": i[10],
                        "expected_return": i[11] == "" ? "0.00" : i[11],
Riri Novita's avatar
Riri Novita committed
504 505
                        // "currency": i[12] == null ? i[12] : i[12].value,
                        "currency": i[12],
Riri Novita's avatar
Riri Novita committed
506 507 508 509 510 511 512 513 514 515 516 517 518 519
                        "investment_amount_ori": Number(i[13]) == "" ? "0.0" : Number(i[13]),
                        "investment_amount_cur": Number(i[14]) == "" ? "0.0" : Number(i[14]),
                        "notes": i[15],
                    })
                } else {
                    data.push({
                        "item_report_id": i[1],
                        "company_name": i[5],
                        "institution_name": i[6],
                        "type_of_investment": i[7] == null ? i[7] : i[7].value,
                        "remarks": i[8],
                        "placement_date": i[9] == undefined || i[9] == "null" || i[9] == null ? "" : (String(tgl[2]).length <= 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[9])),
                        "tenor": i[10],
                        "expected_return": i[11] == "" ? "0.00" : i[11],
Riri Novita's avatar
Riri Novita committed
520 521
                        // "currency": i[12] == null ? i[12] : i[12].value,
                        "currency": i[12],
Riri Novita's avatar
Riri Novita committed
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
                        "investment_amount_ori": Number(i[13]) == "" ? "0.0" : Number(i[13]),
                        "investment_amount_cur": Number(i[14]) == "" ? "0.0" : Number(i[14]),
                        "notes": i[15],
                    })
                }

            }
        })
        let body = {
            "monthly_report_id": this.props.monthlyReportId,
            "company_id": this.props.company.company_id,
            "periode": this.props.periode,
            "report_id": this.props.report_id,
            "status": type,
            "months": this.props.month.month_id,
            "currency_id": this.props.defaultCurrency.id,
            "lov": data,
Riri Novita's avatar
Riri Novita committed
539 540 541
            "per_bs": this.state.perBSLOV,
            "diff": this.state.diffLOV,
            "total_loan": this.state.totalLoanLOV
Riri Novita's avatar
Riri Novita committed
542 543
        }
        console.log(body);
Riri Novita's avatar
Riri Novita committed
544
        console.log(error);
Riri Novita's avatar
Riri Novita committed
545
        if (error && type == 'submitted') {
Riri Novita's avatar
Riri Novita committed
546
            this.setState({ handleDoubleClick: 0, saveDraft: false, saveComp: true, loadingChild: false, snekbar: true, snekbarMsg: 'Data Incomplete', handleDoubleClick: 0 })
Riri Novita's avatar
Riri Novita committed
547 548 549 550 551 552 553
        } else {
            api.create('UPLOAD').createMonthlyReportLOV(body).then(response => {
                console.log(response);
                if (response.data) {
                    if (response.ok) {
                        if (response.data.status === "success") {
                            this.props.saveToMonthlyReport('LOCF')
Riri Novita's avatar
Riri Novita committed
554
                            this.setState({ loadingChild: false })
Riri Novita's avatar
Riri Novita committed
555 556 557 558
                        } else {
                            if (response.data?.message == "Please Set Up Rate Currency First") {
                                this.setState({ visibleAlertSave: true })
                            } else {
Riri Novita's avatar
Riri Novita committed
559
                                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loadingChild: false }, () => {
Riri Novita's avatar
Riri Novita committed
560 561 562 563 564 565 566 567 568 569 570
                                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                        setTimeout(() => {
                                            localStorage.removeItem(Constant.TOKEN)
                                            window.location.reload();
                                        }, 1000);
                                    }
                                })
                            }
                            // alert(response.data.status)
                        }
                    } else {
Riri Novita's avatar
Riri Novita committed
571
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loadingChild: false, handleDoubleClick: 0 })
Riri Novita's avatar
Riri Novita committed
572 573
                    }
                } else {
Riri Novita's avatar
Riri Novita committed
574 575
                    console.log(response.problem);
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loadingChild: false, handleDoubleClick: 0 })
Riri Novita's avatar
Riri Novita committed
576 577 578 579
                }
                this.setState({ handleDoubleClick: 0 })
            })
        }
d.arizona's avatar
d.arizona committed
580 581
    }

Riri Novita's avatar
Riri Novita committed
582
    handleCalculateLOCF = () => {
Riri Novita's avatar
Riri Novita committed
583
        this.setState({ loading: true })
Riri Novita's avatar
Riri Novita committed
584 585 586 587
        // console.log(this.state.dataTableLOCF);
        // console.log(this.state.dataTablelocf);
        // console.log(this.state.tambah);
        let dataTable2 = (this.state.dataTablelocf !== undefined && this.state.tambah == 'upload') ? this.state.dataTablelocf : (this.state.dataTablelocf == undefined || this.state.tambah == 'tambah' || this.state.tambah == 'upload') ? this.state.dataTableLOCF : this.state.dataTablelocf
Riri Novita's avatar
Riri Novita committed
588 589
        let data = []
        let error = false
Riri Novita's avatar
Riri Novita committed
590
        let bankNameEmpty = false
Riri Novita's avatar
Riri Novita committed
591
        console.log(dataTable2);
Riri Novita's avatar
Riri Novita committed
592
        dataTable2.map(i => {
Riri Novita's avatar
Riri Novita committed
593 594 595
            if (i[6] == null) {
                bankNameEmpty = true
            }
Riri Novita's avatar
Riri Novita committed
596
            if (i[0] == 3) {
Riri Novita's avatar
Riri Novita committed
597
                if (i[6] == null || i[7] == null || i[8] == "" || i[10] == "" || i[11] == "" || i[12] == "") {
Riri Novita's avatar
Riri Novita committed
598 599
                    error = true
                }
d.arizona's avatar
d.arizona committed
600

Riri Novita's avatar
Riri Novita committed
601 602
                if (i[7].value == 'Others' && i[18] == '') {
                    error = true
d.arizona's avatar
d.arizona committed
603
                }
Riri Novita's avatar
Riri Novita committed
604
                let tgl = String(i[10]).split('-')
Riri Novita's avatar
Riri Novita committed
605 606 607 608 609 610 611 612
                let checkUndifined = tgl.findIndex((val) => val == undefined)
                if (this.props.defaultCurrency.id == 2) {
                    data.push({
                        "item_report_id": i[1],
                        "borrower_comp_name": i[5],
                        "bank_name": i[6] == null ? [6] : i[6].value,
                        "type_of_credit": i[7] == null ? i[7] : i[7].value,
                        "remarks": i[8],
Riri Novita's avatar
Riri Novita committed
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
                        "remarks2": i[9] == null ? i[9] : i[9].value,
                        // "loan_maturity_date": i[9],
                        "loan_maturity_date": i[10] == undefined || i[10] == "null" || i[10] == null ? "" : (String(tgl[2]).length <= 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[10])),
                        // "loan_maturity_date":  i[9] !== undefined || i[9] !== "null" || i[9] !== null? (String(tgl[2]).length <= 2? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[9])) : "",
                        "interest": i[11] == "" ? "0.00" : i[11],
                        "currency": i[12],
                        "loan_plafond_amount_ori": Number(i[13]) == "" ? "0.0" : Number(i[13]),
                        "loan_plafond_amount_idr": Number(i[14]) == "" ? "0.0" : Number(i[14]),
                        "out_loan_ki_amount_ori": Number(i[15]) == "" ? "0.0" : Number(i[15]),
                        "out_loan_ki_amount_idr": Number(i[16]) == "" ? "0.0" : Number(i[16]),
                        "out_loan_kmk_amount_ori": Number(i[17]) == "" ? "0.0" : Number(i[17]),
                        "out_loan_kmk_amount_idr": Number(i[18]) == "" ? "0.0" : Number(i[18]),
                        // "mtd_vs_previous_month": i[18],
                        "out_loan_other_type": i[19],
                        "out_loan_other_amount_ori": Number(i[20]) == "" ? "0.0" : Number(i[20]),
                        "out_loan_other_amount_idr": Number(i[21]) == "" ? "0.0" : Number(i[21]),
                        "total_out_loan_ori": Number(i[22]) == "" ? "0.0" : Number(i[22]),
                        "total_out_loan_idr": Number(i[23]) == "" ? "0.0" : Number(i[23]),
                        "remaining_plafond_ori": Number(i[24]) == "" ? "0.0" : Number(i[24]),
                        "remaining_plafond_idr": Number(i[25]) == "" ? "0.0" : Number(i[25]),
                        "current_ratio_financial": Number(i[26]) == "" ? "0.00" : Number(i[26]),
                        "current_ratio_current": Number(i[27]) == "" ? "0.00" : Number(i[27]),
                        "der_financial": Number(i[28]) == "" ? "0.00" : Number(i[28]),
                        "der_current": Number(i[29]) == "" ? "0.00" : Number(i[29]),
                        "debt_to_ebitda_financial": Number(i[30]) == "" ? "0.00" : Number(i[30]),
                        "debt_to_ebitda_current": Number(i[31]) == "" ? "0.00" : Number(i[31]),
                        "ebitda_to_interest_financial": Number(i[32]) == "" ? "0.00" : Number(i[32]),
                        "ebitda_to_interest_current": Number(i[33]) == "" ? "0.00" : Number(i[33]),
                        "other_ratio1_ratio_name": i[34],
                        "other_ratio1_financial": Number(i[35]) == "" ? "0.00" : Number(i[35]),
                        "other_ratio1_current": Number(i[36]) == "" ? "0.00" : Number(i[36]),
                        "other_ratio2_ratio_name": i[37],
                        "other_ratio2_financial": Number(i[38]) == "" ? "0.00" : Number(i[38]),
                        "other_ratio2_current": Number(i[39]) == "" ? "0.00" : Number(i[39]),
                        "other_ratio3_ratio_name": i[40],
                        "other_ratio3_financial": Number(i[41]) == "" ? "0.00" : Number(i[41]),
                        "other_ratio3_current": Number(i[42]) == "" ? "0.00" : Number(i[42]),
                        "other_ratio4_ratio_name": i[43],
                        "other_ratio4_financial": Number(i[44]) == "" ? "0.00" : Number(i[44]),
                        "other_ratio4_current": Number(i[45]) == "" ? "0.00" : Number(i[45]),
                        "notes": i[46],
d.arizona's avatar
d.arizona committed
654
                    })
Riri Novita's avatar
Riri Novita committed
655 656 657 658 659 660 661
                } else {
                    data.push({
                        "item_report_id": i[1],
                        "borrower_comp_name": i[5],
                        "bank_name": i[6] == null ? [6] : i[6].value,
                        "type_of_credit": i[7] == null ? i[7] : i[7].value,
                        "remarks": i[8],
Riri Novita's avatar
Riri Novita committed
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
                        "remarks2": i[9] == null ? i[9] : i[9].value,
                        // "loan_maturity_date": i[9],
                        "loan_maturity_date": i[10] == undefined || i[10] == "null" || i[10] == null ? "" : (String(tgl[2]).length <= 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[10])),
                        // "loan_maturity_date":  i[9] !== undefined || i[9] !== "null" || i[9] !== null? (String(tgl[2]).length <= 2? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[9])) : "",
                        "interest": i[11] == "" ? "0.00" : i[11],
                        "currency": i[12],
                        "loan_plafond_amount_ori": Number(i[13]) == "" ? "0.0" : Number(i[13]),
                        "loan_plafond_amount_idr": Number(i[14]) == "" ? "0.0" : Number(i[14]),
                        "out_loan_ki_amount_ori": Number(i[15]) == "" ? "0.0" : Number(i[15]),
                        "out_loan_ki_amount_idr": Number(i[16]) == "" ? "0.0" : Number(i[16]),
                        "out_loan_kmk_amount_ori": Number(i[17]) == "" ? "0.0" : Number(i[17]),
                        "out_loan_kmk_amount_idr": Number(i[18]) == "" ? "0.0" : Number(i[18]),
                        // "mtd_vs_previous_month": i[18],
                        "out_loan_other_type": i[19],
                        "out_loan_other_amount_ori": Number(i[20]) == "" ? "0.0" : Number(i[20]),
                        "out_loan_other_amount_idr": Number(i[21]) == "" ? "0.0" : Number(i[21]),
                        "total_out_loan_ori": Number(i[22]) == "" ? "0.0" : Number(i[22]),
                        "total_out_loan_idr": Number(i[23]) == "" ? "0.0" : Number(i[23]),
                        "remaining_plafond_ori": Number(i[24]) == "" ? "0.0" : Number(i[24]),
                        "remaining_plafond_idr": Number(i[25]) == "" ? "0.0" : Number(i[25]),
                        "current_ratio_financial": Number(i[26]) == "" ? "0.00" : Number(i[26]),
                        "current_ratio_current": Number(i[27]) == "" ? "0.00" : Number(i[27]),
                        "der_financial": Number(i[28]) == "" ? "0.00" : Number(i[28]),
                        "der_current": Number(i[29]) == "" ? "0.00" : Number(i[29]),
                        "debt_to_ebitda_financial": Number(i[30]) == "" ? "0.00" : Number(i[30]),
                        "debt_to_ebitda_current": Number(i[31]) == "" ? "0.00" : Number(i[31]),
                        "ebitda_to_interest_financial": Number(i[32]) == "" ? "0.00" : Number(i[32]),
                        "ebitda_to_interest_current": Number(i[33]) == "" ? "0.00" : Number(i[33]),
                        "other_ratio1_ratio_name": i[34],
                        "other_ratio1_financial": Number(i[35]) == "" ? "0.00" : Number(i[35]),
                        "other_ratio1_current": Number(i[36]) == "" ? "0.00" : Number(i[36]),
                        "other_ratio2_ratio_name": i[37],
                        "other_ratio2_financial": Number(i[38]) == "" ? "0.00" : Number(i[38]),
                        "other_ratio2_current": Number(i[39]) == "" ? "0.00" : Number(i[39]),
                        "other_ratio3_ratio_name": i[40],
                        "other_ratio3_financial": Number(i[41]) == "" ? "0.00" : Number(i[41]),
                        "other_ratio3_current": Number(i[42]) == "" ? "0.00" : Number(i[42]),
                        "other_ratio4_ratio_name": i[43],
                        "other_ratio4_financial": Number(i[44]) == "" ? "0.00" : Number(i[44]),
                        "other_ratio4_current": Number(i[45]) == "" ? "0.00" : Number(i[45]),
                        "notes": i[46],
Riri Novita's avatar
Riri Novita committed
703 704
                    })
                }
705

Riri Novita's avatar
Riri Novita committed
706 707 708 709 710 711 712 713 714 715 716
            }
        })
        let body = {
            "monthly_report_id": this.props.monthlyReportId,
            "company_id": this.props.company.company_id,
            "periode": this.props.periode,
            "report_id": this.props.report_id,
            "status": 'submitted',
            "months": this.props.month.month_id,
            "currency_id": this.props.defaultCurrency.id,
            "locf": data,
Riri Novita's avatar
Riri Novita committed
717 718
            "per_bs": this.state.perBSLOCF,
            "diff": this.state.diffLOCF,
Riri Novita's avatar
Riri Novita committed
719
            "total_loan": this.state.totalLoanLOCF
Riri Novita's avatar
Riri Novita committed
720 721 722 723 724 725
        }
        console.log(body);
        api.create().validateSaveLOCF(body).then((response) => {
            console.log(response);
            let dataTablelocf = []
            if (response.data) {
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
                if (response.data.status == 'success') {

                    let res = response.data.data
                    const handlePushChild = (item) => {
                        let indexIDzz = dataTablelocf.findIndex((val) => val[1] === item.id)
                        let tgl = String(item.locf.loan_maturity_date).split('-')
                        if (indexIDzz === -1) {
                            dataTablelocf.push([
                                item.type_report_id,
                                item.id,
                                item.parent,
                                item.formula,
                                item.level,
                                String(item.locf.bank_name).includes('Total') ? null : item.locf.borrower_comp_name === null || item.locf.borrower_comp_name === "" ? this.props.company.company_name : item.locf.borrower_comp_name,
                                item.locf.bank_name === null ? null : item.locf.bank_name === "" ? null : { value: item.locf.bank_name },
                                item.locf.type_of_credit === null ? null : item.locf.type_of_credit === "" ? null : { value: item.locf.type_of_credit },
                                item.locf.remarks === null || item.locf.remarks === "" ? "" : item.locf.remarks,
                                item.locf.remarks2 === null ? null : item.locf.remarks2 === "" ? null : { value: item.locf.remarks2 },
                                item.locf.loan_maturity_date == null || item.locf.loan_maturity_date == "" ? null : (item.locf.loan_maturity_date !== "null" ? String(tgl[2]).length > 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(item.locf.loan_maturity_date) : null),
                                item.locf.interest === null || item.locf.interest === "" ? "0.00" : item.locf.interest,
                                item.locf.currency === null || item.locf.currency === "" ? "" : item.locf.currency,
                                item.locf.loan_plafond_amount_ori,
                                item.locf.loan_plafond_amount_idr === null ? "0.0" : item.locf.loan_plafond_amount_idr === "" ? "0.0" : item.locf.loan_plafond_amount_idr,
                                item.locf.out_loan_ki_amount_ori,
                                item.locf.out_loan_ki_amount_idr === null ? "0.0" : item.locf.out_loan_ki_amount_idr === "" ? "0.0" : item.locf.out_loan_ki_amount_idr,
                                item.locf.out_loan_kmk_amount_ori,
                                item.locf.out_loan_kmk_amount_idr === null ? "0.0" : item.locf.out_loan_kmk_amount_idr === "" ? "0.0" : item.locf.out_loan_kmk_amount_idr,
                                item.locf.out_loan_other_type,
                                item.locf.out_loan_other_amount_ori,
                                item.locf.out_loan_other_amount_idr === null ? "0.0" : item.locf.out_loan_other_amount_idr === "" ? "0.0" : item.locf.out_loan_other_amount_idr,
                                item.locf.total_out_loan_ori === null ? "0.0" : item.locf.total_out_loan_ori === "" ? "0.0" : item.locf.total_out_loan_ori,
                                item.locf.total_out_loan_idr === null ? "0.0" : item.locf.total_out_loan_idr === "" ? "0.0" : item.locf.total_out_loan_idr,
                                item.locf.remaining_plafond_ori === null ? "0.0" : item.locf.remaining_plafond_ori === "" ? "0.0" : item.locf.remaining_plafond_ori,
                                item.locf.remaining_plafond_idr === null ? "0.0" : item.locf.remaining_plafond_idr === "" ? "0.0" : item.locf.remaining_plafond_idr,
                                item.locf.current_ratio_financial,
                                item.locf.current_ratio_current === null ? "0.0" : item.locf.current_ratio_current === "" ? "0.0" : item.locf.current_ratio_current,
                                item.locf.der_financial,
                                item.locf.der_current === null ? "0.0" : item.locf.der_current === "" ? "0.0" : item.locf.der_current,
                                item.locf.debt_to_ebitda_financial,
                                item.locf.debt_to_ebitda_current === null ? "0.0" : item.locf.debt_to_ebitda_current === "" ? "0.0" : item.locf.debt_to_ebitda_current,
                                item.locf.ebitda_to_interest_financial,
                                item.locf.ebitda_to_interest_current === null ? "0.0" : item.locf.ebitda_to_interest_current === "" ? "0.0" : item.locf.ebitda_to_interest_current,
                                item.locf.other_ratio1_ratio_name,
                                item.locf.other_ratio1_financial,
                                item.locf.other_ratio1_current === null ? "0.0" : item.locf.other_ratio1_current === "" ? "0.0" : item.locf.other_ratio1_current,
                                item.locf.other_ratio2_ratio_name,
                                item.locf.other_ratio2_financial,
                                item.locf.other_ratio2_current === null ? "0.0" : item.locf.other_ratio2_current === "" ? "0.0" : item.locf.other_ratio2_current,
                                item.locf.other_ratio3_ratio_name,
                                item.locf.other_ratio3_financial,
                                item.locf.other_ratio3_current === null ? "0.0" : item.locf.other_ratio3_current === "" ? "0.0" : item.locf.other_ratio3_current,
                                item.locf.other_ratio4_ratio_name,
                                item.locf.other_ratio4_financial,
                                item.locf.other_ratio4_current === null ? "0.0" : item.locf.other_ratio4_current === "" ? "0.0" : item.locf.other_ratio4_current,
                                item.locf.notes,
                                item.diff,
                                item.total_loan,
                                item.per_bs
                                // index
                            ])
                        }
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
                        }
                    }
                    res.map((item, index) => {
                        let tgl = String(item.locf.loan_maturity_date).split('-')
Riri Novita's avatar
Riri Novita committed
797 798 799 800 801 802 803 804 805 806
                        dataTablelocf.push([
                            item.type_report_id,
                            item.id,
                            item.parent,
                            item.formula,
                            item.level,
                            String(item.locf.bank_name).includes('Total') ? null : item.locf.borrower_comp_name === null || item.locf.borrower_comp_name === "" ? this.props.company.company_name : item.locf.borrower_comp_name,
                            item.locf.bank_name === null ? null : item.locf.bank_name === "" ? null : { value: item.locf.bank_name },
                            item.locf.type_of_credit === null ? null : item.locf.type_of_credit === "" ? null : { value: item.locf.type_of_credit },
                            item.locf.remarks === null || item.locf.remarks === "" ? "" : item.locf.remarks,
Riri Novita's avatar
Riri Novita committed
807
                            item.locf.remarks2 === null ? null : item.locf.remarks2 === "" ? null : { value: item.locf.remarks2 },
Riri Novita's avatar
Riri Novita committed
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
                            item.locf.loan_maturity_date == null || item.locf.loan_maturity_date == "" ? null : (item.locf.loan_maturity_date !== "null" ? String(tgl[2]).length > 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(item.locf.loan_maturity_date) : null),
                            item.locf.interest === null || item.locf.interest === "" ? "0.00" : item.locf.interest,
                            item.locf.currency === null || item.locf.currency === "" ? "" : item.locf.currency,
                            item.locf.loan_plafond_amount_ori,
                            item.locf.loan_plafond_amount_idr === null ? "0.0" : item.locf.loan_plafond_amount_idr === "" ? "0.0" : item.locf.loan_plafond_amount_idr,
                            item.locf.out_loan_ki_amount_ori,
                            item.locf.out_loan_ki_amount_idr === null ? "0.0" : item.locf.out_loan_ki_amount_idr === "" ? "0.0" : item.locf.out_loan_ki_amount_idr,
                            item.locf.out_loan_kmk_amount_ori,
                            item.locf.out_loan_kmk_amount_idr === null ? "0.0" : item.locf.out_loan_kmk_amount_idr === "" ? "0.0" : item.locf.out_loan_kmk_amount_idr,
                            item.locf.out_loan_other_type,
                            item.locf.out_loan_other_amount_ori,
                            item.locf.out_loan_other_amount_idr === null ? "0.0" : item.locf.out_loan_other_amount_idr === "" ? "0.0" : item.locf.out_loan_other_amount_idr,
                            item.locf.total_out_loan_ori === null ? "0.0" : item.locf.total_out_loan_ori === "" ? "0.0" : item.locf.total_out_loan_ori,
                            item.locf.total_out_loan_idr === null ? "0.0" : item.locf.total_out_loan_idr === "" ? "0.0" : item.locf.total_out_loan_idr,
                            item.locf.remaining_plafond_ori === null ? "0.0" : item.locf.remaining_plafond_ori === "" ? "0.0" : item.locf.remaining_plafond_ori,
                            item.locf.remaining_plafond_idr === null ? "0.0" : item.locf.remaining_plafond_idr === "" ? "0.0" : item.locf.remaining_plafond_idr,
                            item.locf.current_ratio_financial,
                            item.locf.current_ratio_current === null ? "0.0" : item.locf.current_ratio_current === "" ? "0.0" : item.locf.current_ratio_current,
                            item.locf.der_financial,
                            item.locf.der_current === null ? "0.0" : item.locf.der_current === "" ? "0.0" : item.locf.der_current,
                            item.locf.debt_to_ebitda_financial,
                            item.locf.debt_to_ebitda_current === null ? "0.0" : item.locf.debt_to_ebitda_current === "" ? "0.0" : item.locf.debt_to_ebitda_current,
                            item.locf.ebitda_to_interest_financial,
                            item.locf.ebitda_to_interest_current === null ? "0.0" : item.locf.ebitda_to_interest_current === "" ? "0.0" : item.locf.ebitda_to_interest_current,
                            item.locf.other_ratio1_ratio_name,
                            item.locf.other_ratio1_financial,
                            item.locf.other_ratio1_current === null ? "0.0" : item.locf.other_ratio1_current === "" ? "0.0" : item.locf.other_ratio1_current,
                            item.locf.other_ratio2_ratio_name,
                            item.locf.other_ratio2_financial,
                            item.locf.other_ratio2_current === null ? "0.0" : item.locf.other_ratio2_current === "" ? "0.0" : item.locf.other_ratio2_current,
                            item.locf.other_ratio3_ratio_name,
                            item.locf.other_ratio3_financial,
                            item.locf.other_ratio3_current === null ? "0.0" : item.locf.other_ratio3_current === "" ? "0.0" : item.locf.other_ratio3_current,
                            item.locf.other_ratio4_ratio_name,
                            item.locf.other_ratio4_financial,
                            item.locf.other_ratio4_current === null ? "0.0" : item.locf.other_ratio4_current === "" ? "0.0" : item.locf.other_ratio4_current,
                            item.locf.notes,
                            item.diff,
                            item.total_loan,
                            item.per_bs
                            // index
                        ])
850 851 852 853 854 855
                        if (item.children !== null) {
                            if (item.children.length > 0) {
                                item.children.map((items, indexs) => {
                                    handlePushChild(items)
                                })
                            }
d.arizona's avatar
d.arizona committed
856
                        }
857 858 859 860 861 862 863 864 865 866 867 868
                    })

                    let lastArrayLOCF = dataTablelocf[res.length - 1]
                    let roundDataDiff = fixNumber(Number(lastArrayLOCF[47]), 1)
                    let roundDataLoan = fixNumber(Number(lastArrayLOCF[48]), 1)
                    let roundDataPerBS = fixNumber(Number(lastArrayLOCF[49]), 1)
                    console.log(dataTablelocf);
                    if (bankNameEmpty) {
                        if (this.state.get_for == 'view') {
                            this.setState({ saveDraft: false, saveComp: true })
                        } else {
                            this.setState({ saveDraft: false, saveComp: true })
d.arizona's avatar
d.arizona committed
869
                        }
Riri Novita's avatar
Riri Novita committed
870
                    } else {
871 872 873 874 875
                        if (this.state.get_for == 'view') {
                            console.log("view");
                        } else {
                            this.setState({ saveDraft: false, saveComp: roundDataDiff == 0 || roundDataDiff == '0.0' || roundDataDiff == "-0.0" ? false : true })
                        }
Riri Novita's avatar
Riri Novita committed
876
                    }
877 878 879
                    this.setState({ dataTablelocf, diffLOCF: roundDataDiff, totalLoanLOCF: roundDataLoan, perBSLOCF: roundDataPerBS, loading: false }, () => {
                        this.handleCalculateLOV()
                    })
Riri Novita's avatar
Riri Novita committed
880
                }
d.arizona's avatar
d.arizona committed
881
            }
882

d.arizona's avatar
d.arizona committed
883 884
        })
    }
885

Riri Novita's avatar
Riri Novita committed
886
    handleCalculateLOV = () => {
Riri Novita's avatar
Riri Novita committed
887
        this.setState({ loading: true })
Riri Novita's avatar
Riri Novita committed
888 889 890 891 892 893
        // console.log(this.state.dataTablelov);
        // console.log(this.state.dataTableLOV);
        // console.log(this.state.tambahLOV);
        // console.log(this.state.visibleParent);

        let dataTable2 = []
Riri Novita's avatar
Riri Novita committed
894 895
        let data = []
        let error = false
Riri Novita's avatar
Riri Novita committed
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
        let bankNameEmpty = false

        if (this.state.visibleParent == false) {
            if (this.state.dataTablelov == undefined) {
                dataTable2 = this.state.dataTableLOV
            } else {
                if (this.state.tambahLOV = 'upload') {
                    this.setState({ updateTambah: true })
                    if (this.state.updateData == true) {
                        dataTable2 = this.state.dataTableLOV
                        this.setState({ cekTambah: true })
                        if (this.state.updateTambah == true && this.state.updateData == true) {
                            dataTable2 = this.state.dataTablelov
                            if (this.state.cekTambah == undefined) {
                                dataTable2 = this.state.dataTableLOV
                            }
                        }
                    } else {
                        dataTable2 = this.state.dataTablelov
                    }
                    this.setState({ updateData: true })
                } else if (this.state.tambahLOV = 'tambah') {
                    if (this.state.updateData == true) {
                        dataTable2 = this.state.dataTablelov
                    } else {
                        dataTable2 = this.state.dataTableLOV
                    }
                }
            }
        } else {
            if (this.state.dataTablelov !== undefined && this.state.tambahLOV == undefined) {
                console.log('1');
                dataTable2 = this.state.dataTablelov
            } else {
                console.log('2');
                dataTable2 = this.state.dataTableLOV
                this.setState({ updateTambah: true, updateData: false })
                if (this.state.tambahLOV = 'tambah' && this.state.updateData == false) {
                    console.log('3');
                    dataTable2 = this.state.dataTablelov
                } else {
                    console.log('4')
                    dataTable2 = this.state.dataTableLOV
                }

            }
        }

Riri Novita's avatar
Riri Novita committed
944
        console.log(dataTable2);
Riri Novita's avatar
Riri Novita committed
945
        dataTable2.map(i => {
Riri Novita's avatar
Riri Novita committed
946 947 948
            if (i[6] == null) {
                bankNameEmpty = true
            }
Riri Novita's avatar
Riri Novita committed
949
            if (i[0] == 3) {
Riri Novita's avatar
Riri Novita committed
950
                if (i[6] == null || i[7] == null || i[9] == "" || i[10] == "" || i[11] == "" || i[12] == "") {
Riri Novita's avatar
Riri Novita committed
951
                    error = true
fahrur huzain's avatar
fahrur huzain committed
952
                    this.setState({ emptyData: true})
Riri Novita's avatar
Riri Novita committed
953
                }
fahrur huzain's avatar
fahrur huzain committed
954
                if (i[7] == null || i[7] == ""){
Riri Novita's avatar
Riri Novita committed
955
                    error = true
fahrur huzain's avatar
fahrur huzain committed
956 957 958 959 960 961 962
                }else {
                    if ((i[7].value == 'Government bonds' && i[8] == '') || (i[7].value == 'Stocks' && i[8] == '') || (i[7].value == 'Mutual funds' && i[8] == '') || (i[7].value == 'Investment in associate' && i[8] == '') || (i[7].value == 'Investment in joint venture' && i[8] == '') || (i[7].value == 'Investment in subsidiary' && i[8] == '') || (i[7].value == 'Corporate bonds' && i[8] == '') || (i[7].value == 'Others' && i[8] == '')) {
                        error = true
                        this.setState({ emptyData: true})
                    } else {
                        error = false
                    }
Riri Novita's avatar
Riri Novita committed
963
                }
Riri Novita's avatar
Riri Novita committed
964 965 966
                // if (i[7].value == 'Government bonds' || i[7].value == 'Stocks' || i[7].value == 'Mutual funds' || i[7].value == 'Investment in associate' || i[7].value == 'Investment in joint venture' || i[7].value == 'Investment in subsidiary' || i[7].value == 'Corporate bonds' || i[7].value == 'Others' && i[8] == '' ) {
                //     error = true
                // }
Riri Novita's avatar
Riri Novita committed
967 968 969 970 971 972
                let tgl = String(i[9]).split('-')
                let checkUndifined = tgl.findIndex((val) => val == undefined)
                if (this.props.defaultCurrency.id == 2) {
                    data.push({
                        "item_report_id": i[1],
                        "company_name": i[5],
Riri Novita's avatar
Riri Novita committed
973
                        "institution_name": i[6],
974
                        "type_of_investment": i[7] == null ? i[7] : i[7]?.value,
Riri Novita's avatar
Riri Novita committed
975
                        "remarks": i[8],
Riri Novita's avatar
Riri Novita committed
976 977 978
                        "placement_date": i[9] == undefined || i[9] == "null" || i[9] == null ? "" : (String(tgl[2]).length <= 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[9])),
                        "tenor": i[10],
                        "expected_return": i[11] == "" ? "0.00" : i[11],
Riri Novita's avatar
Riri Novita committed
979 980
                        // "currency": i[12] == null ? i[12] : i[12].value,
                        "currency": i[12],
Riri Novita's avatar
Riri Novita committed
981 982 983
                        "investment_amount_ori": Number(i[13]) == "" ? "0.0" : Number(i[13]),
                        "investment_amount_cur": Number(i[14]) == "" ? "0.0" : Number(i[14]),
                        "notes": i[15],
Riri Novita's avatar
Riri Novita committed
984 985 986 987
                    })
                } else {
                    data.push({
                        "item_report_id": i[1],
Riri Novita's avatar
Riri Novita committed
988 989
                        "company_name": i[5],
                        "institution_name": i[6],
990
                        "type_of_investment": i[7] == null ? i[7] : i[7]?.value,
Riri Novita's avatar
Riri Novita committed
991
                        "remarks": i[8],
Riri Novita's avatar
Riri Novita committed
992 993 994
                        "placement_date": i[9] == undefined || i[9] == "null" || i[9] == null ? "" : (String(tgl[2]).length <= 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[9])),
                        "tenor": i[10],
                        "expected_return": i[11] == "" ? "0.00" : i[11],
Riri Novita's avatar
Riri Novita committed
995 996
                        // "currency": i[12] == null ? i[12] : i[12].value,
                        "currency": i[12],
Riri Novita's avatar
Riri Novita committed
997 998 999
                        "investment_amount_ori": Number(i[13]) == "" ? "0.0" : Number(i[13]),
                        "investment_amount_cur": Number(i[14]) == "" ? "0.0" : Number(i[14]),
                        "notes": i[15],
Riri Novita's avatar
Riri Novita committed
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
                    })
                }

            }
        })
        let body = {
            "monthly_report_id": this.props.monthlyReportId,
            "company_id": this.props.company.company_id,
            "periode": this.props.periode,
            "report_id": this.props.report_id,
            "status": 'submitted',
            "months": this.props.month.month_id,
            "currency_id": this.props.defaultCurrency.id,
Riri Novita's avatar
Riri Novita committed
1013 1014 1015
            "lov": data,
            "per_bs": this.state.perBSLOV,
            "diff": this.state.diffLOV,
Riri Novita's avatar
Riri Novita committed
1016
            "total_loan": this.state.totalLoanLOV
Riri Novita's avatar
Riri Novita committed
1017 1018
        }
        console.log(body);
Riri Novita's avatar
Riri Novita committed
1019
        console.log(error);
Riri Novita's avatar
Riri Novita committed
1020
        api.create().validateSaveLOV(body).then((response) => {
Riri Novita's avatar
Riri Novita committed
1021 1022 1023 1024 1025 1026
            console.log(response);
            let dataTablelov = []
            if (response.data) {
                let res = response.data.data
                const handlePushChild = (item) => {
                    let indexIDzz = dataTablelov.findIndex((val) => val[1] === item.id)
Riri Novita's avatar
Riri Novita committed
1027
                    let tgl = String(item.lov.placement_date).split('-')
Riri Novita's avatar
Riri Novita committed
1028 1029 1030 1031 1032 1033 1034
                    if (indexIDzz === -1) {
                        dataTablelov.push([
                            item.type_report_id,
                            item.id,
                            item.parent,
                            item.formula,
                            item.level,
Riri Novita's avatar
Riri Novita committed
1035 1036 1037 1038 1039 1040 1041
                            String(item.lov.institution_name).includes('Total') ? null : item.lov.company_name === null || item.lov.company_name === "" ? this.props.company.company_name : item.lov.company_name,
                            item.lov.institution_name === null || item.lov.institution_name === "" ? "" : item.lov.institution_name,
                            item.lov.type_of_investment === null ? null : item.lov.type_of_investment === "" ? null : { value: item.lov.type_of_investment },
                            item.lov.remarks === null || item.lov.remarks === "" ? "" : item.lov.remarks,
                            item.lov.placement_date == null || item.lov.placement_date == "" ? null : (item.lov.placement_date !== "null" ? String(tgl[2]).length > 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(item.lov.placement_date) : null),
                            item.lov.tenor === null || item.lov.tenor === "" ? "" : item.lov.tenor,
                            item.lov.expected_return === null || item.lov.expected_return === "" ? "0.0" : item.lov.expected_return,
Riri Novita's avatar
Riri Novita committed
1042 1043
                            // item.lov.currency === null ? null : item.lov.currency === "" ? null : { value: item.lov.currency },
                            item.lov.currency === null || item.lov.currency === "" ? "" : item.lov.currency,
Riri Novita's avatar
Riri Novita committed
1044 1045 1046
                            item.lov.investment_amount_ori === null ? "0.0" : item.lov.investment_amount_ori === "" ? "0.0" : item.lov.investment_amount_ori,
                            item.lov.investment_amount_cur === null ? "0.0" : item.lov.investment_amount_cur === "" ? "0.0" : item.lov.investment_amount_cur,
                            item.lov.notes,
Riri Novita's avatar
Riri Novita committed
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
                            item.diff,
                            item.total_loan,
                            item.per_bs
                            // index
                        ])
                    }
                    if (item.children !== null) {
                        if (item.children.length > 0) {
                            item.children.map((items, indexs) => {
                                handlePushChild(items)
                            })
                        }
                    }
                }
                res.map((item, index) => {
Riri Novita's avatar
Riri Novita committed
1062
                    let tgl = String(item.lov.placement_date).split('-')
Riri Novita's avatar
Riri Novita committed
1063 1064 1065 1066 1067 1068
                    dataTablelov.push([
                        item.type_report_id,
                        item.id,
                        item.parent,
                        item.formula,
                        item.level,
Riri Novita's avatar
Riri Novita committed
1069 1070 1071 1072 1073 1074 1075
                        String(item.lov.institution_name).includes('Total') ? null : item.lov.company_name === null || item.lov.company_name === "" ? this.props.company.company_name : item.lov.company_name,
                        item.lov.institution_name === null || item.lov.institution_name === "" ? "" : item.lov.institution_name,
                        item.lov.type_of_investment === null ? null : item.lov.type_of_investment === "" ? null : { value: item.lov.type_of_investment },
                        item.lov.remarks === null || item.lov.remarks === "" ? "" : item.lov.remarks,
                        item.lov.placement_date == null || item.lov.placement_date == "" ? null : (item.lov.placement_date !== "null" ? String(tgl[2]).length > 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(item.lov.placement_date) : null),
                        item.lov.tenor === null || item.lov.tenor === "" ? "" : item.lov.tenor,
                        item.lov.expected_return === null || item.lov.expected_return === "" ? "0.0" : item.lov.expected_return,
Riri Novita's avatar
Riri Novita committed
1076 1077
                        // item.lov.currency === null ? null : item.lov.currency === "" ? null : { value: item.lov.currency },
                        item.lov.currency === null || item.lov.currency === "" ? "" : item.lov.currency,
Riri Novita's avatar
Riri Novita committed
1078 1079 1080
                        item.lov.investment_amount_ori === null ? "0.0" : item.lov.investment_amount_ori === "" ? "0.0" : item.lov.investment_amount_ori,
                        item.lov.investment_amount_cur === null ? "0.0" : item.lov.investment_amount_cur === "" ? "0.0" : item.lov.investment_amount_cur,
                        item.lov.notes,
Riri Novita's avatar
Riri Novita committed
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
                        item.diff,
                        item.total_loan,
                        item.per_bs
                        // index
                    ])
                    if (item.children !== null) {
                        if (item.children.length > 0) {
                            item.children.map((items, indexs) => {
                                handlePushChild(items)
                            })
                        }
                    }
                })
                let lastArrayLOV = dataTablelov[res.length - 1]
Riri Novita's avatar
Riri Novita committed
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
                if (bankNameEmpty) {
                    if (this.state.get_for == 'view') {
                        this.setState({ saveDraft: false, saveCompLOV: true })
                    } else {
                        this.setState({ saveDraft: false, saveCompLOV: true })
                    }
                } else {
                    if (this.state.get_for == 'view') {
                        console.log("view");
                    } else {
                        this.setState({ saveDraft: false, saveCompLOV: lastArrayLOV[16] == 0 || lastArrayLOV[16] == '0.0' || lastArrayLOV[16] == "-0.0" ? false : true })
                    }
                }
Riri Novita's avatar
Riri Novita committed
1108
                this.setState({ dataTablelov, diffLOV: lastArrayLOV[16], totalLoanLOV: lastArrayLOV[17], perBSLOV: lastArrayLOV[18], loading: false, loadingChild: false }, () => {
Riri Novita's avatar
Riri Novita committed
1109 1110
                    // this.handleCalculateLOV()
                })
1111 1112
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
Riri Novita's avatar
Riri Novita committed
1113 1114 1115
            }

        })
Riri Novita's avatar
Riri Novita committed
1116
    }
d.arizona's avatar
d.arizona committed
1117

1118
    uploadLOCF(type) {
Riri Novita's avatar
Riri Novita committed
1119
        console.log('masoook LOCF');
Riri Novita's avatar
Riri Novita committed
1120
        let dataTable2 = (this.state.dataTablelocf !== undefined && this.state.tambah == 'upload') ? this.state.dataTablelocf : (this.state.dataTablelocf == undefined || this.state.tambah == 'tambah' || this.state.tambah == 'upload') ? this.state.dataTableLOCF : this.state.dataTablelocf
1121 1122
        let data = []
        let error = false
Riri Novita's avatar
Riri Novita committed
1123 1124 1125
        // this.deleteReport()
        console.log(dataTable2);
        dataTable2.map(i => {
1126
            if (i[0] == 3) {
Riri Novita's avatar
Riri Novita committed
1127
                if (i[6] == null || i[7] == null || i[8] == "" || i[10] == "" || i[11] == "" || i[12] == "") {
1128
                    error = true
d.arizona's avatar
d.arizona committed
1129
                }
1130

1131 1132
                if (i[7].value == 'Others' && i[18] == '') {
                    error = true
d.arizona's avatar
d.arizona committed
1133
                }
Riri Novita's avatar
Riri Novita committed
1134
                let tgl = String(i[10]).split('-')
1135 1136 1137 1138 1139 1140 1141 1142
                let checkUndifined = tgl.findIndex((val) => val == undefined)
                if (this.props.defaultCurrency.id == 2) {
                    data.push({
                        "item_report_id": i[1],
                        "borrower_comp_name": i[5],
                        "bank_name": i[6] == null ? [6] : i[6].value,
                        "type_of_credit": i[7] == null ? i[7] : i[7].value,
                        "remarks": i[8],
Riri Novita's avatar
Riri Novita committed
1143
                        "remarks2": i[9] == null ? i[9] : i[9].value,
1144
                        // "loan_maturity_date": i[9],
Riri Novita's avatar
Riri Novita committed
1145
                        "loan_maturity_date": i[10] == undefined || i[10] == "null" || i[10] == null ? "" : (String(tgl[2]).length <= 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[10])),
1146
                        // "loan_maturity_date":  i[9] !== undefined || i[9] !== "null" || i[9] !== null? (String(tgl[2]).length <= 2? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[9])) : "",
Riri Novita's avatar
Riri Novita committed
1147 1148 1149 1150 1151 1152 1153 1154
                        "interest": i[11] == "" ? "0.00" : i[11],
                        "currency": i[12],
                        "loan_plafond_amount_ori": Number(i[13]) == "" ? "0.0" : Number(i[13]),
                        "loan_plafond_amount_idr": Number(i[14]) == "" ? "0.0" : Number(i[14]),
                        "out_loan_ki_amount_ori": Number(i[15]) == "" ? "0.0" : Number(i[15]),
                        "out_loan_ki_amount_idr": Number(i[16]) == "" ? "0.0" : Number(i[16]),
                        "out_loan_kmk_amount_ori": Number(i[17]) == "" ? "0.0" : Number(i[17]),
                        "out_loan_kmk_amount_idr": Number(i[18]) == "" ? "0.0" : Number(i[18]),
1155
                        // "mtd_vs_previous_month": i[18],
Riri Novita's avatar
Riri Novita committed
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
                        "out_loan_other_type": i[19],
                        "out_loan_other_amount_ori": Number(i[20]) == "" ? "0.0" : Number(i[20]),
                        "out_loan_other_amount_idr": Number(i[21]) == "" ? "0.0" : Number(i[21]),
                        "total_out_loan_ori": Number(i[22]) == "" ? "0.0" : Number(i[22]),
                        "total_out_loan_idr": Number(i[23]) == "" ? "0.0" : Number(i[23]),
                        "remaining_plafond_ori": Number(i[24]) == "" ? "0.0" : Number(i[24]),
                        "remaining_plafond_idr": Number(i[25]) == "" ? "0.0" : Number(i[25]),
                        "current_ratio_financial": Number(i[26]) == "" ? "0.00" : Number(i[26]),
                        "current_ratio_current": Number(i[27]) == "" ? "0.00" : Number(i[27]),
                        "der_financial": Number(i[28]) == "" ? "0.00" : Number(i[28]),
                        "der_current": Number(i[29]) == "" ? "0.00" : Number(i[29]),
                        "debt_to_ebitda_financial": Number(i[30]) == "" ? "0.00" : Number(i[30]),
                        "debt_to_ebitda_current": Number(i[31]) == "" ? "0.00" : Number(i[31]),
                        "ebitda_to_interest_financial": Number(i[32]) == "" ? "0.00" : Number(i[32]),
                        "ebitda_to_interest_current": Number(i[33]) == "" ? "0.00" : Number(i[33]),
                        "other_ratio1_ratio_name": i[34],
                        "other_ratio1_financial": Number(i[35]) == "" ? "0.00" : Number(i[35]),
                        "other_ratio1_current": Number(i[36]) == "" ? "0.00" : Number(i[36]),
                        "other_ratio2_ratio_name": i[37],
                        "other_ratio2_financial": Number(i[38]) == "" ? "0.00" : Number(i[38]),
                        "other_ratio2_current": Number(i[39]) == "" ? "0.00" : Number(i[39]),
                        "other_ratio3_ratio_name": i[40],
                        "other_ratio3_financial": Number(i[41]) == "" ? "0.00" : Number(i[41]),
                        "other_ratio3_current": Number(i[42]) == "" ? "0.00" : Number(i[42]),
                        "other_ratio4_ratio_name": i[43],
                        "other_ratio4_financial": Number(i[44]) == "" ? "0.00" : Number(i[44]),
                        "other_ratio4_current": Number(i[45]) == "" ? "0.00" : Number(i[45]),
                        "notes": i[46],
1184
                    })
d.arizona's avatar
d.arizona committed
1185
                } else {
1186 1187 1188 1189 1190 1191
                    data.push({
                        "item_report_id": i[1],
                        "borrower_comp_name": i[5],
                        "bank_name": i[6] == null ? [6] : i[6].value,
                        "type_of_credit": i[7] == null ? i[7] : i[7].value,
                        "remarks": i[8],
Riri Novita's avatar
Riri Novita committed
1192
                        "remarks2": i[9] == null ? i[9] : i[9].value,
1193
                        // "loan_maturity_date": i[9],
Riri Novita's avatar
Riri Novita committed
1194
                        "loan_maturity_date": i[10] == undefined || i[10] == "null" || i[10] == null ? "" : (String(tgl[2]).length <= 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[10])),
1195
                        // "loan_maturity_date":  i[9] !== undefined || i[9] !== "null" || i[9] !== null? (String(tgl[2]).length <= 2? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[9])) : "",
Riri Novita's avatar
Riri Novita committed
1196 1197 1198 1199 1200 1201 1202 1203
                        "interest": i[11] == "" ? "0.00" : i[11],
                        "currency": i[12],
                        "loan_plafond_amount_ori": Number(i[13]) == "" ? "0.0" : Number(i[13]),
                        "loan_plafond_amount_idr": Number(i[14]) == "" ? "0.0" : Number(i[14]),
                        "out_loan_ki_amount_ori": Number(i[15]) == "" ? "0.0" : Number(i[15]),
                        "out_loan_ki_amount_idr": Number(i[16]) == "" ? "0.0" : Number(i[16]),
                        "out_loan_kmk_amount_ori": Number(i[17]) == "" ? "0.0" : Number(i[17]),
                        "out_loan_kmk_amount_idr": Number(i[18]) == "" ? "0.0" : Number(i[18]),
1204
                        // "mtd_vs_previous_month": i[18],
Riri Novita's avatar
Riri Novita committed
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
                        "out_loan_other_type": i[19],
                        "out_loan_other_amount_ori": Number(i[20]) == "" ? "0.0" : Number(i[20]),
                        "out_loan_other_amount_idr": Number(i[21]) == "" ? "0.0" : Number(i[21]),
                        "total_out_loan_ori": Number(i[22]) == "" ? "0.0" : Number(i[22]),
                        "total_out_loan_idr": Number(i[23]) == "" ? "0.0" : Number(i[23]),
                        "remaining_plafond_ori": Number(i[24]) == "" ? "0.0" : Number(i[24]),
                        "remaining_plafond_idr": Number(i[25]) == "" ? "0.0" : Number(i[25]),
                        "current_ratio_financial": Number(i[26]) == "" ? "0.00" : Number(i[26]),
                        "current_ratio_current": Number(i[27]) == "" ? "0.00" : Number(i[27]),
                        "der_financial": Number(i[28]) == "" ? "0.00" : Number(i[28]),
                        "der_current": Number(i[29]) == "" ? "0.00" : Number(i[29]),
                        "debt_to_ebitda_financial": Number(i[30]) == "" ? "0.00" : Number(i[30]),
                        "debt_to_ebitda_current": Number(i[31]) == "" ? "0.00" : Number(i[31]),
                        "ebitda_to_interest_financial": Number(i[32]) == "" ? "0.00" : Number(i[32]),
                        "ebitda_to_interest_current": Number(i[33]) == "" ? "0.00" : Number(i[33]),
                        "other_ratio1_ratio_name": i[34],
                        "other_ratio1_financial": Number(i[35]) == "" ? "0.00" : Number(i[35]),
                        "other_ratio1_current": Number(i[36]) == "" ? "0.00" : Number(i[36]),
                        "other_ratio2_ratio_name": i[37],
                        "other_ratio2_financial": Number(i[38]) == "" ? "0.00" : Number(i[38]),
                        "other_ratio2_current": Number(i[39]) == "" ? "0.00" : Number(i[39]),
                        "other_ratio3_ratio_name": i[40],
                        "other_ratio3_financial": Number(i[41]) == "" ? "0.00" : Number(i[41]),
                        "other_ratio3_current": Number(i[42]) == "" ? "0.00" : Number(i[42]),
                        "other_ratio4_ratio_name": i[43],
                        "other_ratio4_financial": Number(i[44]) == "" ? "0.00" : Number(i[44]),
                        "other_ratio4_current": Number(i[45]) == "" ? "0.00" : Number(i[45]),
                        "notes": i[46],
1233
                    })
d.arizona's avatar
d.arizona committed
1234
                }
d.arizona's avatar
d.arizona committed
1235 1236

            }
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246
        })
        let body = {
            "monthly_report_id": this.props.monthlyReportId,
            "company_id": this.props.company.company_id,
            "periode": this.props.periode,
            "report_id": this.props.report_id,
            "status": type,
            "months": this.props.month.month_id,
            "currency_id": this.props.defaultCurrency.id,
            "locf": data,
Riri Novita's avatar
Riri Novita committed
1247 1248 1249
            "per_bs": this.state.perBSLOCF,
            "diff": this.state.diffLOCF,
            "total_loan": this.state.totalLoanLOCF
d.arizona's avatar
d.arizona committed
1250
        }
Riri Novita's avatar
Riri Novita committed
1251
        console.log(body);
Riri Novita's avatar
Riri Novita committed
1252
        if (error && type == 'submitted') {
Riri Novita's avatar
Riri Novita committed
1253
            this.setState({ handleDoubleClick: 0, saveDraft: false, saveComp: true, loadingChild: false, snekbar: true, snekbarMsg: 'Data Incomplete', handleDoubleClick: 0 })
Riri Novita's avatar
Riri Novita committed
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291
        } else {
            api.create('UPLOAD').uploadMonthlyReportLOCF(body).then(response => {
                console.log(response);
                if (response.data) {
                    if (response.ok) {
                        if (response.data.status === "success") {
                            this.uploadLOV(type)
                            // this.props.saveToMonthlyReport('LOCF')
                            // this.props.onClickClose()
                            // this.props.getReport()
                        } else {
                            if (response.data?.message == "Please Set Up Rate Currency First") {
                                this.setState({ visibleAlertSave: true })
                            } else {
                                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                        setTimeout(() => {
                                            localStorage.removeItem(Constant.TOKEN)
                                            window.location.reload();
                                        }, 1000);
                                    }
                                })
                            }
                            // alert(response.data.status)
                        }
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false, handleDoubleClick: 0 })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false, handleDoubleClick: 0 })
                }
                this.setState({ handleDoubleClick: 0 })
            })
        }
    }

    uploadLOV(type) {
        console.log('masoook LOV');
Riri Novita's avatar
Riri Novita committed
1292
        let dataTable2 = []
Riri Novita's avatar
Riri Novita committed
1293 1294 1295
        let data = []
        let error = false
        // this.deleteReport()
Riri Novita's avatar
Riri Novita committed
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
        if (this.state.dataTablelov == undefined) {
            dataTable2 = this.state.dataTableLOV
        } else {
            if (this.state.tambahLOV = 'upload') {
                this.setState({ updateTambah: true })
                if (this.state.updateData == true) {
                    dataTable2 = this.state.dataTableLOV
                    this.setState({ cekTambah: true })
                    if (this.state.updateTambah == true && this.state.updateData == true) {
                        dataTable2 = this.state.dataTablelov
                        if (this.state.cekTambah == undefined) {
                            dataTable2 = this.state.dataTableLOV
                        }
                    }
                } else {
                    dataTable2 = this.state.dataTablelov
                }
                this.setState({ updateData: true })
            } else if (this.state.tambahLOV = 'tambah') {
                if (this.state.updateData == true) {
                    dataTable2 = this.state.dataTablelov
                } else {
                    dataTable2 = this.state.dataTableLOV
                }
            }
        }
Riri Novita's avatar
Riri Novita committed
1322 1323 1324 1325 1326 1327 1328
        console.log(dataTable2);
        dataTable2.map(i => {
            if (i[0] == 3) {
                if (i[6] == null || i[7] == null || i[8] == "" || i[9] == "" || i[10] == "" || i[11] == "" || i[12] == "") {
                    error = true
                }

1329
                if ((i[7].value == 'Government bonds' && i[8] == '') || (i[7].value == 'Stocks' && i[8] == '') || (i[7].value == 'Mutual funds' && i[8] == '') || (i[7].value == 'Investment in associate' && i[8] == '') || (i[7].value == 'Investment in joint venture' && i[8] == '') || (i[7].value == 'Investment in subsidiary' && i[8] == '') || (i[7].value == 'Corporate bonds' && i[8] == '') || (i[7].value == 'Others' && i[8] == '')) {
Riri Novita's avatar
Riri Novita committed
1330
                    error = true
1331 1332
                } else {
                    error = false
Riri Novita's avatar
Riri Novita committed
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
                }
                let tgl = String(i[9]).split('-')
                let checkUndifined = tgl.findIndex((val) => val == undefined)
                if (this.props.defaultCurrency.id == 2) {
                    data.push({
                        "item_report_id": i[1],
                        "company_name": i[5],
                        "institution_name": i[6],
                        "type_of_investment": i[7] == null ? i[7] : i[7].value,
                        "remarks": i[8],
                        "placement_date": i[9] == undefined || i[9] == "null" || i[9] == null ? "" : (String(tgl[2]).length <= 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[9])),
                        "tenor": i[10],
                        "expected_return": i[11] == "" ? "0.00" : i[11],
Riri Novita's avatar
Riri Novita committed
1346 1347
                        // "currency": i[12] == null ? i[12] : i[12].value,
                        "currency": i[12],
Riri Novita's avatar
Riri Novita committed
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361
                        "investment_amount_ori": Number(i[13]) == "" ? "0.0" : Number(i[13]),
                        "investment_amount_cur": Number(i[14]) == "" ? "0.0" : Number(i[14]),
                        "notes": i[15],
                    })
                } else {
                    data.push({
                        "item_report_id": i[1],
                        "company_name": i[5],
                        "institution_name": i[6],
                        "type_of_investment": i[7] == null ? i[7] : i[7].value,
                        "remarks": i[8],
                        "placement_date": i[9] == undefined || i[9] == "null" || i[9] == null ? "" : (String(tgl[2]).length <= 2 ? tgl[2] + '-' + tgl[1] + '-' + tgl[0] : String(i[9])),
                        "tenor": i[10],
                        "expected_return": i[11] == "" ? "0.00" : i[11],
Riri Novita's avatar
Riri Novita committed
1362 1363
                        // "currency": i[12] == null ? i[12] : i[12].value,
                        "currency": i[12],
Riri Novita's avatar
Riri Novita committed
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380
                        "investment_amount_ori": Number(i[13]) == "" ? "0.0" : Number(i[13]),
                        "investment_amount_cur": Number(i[14]) == "" ? "0.0" : Number(i[14]),
                        "notes": i[15],
                    })
                }

            }
        })
        let body = {
            "monthly_report_id": this.props.monthlyReportId,
            "company_id": this.props.company.company_id,
            "periode": this.props.periode,
            "report_id": this.props.report_id,
            "status": type,
            "months": this.props.month.month_id,
            "currency_id": this.props.defaultCurrency.id,
            "lov": data,
Riri Novita's avatar
Riri Novita committed
1381 1382 1383
            "per_bs": this.state.perBSLOV,
            "diff": this.state.diffLOV,
            "total_loan": this.state.totalLoanLOV
Riri Novita's avatar
Riri Novita committed
1384 1385 1386
        }
        console.log(body);
        if (error && type == 'submitted') {
Riri Novita's avatar
Riri Novita committed
1387
            this.setState({ handleDoubleClick: 0, saveDraft: false, saveComp: true, loadingChild: false, snekbar: true, snekbarMsg: 'Data Incomplete', handleDoubleClick: 0 })
Riri Novita's avatar
Riri Novita committed
1388
        } else {
Riri Novita's avatar
Riri Novita committed
1389
            api.create('UPLOAD').createMonthlyReportLOV(body).then(response => {
Riri Novita's avatar
Riri Novita committed
1390 1391 1392 1393 1394
                console.log(response);
                if (response.data) {
                    if (response.ok) {
                        if (response.data.status === "success") {
                            this.props.saveToMonthlyReport('LOCF')
Riri Novita's avatar
Riri Novita committed
1395
                            this.setState({ loadingChild: false })
Riri Novita's avatar
Riri Novita committed
1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
                            // this.props.onClickClose()
                            // this.props.getReport()
                        } else {
                            if (response.data?.message == "Please Set Up Rate Currency First") {
                                this.setState({ visibleAlertSave: true })
                            } else {
                                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
                                    if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
                                        setTimeout(() => {
                                            localStorage.removeItem(Constant.TOKEN)
                                            window.location.reload();
                                        }, 1000);
                                    }
                                })
                            }
                            // alert(response.data.status)
                        }
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false, handleDoubleClick: 0 })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false, handleDoubleClick: 0 })
                }
                this.setState({ handleDoubleClick: 0 })
            })
        }
1422
    }
d.arizona's avatar
d.arizona committed
1423

Riri Novita's avatar
Riri Novita committed
1424 1425 1426 1427
    closeAlert() {
        this.setState({ alert: false })
    }

1428 1429 1430
    render() {
        let dataTable2 = this.state.dataTable
        let loading = this.state.loading
Riri Novita's avatar
Riri Novita committed
1431

Riri Novita's avatar
Riri Novita committed
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
        const loadingComponent = (
            <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)' }}>
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
            </div>
        );
1442

Riri Novita's avatar
Riri Novita committed
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459
        const handleClose = (event, reason) => {
            if (reason === 'clickaway') {
                return;
            }

            this.setState({
                snekbar: false,
                snekbarMsg: ''
            })
        };

        return (
            <div>
                <div className={"main-color"} style={{ height: 78, flex: 1, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
                    <Typography style={{ fontSize: '16px', color: 'white' }}>Monthly Report</Typography>
                </div>
                <div style={{ flex: 1, padding: 20, width: '100%' }}>
Riri Novita's avatar
Riri Novita committed
1460
                    {this.state.visibleParent ?
Riri Novita's avatar
Riri Novita committed
1461
                        < Paper style={{ paddingTop: 10, paddingBottom: 20 }}>
Riri Novita's avatar
Riri Novita committed
1462 1463 1464
                            <Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
                                <Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
                                    {this.state.messageAlert}
Riri Novita's avatar
Riri Novita committed
1465 1466 1467 1468
                                </Alert>
                            </Snackbar>
                            <div style={{ borderBottom: 'solid 1px #c4c4c4' }} >
                                <Typography style={{ fontSize: '12px', color: '#4b4b4b', margin: 10 }}>Monthly Report - List Of Credit Facilities and Investment</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
1469
                            </div>
d.arizona's avatar
d.arizona committed
1470

Riri Novita's avatar
Riri Novita committed
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484
                            <LOCF
                                company={this.props.company}
                                month={this.props.month}
                                periode={this.props.periode}
                                revision={this.props.revision}
                                defaultCurrency={this.props.defaultCurrency}
                                get_for={this.state.get_for}
                                monthlyReportId={this.props.monthlyReportId}
                                report_id={this.props.report_id}
                                updateBy={this.state.updateBy}
                                notes={this.state.notes}
                                open={this.props.open}
                                height={this.props.height}
                                width={this.props.width}
Riri Novita's avatar
Riri Novita committed
1485
                                sendToParent={this.dataTableForChild.bind(this)}
Riri Novita's avatar
Riri Novita committed
1486
                                dataTablelocf={this.state.dataTablelocf}
Riri Novita's avatar
Riri Novita committed
1487
                                loadingChild={this.state.loadingChild}
Riri Novita's avatar
Riri Novita committed
1488
                            />
Riri Novita's avatar
Riri Novita committed
1489
                            <hr />
Riri Novita's avatar
Riri Novita committed
1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503
                            <LOV
                                company={this.props.company}
                                month={this.props.month}
                                periode={this.props.periode}
                                revision={this.props.revision}
                                defaultCurrency={this.props.defaultCurrency}
                                get_for={this.state.get_for}
                                monthlyReportId={this.props.monthlyReportId}
                                report_id={this.props.report_id}
                                updateBy={this.state.updateBy}
                                notes={this.state.notes}
                                open={this.props.open}
                                height={this.props.height}
                                width={this.props.width}
Riri Novita's avatar
Riri Novita committed
1504
                                sendToParent={this.dataTableForChild.bind(this)}
Riri Novita's avatar
Riri Novita committed
1505
                                dataTablelov={this.state.dataTablelov}
Riri Novita's avatar
Riri Novita committed
1506
                                loadingChild={this.state.loadingChild}
Riri Novita's avatar
Riri Novita committed
1507
                            />
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529
                            <div className="grid grid-2x" style={{ marginTop: 20 }}>
                                <div className="col-1">
                                    <button
                                        type="button"
                                        onClick={() => this.setState({ loading: true }, () => {
                                            setTimeout(() => {
                                                this.props.onClickClose()
                                            }, 100);
                                        })}
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            outline: 'none'
                                        }}
                                    >
                                        <div style={{ backgroundColor: '#019ce5', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', marginLeft: 10 }}>
                                            <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Back</Typography>
                                        </div>
                                    </button>
                                </div>
                                {/* (this.props.lastStatus === 'SUBMIT' || this.props.lastStatus === 'REVISION') && this.props.prevRevision === false && (this.props.status === 'revision' || this.props.status === 'not-yet' || this.props.status === 'draft' || this.props.status === 'submitted') ? */}
d.arizona's avatar
d.arizona committed
1530

1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545
                                {this.props.isApprover === true ? null :
                                    <div className="col-2" style={{ display: 'flex', justifyContent: 'flex-end', maxWidth: '100%' }}>
                                        {this.state.get_for == 'view' && this.state.viewOnly && <button
                                            className="button"
                                            type="button"
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent',
                                                outline: 'none',
                                                marginRight: 20
                                            }}
                                            onClick={() => {
                                                this.setState({ loading: true }, () => {
                                                    this.handleGetFor('edit')
qorri_di's avatar
qorri_di committed
1546
                                                })
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562
                                            }}
                                        >
                                            <div style={{ backgroundColor: '#fff', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #354960' }}>
                                                <Typography style={{ fontSize: '11px', color: '#354960', textAlign: 'center' }}>Edit</Typography>
                                            </div>
                                        </button>}
                                        {this.state.get_for == 'edit' && <button
                                            className="button"
                                            type="button"
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent',
                                                outline: 'none',
                                                marginRight: 20
                                            }}
Riri Novita's avatar
Riri Novita committed
1563
                                            onClick={() => this.setState({ saveTambahan: false, loadingChild: true }, () => {
Riri Novita's avatar
Riri Novita committed
1564 1565 1566
                                                setTimeout(() => {
                                                    this.handleCalculateLOCF()
                                                }, 100);
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
                                            })}
                                        >
                                            <div style={{ backgroundColor: '#fff', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #354960' }}>
                                                <Typography style={{ fontSize: '11px', color: '#354960', textAlign: 'center' }}>Calculate</Typography>
                                            </div>
                                        </button>}
                                        {this.state.get_for == 'edit' && <button
                                            className="button"
                                            type="button"
                                            onClick={() =>
                                                this.state.saveDraft === true || this.state.saveTambahan ?
                                                    this.setState({ snekbar: true, snekbarMsg: 'Data Incomplete' })
                                                    :
                                                    this.state.handleDoubleClick == 1 ? null :
Riri Novita's avatar
Riri Novita committed
1581
                                                        this.setState({ handleDoubleClick: 1, loadingChild: true }, () => {
1582
                                                            setTimeout(() => {
1583
                                                                this.backToMonthlyReportLOCF('draft')
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602
                                                            }, 100);
                                                        })
                                            }
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent',
                                                outline: 'none',
                                                marginRight: 20
                                            }}
                                        >
                                            <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                                <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Save as Draft</Typography>
                                            </div>
                                        </button>}
                                        {this.state.get_for == 'edit' && <button
                                            type="button"
                                            // disabled={this.state.buttonError}
                                            onClick={() =>
Riri Novita's avatar
Riri Novita committed
1603
                                                this.state.saveComp || this.state.saveCompLOV || this.state.saveTambahan ?
1604 1605 1606
                                                    this.setState({ snekbar: true, snekbarMsg: 'Data Incomplete / Diff must be 0' })
                                                    :
                                                    this.state.handleDoubleClick == 1 ? null :
Riri Novita's avatar
Riri Novita committed
1607
                                                        this.setState({ handleDoubleClick: 1, loadingChild: true }, () => {
1608
                                                            setTimeout(() => {
1609
                                                                this.backToMonthlyReportLOCF('submitted')
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625
                                                            }, 100);
                                                        })
                                            }
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent',
                                                outline: 'none'
                                            }}
                                        >
                                            <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', marginRight: 20 }}>
                                                <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Save & Complete</Typography>
                                            </div>
                                        </button>}
                                    </div>}
                                {/* : null } */}
d.arizona's avatar
d.arizona committed
1626
                            </div>
1627 1628 1629 1630 1631 1632 1633 1634 1635
                        </Paper>
                        :
                        <Paper style={{ paddingTop: 10, paddingBottom: 20 }}>
                            <Snackbar open={this.state.snekbar} autoHideDuration={6000} onClose={handleClose}>
                                <Alert onClose={handleClose} severity="error">
                                    {this.state.snekbarMsg}
                                </Alert>
                            </Snackbar>
                            <div style={{ borderBottom: 'solid 1px #c4c4c4' }} >
Riri Novita's avatar
Riri Novita committed
1636
                                <Typography style={{ fontSize: '12px', color: '#4b4b4b', margin: 10 }}>Monthly Report - List Of Credit Facilities and Investment</Typography>
d.arizona's avatar
d.arizona committed
1637
                            </div>
Riri Novita's avatar
Riri Novita committed
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651
                            <LOCF
                                company={this.props.company}
                                month={this.props.month}
                                periode={this.props.periode}
                                revision={this.props.revision}
                                defaultCurrency={this.props.defaultCurrency}
                                get_for={this.state.get_for}
                                monthlyReportId={this.props.monthlyReportId}
                                report_id={this.props.report_id}
                                updateBy={this.state.updateBy}
                                notes={this.state.notes}
                                open={this.props.open}
                                height={this.props.height}
                                width={this.props.width}
Riri Novita's avatar
Riri Novita committed
1652
                                sendToParent={this.dataTableForChild.bind(this)}
Riri Novita's avatar
Riri Novita committed
1653
                                dataTablelocf={this.state.dataTablelocf}
Riri Novita's avatar
Riri Novita committed
1654
                                loadingChild={this.state.loadingChild}
Riri Novita's avatar
Riri Novita committed
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670
                            />
                            <hr />
                            <LOV
                                company={this.props.company}
                                month={this.props.month}
                                periode={this.props.periode}
                                revision={this.props.revision}
                                defaultCurrency={this.props.defaultCurrency}
                                get_for={this.state.get_for}
                                monthlyReportId={this.props.monthlyReportId}
                                report_id={this.props.report_id}
                                updateBy={this.state.updateBy}
                                notes={this.state.notes}
                                open={this.props.open}
                                height={this.props.height}
                                width={this.props.width}
Riri Novita's avatar
Riri Novita committed
1671
                                sendToParent={this.dataTableForChild.bind(this)}
Riri Novita's avatar
Riri Novita committed
1672
                                dataTablelov={this.state.dataTablelov}
Riri Novita's avatar
Riri Novita committed
1673
                                loadingChild={this.state.loadingChild}
Riri Novita's avatar
Riri Novita committed
1674
                            />
1675 1676 1677 1678
                            <div className="grid grid-2x" style={{ marginTop: 20 }}>
                                <div className="col-1">
                                    <button
                                        type="button"
Riri Novita's avatar
Riri Novita committed
1679 1680 1681 1682 1683
                                        onClick={() => this.setState({ loading: true }, () => {
                                            setTimeout(() => {
                                                this.props.onClickClose()
                                            }, 100);
                                        })}
1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            outline: 'none'
                                        }}
                                    >
                                        <div style={{ backgroundColor: '#019ce5', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', marginLeft: 10 }}>
                                            <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Back</Typography>
                                        </div>
                                    </button>
                                </div>
                                {/* {this.props.isApprover === true || this.state.dataTable.length == 0 ? null :
d.arizona's avatar
d.arizona committed
1697
                                (this.props.lastStatus === 'SUBMIT' || this.props.lastStatus === 'REVISION') && this.props.prevRevision === false && (this.props.status === 'revision' || this.props.status === 'not-yet' || this.props.status === 'draft' || this.props.status === 'submitted') ? */}
1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708
                                <div className="col-2" style={{ display: 'flex', justifyContent: 'flex-end', maxWidth: '100%' }}>
                                    <button
                                        className="button"
                                        type="button"
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            outline: 'none',
                                            marginRight: 20
                                        }}
Riri Novita's avatar
Riri Novita committed
1709
                                        onClick={() => this.setState({ saveTambahan: false, loadingChild: true }, () => {
Riri Novita's avatar
Riri Novita committed
1710
                                            this.handleCalculateLOCF()
1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724
                                        })}
                                    >
                                        <div style={{ backgroundColor: '#fff', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #354960' }}>
                                            <Typography style={{ fontSize: '11px', color: '#354960', textAlign: 'center' }}>Calculate</Typography>
                                        </div>
                                    </button>
                                    <button
                                        className="button"
                                        type="button"
                                        onClick={() =>
                                            this.state.saveDraft === true || this.state.saveTambahan ?
                                                this.setState({ snekbar: true, snekbarMsg: 'Data Incomplete' })
                                                :
                                                this.state.handleDoubleClick == 1 ? null :
Riri Novita's avatar
Riri Novita committed
1725
                                                    this.setState({ handleDoubleClick: 1, loadingChild: true }, () => {
1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746
                                                        setTimeout(() => {
                                                            this.uploadLOCF('draft')
                                                        }, 100);
                                                    })
                                        }
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            outline: 'none',
                                            marginRight: 20
                                        }}
                                    >
                                        <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                            <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Save as Draft</Typography>
                                        </div>
                                    </button>
                                    <button
                                        type="button"
                                        // disabled={this.state.buttonError}
                                        onClick={() =>
Riri Novita's avatar
Riri Novita committed
1747
                                            this.state.saveComp || this.state.saveCompLOV || this.state.saveTambahan ?
1748 1749 1750
                                                this.setState({ snekbar: true, snekbarMsg: 'Data Incomplete / Diff must be 0' })
                                                :
                                                this.state.handleDoubleClick == 1 ? null :
Riri Novita's avatar
Riri Novita committed
1751
                                                    this.setState({ handleDoubleClick: 1, loadingChild: true }, () => {
1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769
                                                        setTimeout(() => {
                                                            this.uploadLOCF('submitted')
                                                        }, 100);
                                                    })
                                        }
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            outline: 'none'
                                        }}
                                    >
                                        <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', marginRight: 20 }}>
                                            <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Save & Complete</Typography>
                                        </div>
                                    </button>
                                </div>
                                {/* : null } */}
d.arizona's avatar
d.arizona committed
1770
                            </div>
1771
                        </Paper>}
Deni Rinaldi's avatar
Deni Rinaldi committed
1772
                </div>
fahrur huzain's avatar
fahrur huzain committed
1773 1774 1775 1776 1777
                {this.state.emptyData && (
                    <PopUpValidationLOV
                        onClickClose={() => this.setState({ emptyData: false })}
                    />
                )}
Riri Novita's avatar
Riri Novita committed
1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789
                {
                    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>
1790
                                    </div>
Riri Novita's avatar
Riri Novita committed
1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808
                                    <div style={{ display: 'flex', justifyContent: 'flex-end' }}>
                                        <button
                                            className="button"
                                            type="button"
                                            style={{
                                                background: '#F6F7F9',
                                                cursor: 'pointer',
                                                border: '1px solid #3549609e',
                                                outline: 'none',
                                                marginRight: 20,
                                                borderRadius: 9
                                            }}
                                            onClick={() => this.setState({ visibleAlertSave: false, handleDoubleClick: 0, loading: false })}
                                        >
                                            <div style={{ backgroundColor: '#fff', width: 105, height: 30, borderRadius: 9, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #3549609e' }}>
                                                <Typography style={{ fontSize: '15px', color: '#354960', textAlign: 'center' }}>Close</Typography>
                                            </div>
                                        </button>
1809 1810 1811
                                    </div>
                                </div>
                            </div>
d.arizona's avatar
d.arizona committed
1812
                        </div>
Riri Novita's avatar
Riri Novita committed
1813 1814 1815
                    )
                }
            </div >
Deni Rinaldi's avatar
Deni Rinaldi committed
1816 1817 1818
        )
    }

Riri Novita's avatar
Riri Novita committed
1819
}