Commit 016f707e authored by Riri Novita's avatar Riri Novita

RO simulasi

parent cf63463e
......@@ -91,6 +91,7 @@ export default class ProfitLossROO extends Component {
}
this.fileHandler = this.fileHandler.bind(this);
this.fileHandlerSimulasi = this.fileHandlerSimulasi.bind(this);
}
componentDidMount() {
......@@ -478,6 +479,56 @@ export default class ProfitLossROO extends Component {
});
}
fileHandlerSimulasi = (event) => {
let fileObj = event
ExcelRenderer(fileObj, (err, resp) => {
console.log(resp)
if (err) {
console.log(err);
}
else {
let isi = resp.rows.slice(3)
// console.log(resp.rows[2]);
let payload = []
let reg = /^[-+]?(?:[0-9]+,)*[0-9]+(?:\.[0-9]+)?$/;
isi.map((i, index) => {
if (i.length > 0) {
payload.push({
orders: i[0] === undefined ? "" : String(i[0]).trim(),
"item_report_id": i[1] === undefined ? 0 : i[1],
"item_report": i[2] === undefined ? "" : String(i[2]).trim(),
"notes": i[3] === undefined ? "" : reg.test(String(i[3])) === false ? "" : String(i[3]).trim(),
"january": i[5] === undefined ? "0" : reg.test(String(fixNumber(Number(i[5]), 1))) === false ? "0" : String(fixNumber(Number(i[5]), 1)).trim(),
"february": i[6] === undefined ? "0" : reg.test(String(fixNumber(Number(i[6]), 1))) === false ? "0" : String(fixNumber(Number(i[6]), 1)).trim(),
"march": i[7] === undefined ? "0" : reg.test(String(fixNumber(Number(i[7]), 1))) === false ? "0" : String(fixNumber(Number(i[7]), 1)).trim(),
"april": i[8] === undefined ? "0" : reg.test(String(fixNumber(Number(i[8]), 1))) === false ? "0" : String(fixNumber(Number(i[8]), 1)).trim(),
"may": i[9] === undefined ? "0" : reg.test(String(fixNumber(Number(i[9]), 1))) === false ? "0" : String(fixNumber(Number(i[9]), 1)).trim(),
"june": i[10] === undefined ? "0" : reg.test(String(fixNumber(Number(i[10]), 1))) === false ? "0" : String(fixNumber(Number(i[10]), 1)).trim(),
"july": i[11] === undefined ? "0" : reg.test(String(fixNumber(Number(i[11]), 1))) === false ? "0" : String(fixNumber(Number(i[11]), 1)).trim(),
"august": i[12] === undefined ? "0" : reg.test(String(fixNumber(Number(i[12]), 1))) === false ? "0" : String(fixNumber(Number(i[12]), 1)).trim(),
"september": i[13] === undefined ? "0" : reg.test(String(fixNumber(Number(i[13]), 1))) === false ? "0" : String(fixNumber(Number(i[13]), 1)).trim(),
"october": i[14] === undefined ? "0" : reg.test(String(fixNumber(Number(i[14]), 1))) === false ? "0" : String(fixNumber(Number(i[14]), 1)).trim(),
"november": i[15] === undefined ? "0" : reg.test(String(fixNumber(Number(i[15]), 1))) === false ? "0" : String(fixNumber(Number(i[15]), 1)).trim(),
"december": i[16] === undefined ? "0" : reg.test(String(fixNumber(Number(i[16]), 1))) === false ? "0" : String(fixNumber(Number(i[16]), 1)).trim(),
})
}
})
console.log("fileHandler payload", payload)
let body = {
company_id: this.props.company.company_id,
periode: this.props.periode,
report_id: this.props.report_id,
quartal: this.props.quarter,
rolling_outlook_id: this.props.rollingOutlookID,
status: 'submitted',
profit_loss: payload
}
console.log("fileHandler body", body)
this.setState({ payload: body, judul: resp.rows[1][0], judulColumn: resp.rows[0][0] })
}
});
}
checkUpload() {
let payload = {
...this.state.payload,
......@@ -540,6 +591,33 @@ export default class ProfitLossROO 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()
this.props.refresh('PL', 'simulasiPL')
this.setState({ loading: false })
} 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 })
}
})
}
uploadProfitLossRO(type) {
let data = []
this.state.dataTable.map(i => {
......@@ -2329,80 +2407,97 @@ export default class ProfitLossROO extends Component {
}
</div>
<div style={{ width: '50%' }}>
{this.props.isApprover === true || this.state.get_for == 'view' ?
null
// <div style={{ justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
// <a data-tip={'Download'} data-for="download">
// <button
// style={{
// backgroundColor: 'transparent',
// cursor: 'pointer',
// borderColor: 'transparent',
// margin: 5
// }}
// onClick={() =>
// this.setState({ loading: true }, () => {
// setTimeout(() => {
// this.downloadAllData()
// }, 100);
// })}
// >
// <img src={Images.download} />
// </button>
// </a>
// <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
// </div>
:
<div style={{ justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
<a data-tip={'Download Template'} data-for="template">
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
margin: 5
}}
onClick={() => this.setState({ loading: true }, () => {
this.downloadTemplate()
})}
>
<img src={Images.template} />
</button>
</a>
<ReactTooltip border={true} id="template" place="bottom" type="light" effect="solid" />
<a data-tip={'Upload'} data-for="upload">
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
margin: 5
}}
onClick={() => this.setState({ visibleUpload: true })}
>
<img src={Images.upload} />
</button>
</a>
<ReactTooltip border={true} id="upload" place="bottom" type="light" effect="solid" />
<a data-tip={'Download'} data-for="download">
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
margin: 5
}}
onClick={() =>
this.setState({ loading: true }, () => {
this.downloadAllData()
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
<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.props.isApprover === true || this.state.get_for == 'view' ?
null
// <div style={{ justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
// <a data-tip={'Download'} data-for="download">
// <button
// style={{
// backgroundColor: 'transparent',
// cursor: 'pointer',
// borderColor: 'transparent',
// margin: 5
// }}
// onClick={() =>
// this.setState({ loading: true }, () => {
// setTimeout(() => {
// this.downloadAllData()
// }, 100);
// })}
// >
// <img src={Images.download} />
// </button>
// </a>
// <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
// </div>
:
<div style={{ justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
<a data-tip={'Download Template'} data-for="template">
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
margin: 5
}}
onClick={() => this.setState({ loading: true }, () => {
this.downloadTemplate()
})}
>
<img src={Images.download} />
</button>
</a>
<ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
</div>
}
>
<img src={Images.template} />
</button>
</a>
<ReactTooltip border={true} id="template" place="bottom" type="light" effect="solid" />
<a data-tip={'Upload'} data-for="upload">
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
margin: 5
}}
onClick={() => this.setState({ visibleUpload: true })}
>
<img src={Images.upload} />
</button>
</a>
<ReactTooltip border={true} id="upload" place="bottom" type="light" effect="solid" />
<a data-tip={'Download'} data-for="download">
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
margin: 5
}}
onClick={() =>
this.setState({ loading: true }, () => {
this.downloadAllData()
})}
>
<img src={Images.download} />
</button>
</a>
<ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
</div>
}
</div>
</div>
</div>
......@@ -2722,6 +2817,48 @@ export default class ProfitLossROO extends Component {
</div>
)}
{this.state.visibleUploadSimulasi && (
// alert("Coming Soon...")
<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("ROLLING") && String(this.state.judul).includes("OUTLOOK") && String(this.state.judul).includes("PROFIT") && String(this.state.judul).includes("LOSS") ?
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 }}>
......
......@@ -606,7 +606,7 @@ export default class RollingOutlook extends Component {
})
}
getRollingOutlookID(type) {
getRollingOutlookID(type, trigger) {
this.setState({ loading: true })
let payload = {
"company_id": this.state.company.company_id,
......@@ -653,7 +653,7 @@ export default class RollingOutlook extends Component {
this.getLatestPeriodSubmit()
if (type != undefined && type == 'PL') {
// this.getCashFlow(type)
this.getPL(type)
this.getPL(type, trigger)
} else if (type != undefined && type == 'BS') {
let bodyRatioBs = {
"report": 'ratio',
......@@ -1017,7 +1017,7 @@ export default class RollingOutlook extends Component {
}
}
getPL(type) {
getPL(type, trigger) {
let PLID = null
let payloadID = {
"periode": this.state.periode.periode,
......@@ -1128,7 +1128,7 @@ export default class RollingOutlook extends Component {
})
// console.log(dataTable)
this.setState({ dbPL: dataTable }, () => {
this.olahDataPL(this.state.dbPL, type)
this.olahDataPL(this.state.dbPL, type, trigger)
})
} else {
this.setState({ dbPL: [], previewTable: false, previewDownload: false })
......@@ -1367,7 +1367,7 @@ export default class RollingOutlook extends Component {
return total
}
olahDataPL(dbPL, type) {
olahDataPL(dbPL, type, trigger) {
dbPL.map((item, index) => {
if (item[0] == 5 || item[0] == 6 || item[0] == 7) {
item[7].value = this.handleValueFormulaDBPL(index, item[7], item, 7)
......@@ -1387,11 +1387,11 @@ export default class RollingOutlook extends Component {
}
})
this.setState({ dbPL }, () => {
this.payloadPL(type)
this.payloadPL(type, trigger)
})
}
payloadPL(type) {
payloadPL(type, trigger) {
let listPL = []
// console.log(this.state.dbPL)
this.state.dbPL.map((item, index) => {
......@@ -1486,13 +1486,13 @@ export default class RollingOutlook extends Component {
if (type != undefined) {
if (type == 'PL') {
console.log('tarik sis')
this.createDBPL()
this.createDBPL(trigger)
}
}
})
}
createDBPL() {
createDBPL(trigger) {
let payload = {
// "submission_id": this.state.submissionID,
"company_id": this.state.company.company_id,
......@@ -1506,10 +1506,14 @@ export default class RollingOutlook extends Component {
}
console.log(this.state.dbPL)
// console.log(JSON.stringify(payload))
api.create().createDBPLRO(payload).then((res) => {
console.log(res)
this.setState({ loading: false })
})
if (trigger === 'simulasiPL') {
} else {
api.create().createDBPLRO(payload).then((res) => {
console.log(res)
this.setState({ loading: false })
})
}
}
handleApproveAdmin() {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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