Commit aa9e3d12 authored by Riri Novita's avatar Riri Novita

Update Simulasi MB

parent 62587f66
...@@ -48,7 +48,6 @@ class Login extends Component { ...@@ -48,7 +48,6 @@ class Login extends Component {
componentDidMount() { componentDidMount() {
this.getUser() this.getUser()
var email = localStorage.getItem(Constant.EMAIL) var email = localStorage.getItem(Constant.EMAIL)
console.log(email)
} }
getWindowDimensions() { getWindowDimensions() {
...@@ -112,6 +111,7 @@ class Login extends Component { ...@@ -112,6 +111,7 @@ class Login extends Component {
} else { } else {
localStorage.setItem(Constant.TOKEN, datas.token) localStorage.setItem(Constant.TOKEN, datas.token)
localStorage.setItem(Constant.USER, datas.user_id) localStorage.setItem(Constant.USER, datas.user_id)
localStorage.setItem(Constant.ROLE, datas.role_id)
if (this.state.rememberMe) { if (this.state.rememberMe) {
localStorage.setItem(Constant.EMAIL, this.state.email) localStorage.setItem(Constant.EMAIL, this.state.email)
localStorage.setItem(Constant.PASSWORD, this.state.password) localStorage.setItem(Constant.PASSWORD, this.state.password)
......
This diff is collapsed.
...@@ -65,7 +65,8 @@ export default class ProfitLoss extends Component { ...@@ -65,7 +65,8 @@ export default class ProfitLoss extends Component {
handleDoubleClick: 0, handleDoubleClick: 0,
fromUpload: false, fromUpload: false,
defaultCurrencyUpload: this.props.defaultCurrency, defaultCurrencyUpload: this.props.defaultCurrency,
visibleAlertSave: false visibleAlertSave: false,
visibleButtonUpload: false
} }
this.handleValue = this.handleValue.bind(this) this.handleValue = this.handleValue.bind(this)
this.fileHandler = this.fileHandler.bind(this); this.fileHandler = this.fileHandler.bind(this);
...@@ -475,27 +476,105 @@ export default class ProfitLoss extends Component { ...@@ -475,27 +476,105 @@ export default class ProfitLoss extends Component {
}) })
} }
uploadSimulasi() { checkUploadSimulasi() {
let payload = { let payload = {
...this.state.payload, ...this.state.payload,
currency_id: this.state.defaultCurrencyUpload?.id currency_id: this.state.defaultCurrencyUpload?.id
} }
this.setState({ loading: true, dataTable: [] }) api.create().checkUploadMB(payload).then(response => {
// let dataDelete = this.state.dataDelete // console.log(JSON.stringify(this.state.payload));
// api.create().getIdDeleteFromExcel(payload).then((response) => { console.log(response)
// if (response.data) { if (response.data) {
// // // // // // console.log(response.data) if (response.data.status === 'success') {
// let idDelete = response.data.data.item_report_id this.setState({ visibleUpload: false, visibleProfitLoss: false, loading: true, visibleButtonUpload: true })
// if (idDelete.length > 0) { let dataTable = response.data.data.map((item, index) => {
// idDelete.map((item, index) => { return [
// dataDelete.push(item) item.type_report_id,
// }) item.item_report_id,
// this.setState({ dataDelete }) item.parent,
// } item.formula,
// } item.level,
// }) item.item_report,
console.log(payload) item.notes,
api.create().uploadSimulasiMB(payload).then(response => { Number(item.total_actual_before).toFixed(1),
Number(item.january).toFixed(1),
Number(item.february).toFixed(1),
Number(item.march).toFixed(1),
Number(item.april).toFixed(1),
Number(item.may).toFixed(1),
Number(item.june).toFixed(1),
Number(item.july).toFixed(1),
Number(item.august).toFixed(1),
Number(item.september).toFixed(1),
Number(item.october).toFixed(1),
Number(item.november).toFixed(1),
Number(item.december).toFixed(1),
Number(item.total_current_year).toFixed(1),
Number(item.total_next_year).toFixed(1),
Number(item.total_more_year).toFixed(1),
item.orders,
item.error
]
})
this.setState({ dataTable, dataLoaded: true, loading: false, buttonError: false, editable: true, fromUpload: true }, () => {
this.state.dataTable.map(item => {
if (item[24].length > 0) {
// console.log('masuk')
this.setState({ buttonError: true, errorPreview: true, editable: true })
}
})
// console.log(this.state.buttonError)
})
} 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],
notes: String(i[6]),
total_actual_before: 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)),
total_current_year: String(Number(i[20]).toFixed(1)),
total_next_year: String(Number(i[21]).toFixed(1)),
total_more_year: String(Number(i[22]).toFixed(1)),
})
})
let body = {
submission_id: this.props.submissionID,
company_id: this.props.company.company_id,
periode: this.props.periode,
report_id: this.props.report_id,
currency_id: this.state.defaultCurrencyUpload?.id,
profit_loss: data,
status: type
}
console.log(body)
api.create().uploadSimulasiMB(body).then(response => {
console.log(response) console.log(response)
if (response.data) { if (response.data) {
if (response.ok) { if (response.ok) {
...@@ -3419,13 +3498,37 @@ export default class ProfitLoss extends Component { ...@@ -3419,13 +3498,37 @@ export default class ProfitLoss extends Component {
}} }}
onUpload={() => { onUpload={() => {
String(this.state.judul).includes("MASTER") && String(this.state.judul).includes("BUDGET") && String(this.state.judul).includes("PROFIT") && String(this.state.judul).includes("LOSS") ? String(this.state.judul).includes("MASTER") && String(this.state.judul).includes("BUDGET") && 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' }) this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning' })
}} }}
/> />
</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> {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>
</div> </div>
)} )}
......
This diff is collapsed.
const Constant = { const Constant = {
TOKEN: null, TOKEN: null,
USER: 0, USER: 0,
ROLE: 'role_id',
EMAIL: 'TOKEN', EMAIL: 'TOKEN',
PASSWORD: 'PASSWORD', PASSWORD: 'PASSWORD',
URL_BE_DEV: '${process.env.REACT_APP_URL_MAIN_BE}', URL_BE_DEV: '${process.env.REACT_APP_URL_MAIN_BE}',
......
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