Commit 76f099bd authored by Riri Novita's avatar Riri Novita

simulasi RO PL

parent 56ded309
......@@ -87,7 +87,8 @@ export default class ProfitLossROO extends Component {
viewOnly: true,
get_for: 'view',
defaultCurrencyUpload: this.props.defaultCurrency,
visibleAlertSave: false
visibleAlertSave: false,
visibleButtonUpload: false
}
this.fileHandler = this.fileHandler.bind(this);
......@@ -591,14 +592,106 @@ export default class ProfitLossROO extends Component {
})
}
uploadSimulasi() {
checkUploadSimulasi() {
let payload = {
...this.state.payload,
currency_id: this.state.defaultCurrencyUpload?.id
}
api.create().checkImportRollingOutlookPL(payload).then(response => {
// console.log(JSON.stringify(this.state.payload));
console.log("checkUpload Response", response)
if (response.data) {
if (response.data.status === 'success') {
this.setState({ visibleUpload: false, visiblePLRO: false, loading: true, visibleButtonUpload: true })
let dataTable = response.data.data.map((item, index) => {
return [
item.type_report_id,
item.item_report_id,
item.parent,
item.formula,
item.level,
item.item_report,
item.notes,
item.last_year_total === "" ? "0" : item.last_year_total,
item.january === "" ? "0" : item.january,
item.february === "" ? "0" : item.february,
item.march === "" ? "0" : item.march,
item.april === "" ? "0" : item.april,
item.may === "" ? "0" : item.may,
item.june === "" ? "0" : item.june,
item.july === "" ? "0" : item.july,
item.august === "" ? "0" : item.august,
item.september === "" ? "0" : item.september,
item.october === "" ? "0" : item.october,
item.november === "" ? "0" : item.november,
item.december === "" ? "0" : item.december,
item.current_year_total === "" ? "0" : item.current_year_total,
"",
item.order,
]
})
this.setState({ dataTable, dataLoaded: true, loading: false, buttonError: false }, () => {
this.state.dataTable.map(item => {
// if (item[24].length > 0) {
// // console.log('masuk')
// this.setState({ buttonError: true, errorPreview: true })
// }
})
// console.log(this.state.buttonError)
})
console.log("checkUpload DataTable", dataTable);
} 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);
}
})
}
}
})
}
uploadSimulasi(type) {
let data = []
this.state.dataTable.map(i => {
data.push({
"item_report_id": i[1],
"item_report": i[5],
"notes": String(i[6]),
"last_year_total": String(Number(i[7]).toFixed(1)),
"january": String(Number(i[8]).toFixed(1)),
"february": String(Number(i[9]).toFixed(1)),
"march": String(Number(i[10]).toFixed(1)),
"april": String(Number(i[11]).toFixed(1)),
"may": String(Number(i[12]).toFixed(1)),
"june": String(Number(i[13]).toFixed(1)),
"july": String(Number(i[14]).toFixed(1)),
"august": String(Number(i[15]).toFixed(1)),
"september": String(Number(i[16]).toFixed(1)),
"october": String(Number(i[17]).toFixed(1)),
"november": String(Number(i[18]).toFixed(1)),
"december": String(Number(i[19]).toFixed(1)),
"current_year_total": String(Number(i[20]).toFixed(1)),
})
})
console.log("uploadProfitLossRO Data", data)
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,
"currency_id": this.state.defaultCurrencyUpload?.id,
"quartal": this.props.quarter,
"rolling_outlook_id": this.props.rollingOutlookID,
"status": type,
"profit_loss": data
}
this.setState({ loading: true, dataTable: [] })
console.log(payload)
api.create().uploadSimulasiROPL(payload).then(response => {
console.log(body)
api.create().uploadSimulasiROPL(body).then(response => {
console.log(response)
if (response.data) {
if (response.ok) {
......@@ -2407,22 +2500,6 @@ export default class ProfitLossROO extends Component {
}
</div>
<div style={{ width: '50%' }}>
<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: 15
}}
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' }}>
......@@ -2448,6 +2525,20 @@ export default class ProfitLossROO extends Component {
// </div>
:
<div style={{ justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
<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" />
<a data-tip={'Download Template'} data-for="template">
<button
style={{
......@@ -2478,7 +2569,7 @@ export default class ProfitLossROO extends Component {
</button>
</a>
<ReactTooltip border={true} id="upload" place="bottom" type="light" effect="solid" />
<a data-tip={'Download'} data-for="download">
{/* <a data-tip={'Download'} data-for="download">
<button
style={{
backgroundColor: 'transparent',
......@@ -2494,12 +2585,11 @@ export default class ProfitLossROO extends Component {
<img src={Images.download} />
</button>
</a>
<ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
<ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" /> */}
</div>
}
</div>
</div>
</div>
<div style={{ marginTop: 20, width: this.props.width - (this.props.open === true ? 400 : 150) }}>
{!this.state.refresh && (
......@@ -2849,12 +2939,37 @@ export default class ProfitLossROO extends Component {
}}
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.checkUploadSimulasi() :
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>
{this.state.visibleButtonUpload &&
<div style={{ display: 'flex', justifyContent: 'flex-end', margin: '0px 32px 16px' }}>
<div>
<button
type="button"
// disabled={this.state.buttonError}
onClick={() =>
this.setState({ handleDoubleClick: 1, loading: true }, () => {
this.uploadSimulasi('submitted')
})}
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' }}>
<Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Save Data</Typography>
</div>
</button>
</div>
</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>
)}
......
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