Commit 44b07711 authored by Riri Novita's avatar Riri Novita

Button Upload Simulasi MR

parent 72e45bfd
......@@ -81,6 +81,7 @@ export default class CorporateAnnualTargetMR extends Component {
visibleAlertSave: false
}
this.fileHandler = this.fileHandler.bind(this);
this.fileHandlerSimulasi = this.fileHandlerSimulasi.bind(this);
}
componentDidMount() {
......@@ -409,6 +410,45 @@ export default class CorporateAnnualTargetMR extends Component {
});
}
fileHandlerSimulasi = (event) => {
let fileObj = event
ExcelRenderer(fileObj, (err, resp) => {
if (err) {
console.log(err);
}
else {
let isi = resp.rows.slice(3)
console.log(isi);
let payload = []
let reg = /^[-+]?(?:[0-9]+,)*[0-9]+(?:\.[0-9]+)?$/;
isi.map((i, index) => {
if (i.length > 0) {
payload.push({
item_report_id: i[1] === undefined ? "" : String(i[1]).trim(),
item_report: i[2] === undefined ? "" : String(i[2]).trim(),
weight: i[3] === undefined ? "" : (String(i[3])) === false ? "0" : String(i[3]).trim(),
uom: i[4] === undefined ? "" : (String(i[4])) === false ? "0" : String(i[4]).trim(),
jenis_kpi: i[5] === undefined ? "" : (String(i[5])) === false ? "0" : String(i[5]).trim(),
max_ach: i[6] === undefined ? "" : (String(i[6])) === false ? "0" : String(i[6]).trim(),
actual_monthly: i[7] === undefined ? "0.0" : (String(i[7])) === false ? "0" : String(i[7]).trim(),
notes: i[8] === undefined ? "" : (String(i[8])) === false ? "0" : String(i[8]).trim(),
})
}
})
let body = {
company_id: this.props.company.company_id,
periode: this.props.periode,
report_id: this.props.report_id,
months: this.props.month.month_id,
corporate_annual_target: payload,
status: "submitted"
}
console.log(body)
this.setState({ payload: body, judul: resp.rows[1][0], judulColumn: resp.rows[0][0] })
}
});
}
checkUpload() {
this.setState({ loading: true })
let payload = {
......@@ -471,6 +511,31 @@ export default class CorporateAnnualTargetMR extends Component {
})
}
uploadSimulasi() {
let payload = {
...this.state.payload,
currency_id: this.state.defaultCurrencyUpload?.id
}
this.setState({ loading: true, dataTable: [] })
console.log(payload)
api.create().checkUploadMBSimulasi(payload).then(response => {
console.log(response)
if (response.data) {
if (response.ok) {
if (response.data.status === "success") {
this.props.onClickClose()
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
}
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
}
} else {
this.setState({ alert: true, messageAlert: 'Error saving data. Please try again', tipeAlert: 'error', loading: false })
}
})
}
uploadCATMR(type) {
let data = []
this.state.dataTable.map(i => {
......@@ -1989,6 +2054,21 @@ export default class CorporateAnnualTargetMR extends Component {
</div>
<div style={{ width: '50%' }}>
<div style={{ justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
<ReactTooltip border={true} id="template" place="bottom" type="light" effect="solid" />
<a data-tip={'Upload Simulasi'} data-for="upload">
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
margin: 5
}}
onClick={() => this.setState({ visibleUploadSimulasi: true, buttonDraft: true })}
>
<img src={Images.simulasiUpload} style={{ width: 40, height: 40, marginRight: 3 }} />
</button>
</a>
<ReactTooltip border={true} id="upload" place="bottom" type="light" effect="solid" />
{this.state.get_for == 'edit' && <a data-tip={'Download Template'} data-for="template">
<button
style={{
......@@ -2415,6 +2495,47 @@ export default class CorporateAnnualTargetMR extends Component {
</div>
)}
{this.state.visibleUploadSimulasi && (
<div className="test app-popup-show">
<div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
<div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
<div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
<div className="popup-title">
<span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Upload File Simulasi</span>
</div>
</div>
<div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
<button
type="button"
className="btn btn-circle btn-white"
onClick={() => this.setState({ visibleUploadSimulasi: false })}
>
<img src={Images.close} />
</button>
</div>
</div>
<div style={{ padding: '25px 30px' }}>
<UploadFile
type={this.state.uploadStatusSimulasi}
percentage={this.state.percentageSimulasi}
result={this.state.resultSimulasi}
acceptedFiles={["xlsx"]}
onHandle={(dt) => {
this.fileHandlerSimulasi(dt)
this.setState({ uploadStatusSimulasi: 'idle', percentageSimulasi: '0' })
}}
onUpload={() => {
String(this.state.judulColumn).includes("TEMPLATE") && String(this.state.judulColumn).includes("UPLOAD") && String(this.state.judul).includes("PERFORMANCE") && String(this.state.judul).includes("CAT") && String(this.state.judul).includes("MONTHLY") && String(this.state.judul).includes("REPORT") ?
this.uploadSimulasi() :
this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning' })
}}
/>
</div>
<div style={{ padding: '0px 30px 29px', fontSize: 17, color: 'red' }}><b>Warning:</b> Valid currency for uploading data is <b>{this.props.defaultCurrency.id == 1 ? "IDR" : "USD"}</b></div>
</div>
</div>
)}
{this.state.visibleAlertSave && (
<div className="test app-popup-show">
<div className="popup-content border-radius" style={{ background: '#FFF27D', borderRadius: 10, width: 715, height: 238 }}>
......
......@@ -685,7 +685,7 @@ export default class MonthlyReport extends Component {
})
}
getMonthlyReportID(type) {
getMonthlyReportID(type, trigger) {
this.setState({ selectReport: [], isCheckAll: false }, () => {
let payload = {
"company_id": this.state.company.company_id,
......@@ -730,7 +730,7 @@ export default class MonthlyReport extends Component {
}
// this.getPL(type)
if (type != undefined && type == 'PL') {
this.getPL(type)
this.getPL(type, trigger)
} else if (type != undefined && type == 'LOCF') {
let bodyRatioLocf = {
"report": 'ratio',
......@@ -842,7 +842,8 @@ export default class MonthlyReport extends Component {
})
}
saveToMonthlyReport(type) {
saveToMonthlyReport(type, trigger) {
console.log(trigger);
this.setState({
visibleMonthlyReport: true,
loading: true,
......@@ -855,7 +856,7 @@ export default class MonthlyReport extends Component {
visibleLOCF: false,
visibleOI: false,
}, () => {
this.getMonthlyReportID(type)
this.getMonthlyReportID(type, trigger)
})
}
......@@ -1536,7 +1537,7 @@ export default class MonthlyReport extends Component {
})
}
getPL(type) {
getPL(type, trigger) {
let PLID = null
let payloadID = {
"periode": this.state.periode.periode,
......@@ -1661,7 +1662,7 @@ export default class MonthlyReport extends Component {
console.log(JSON.stringify(dataTable))
console.log(dataTable)
this.setState({ dbPL: dataTable }, () => {
this.olahDataPL(this.state.dbPL, type)
this.olahDataPL(this.state.dbPL, type, trigger)
})
} else {
this.setState({ loading: false, alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
......@@ -1897,7 +1898,7 @@ export default class MonthlyReport extends Component {
}
olahDataPL(dbPL, type) {
olahDataPL(dbPL, type, trigger) {
dbPL.map((item, index) => {
if (item[0] == 5 || item[0] == 6) {
item[6].value = this.handleValueFormulaDBPLMR(item[6], item, 6)
......@@ -1906,11 +1907,11 @@ export default class MonthlyReport extends Component {
})
// console.log(dbPL)
this.setState({ dbPL }, () => {
this.payloadPL(type)
this.payloadPL(type, trigger)
})
}
payloadPL(type) {
payloadPL(type, trigger) {
let listPL = []
this.state.dbPL.map((item, index) => {
// if (item[6].value == "" || item[6].value == 0 || item[6].value == "0.0") {
......@@ -1939,13 +1940,14 @@ export default class MonthlyReport extends Component {
// console.log(this.state.dbPL)
// this.setState({ loading: false })
console.log('tarik sis')
this.createPL()
this.createPL(trigger)
}
}
})
}
createPL() {
createPL(trigger) {
console.log(trigger);
let payload = {
// "monthly_report_id": this.state.monthlyReportId,
"company_id": this.state.company.company_id,
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment