Commit 3df18b93 authored by faisalhamdi's avatar faisalhamdi

editMasterDataCat

parent 9e2b67f2
...@@ -16,6 +16,7 @@ export default class EditMasterDataCAT extends Component { ...@@ -16,6 +16,7 @@ export default class EditMasterDataCAT extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = {
loading: true,
company: null, company: null,
parent: null, parent: null,
reportType: null, reportType: null,
...@@ -26,13 +27,15 @@ export default class EditMasterDataCAT extends Component { ...@@ -26,13 +27,15 @@ export default class EditMasterDataCAT extends Component {
listPeriode: null, listPeriode: null,
errorWeight: false, errorWeight: false,
msgErrorWeight: '', msgErrorWeight: '',
getParent: [] getParent: [],
periode: null,
created_by: '',
updated_by: ''
} }
} }
componentDidMount() { componentDidMount() {
this.getInputType() this.getInputType()
this.getPerusahaan()
this.getReportType() this.getReportType()
let date = format(new Date, 'yyyy-MM-dd') let date = format(new Date, 'yyyy-MM-dd')
this.setState({ this.setState({
...@@ -65,7 +68,7 @@ export default class EditMasterDataCAT extends Component { ...@@ -65,7 +68,7 @@ export default class EditMasterDataCAT extends Component {
if (response.data) { if (response.data) {
if (response.data.status === 'success') { if (response.data.status === 'success') {
let data = response.data.data let data = response.data.data
let comID = this.state.rawData ? this.state.rawData.company_id : 0 let comID = this.props.data[8]
let companyData = data.map((item) => { let companyData = data.map((item) => {
return { return {
company_id: item.company_id, company_id: item.company_id,
...@@ -137,8 +140,8 @@ export default class EditMasterDataCAT extends Component { ...@@ -137,8 +140,8 @@ export default class EditMasterDataCAT extends Component {
}; };
// let periode = (this.state.lastPeriod == "" ? String(Number(currentYear) + 1) : this.state.lastPeriod) // let periode = (this.state.lastPeriod == "" ? String(Number(currentYear) + 1) : this.state.lastPeriod)
let periode = String(Number(currentYear)) let periode = String(Number(currentYear))
let index = data.sort((a, b) => a - b).findIndex((val) => val === periode) let index = data.sort((a, b) => a - b).findIndex((val) => val == this.props.data[6])
// console.log(data) // console.log(this.props.data)
// console.log(this.state.latestPeriode) // console.log(this.state.latestPeriode)
// console.log(periodeData) // console.log(periodeData)
console.log(index) console.log(index)
...@@ -181,7 +184,7 @@ export default class EditMasterDataCAT extends Component { ...@@ -181,7 +184,7 @@ export default class EditMasterDataCAT extends Component {
handleReportName(item) { handleReportName(item) {
let indexString = String(item).indexOf('-') let indexString = String(item).indexOf('-')
let gantiNama = String(item).substr(0, indexString) let gantiNama = indexString === -1 ? item : String(item).substr(0, indexString)
return gantiNama return gantiNama
} }
...@@ -219,7 +222,7 @@ export default class EditMasterDataCAT extends Component { ...@@ -219,7 +222,7 @@ export default class EditMasterDataCAT extends Component {
"detail": simpan "detail": simpan
} }
console.log(payload) console.log(payload)
this.props.createReportItems(payload) this.props.updateReportItems(payload)
} }
...@@ -261,48 +264,6 @@ export default class EditMasterDataCAT extends Component { ...@@ -261,48 +264,6 @@ export default class EditMasterDataCAT extends Component {
}) })
} }
getPerusahaan() {
api.create().getPerusahaanActive().then((response) => {
// console.log(response)
if (response.data) {
if (response.ok) {
if (response.data.status === 'success') {
let data = response.data.data
let companyData = data.map((item) => {
return {
company_id: item.company_id,
company_name: item.company_name
}
})
companyData.push({
company_id: 0,
company_name: 'Default'
})
let typeProps = {
options: companyData.sort((a, b) => a.company_id - b.company_id),
getOptionLabel: (option) => option.company_name,
};
this.setState({ listCompany: typeProps, companyData: response.data.data })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Someone Logged In")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
// alert(response.data.message)
}
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
}
})
}
getReportType() { getReportType() {
api.create().getReportType().then((response) => { api.create().getReportType().then((response) => {
// console.log(response) // console.log(response)
...@@ -341,82 +302,31 @@ export default class EditMasterDataCAT extends Component { ...@@ -341,82 +302,31 @@ export default class EditMasterDataCAT extends Component {
}) })
} }
getParent() {
if (this.state.reportType !== null && this.state.company !== null) {
let payload = {
"report_id": this.state.reportType.report_id,
"company_id": this.state.company.company_id
}
api.create().getReportParent(payload).then((response) => {
// console.log(response)
if (response.data) {
if (response.ok) {
if (response.data.status === 'success') {
let data = response.data.data
let parentData = data.map((item) => {
return {
item_report_id: item.item_report_id,
description: item.description
}
})
let defaultProps = {
options: parentData,
getOptionLabel: (option) => titleCase(option.description),
};
this.setState({ listParent: defaultProps, parentData: response.data.data })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Someone Logged In")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
// alert(response.data.message)
}
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
}
})
}
}
handleDate(item) { handleDate(item) {
let value = format(item, 'dd MMMM yyyy') let value = format(item, 'dd MMMM yyyy')
return value return value
} }
getDetailMasterDataCat() { getDetailMasterDataCat() {
console.log(this.props); this.setState({ loading: true })
api.create().getDetailMasterDataCat(this.props.data[1], this.props.data[6]).then((response) => { api.create().getDetailMasterDataCat(this.props.data[8], this.props.data[6]).then((response) => {
console.log(response); // console.log(response);
if (response.data) { if (response.data) {
if (response.ok) { if (response.data.status === "success") {
if (response.data.status === 'success') { this.setState({ getParent: response.data.data.filter((val) => String(val.type_item_report_name).toLocaleLowerCase() != 'break'), created_by: response.data.data[0].created, updated_by: response.data.data[0].created_at }, () => {
let data = response.data.data // console.log(this.state.getParent[0].created);
this.setState({ this.setState({ loading: false })
tempData: response.data.data, })
getCompanyID: data.company_id
}, () => this.getInputType(),
this.getPerusahaan(),
this.getReportType())
// console.log(response.data.data)
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Someone Logged In")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' }) // alert(response.data.message)
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Someone Logged In")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
} }
} else { } else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' }) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
...@@ -437,7 +347,7 @@ export default class EditMasterDataCAT extends Component { ...@@ -437,7 +347,7 @@ export default class EditMasterDataCAT extends Component {
<div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 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="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
<div className="popup-title"> <div className="popup-title">
<span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Create Data</span> <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Edit Data</span>
</div> </div>
</div> </div>
<div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}> <div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
...@@ -464,11 +374,8 @@ export default class EditMasterDataCAT extends Component { ...@@ -464,11 +374,8 @@ export default class EditMasterDataCAT extends Component {
<Autocomplete <Autocomplete
{...this.state.listCompany} {...this.state.listCompany}
id="company" id="company"
disabled={this.state.intent === 'Home' ? true : false} onChange={(event, newInputValue) => this.setState({ company_name: newInputValue }, () => this.getParent(), this.clearMessage())}
onChange={(event, newInputValue) => this.setState({ company: newInputValue, loading: true, previewTable: false }, () => { debug
this.getReportType()
})}
disableClearable
style={{ width: 250 }} style={{ width: 250 }}
renderInput={(params) => renderInput={(params) =>
<TextField {...params} <TextField {...params}
...@@ -589,7 +496,7 @@ export default class EditMasterDataCAT extends Component { ...@@ -589,7 +496,7 @@ export default class EditMasterDataCAT extends Component {
disabled disabled
// onChange={(e) => this.handleChange(e, null)} // onChange={(e) => this.handleChange(e, null)}
// value={this.state.order} // value={this.state.order}
value={this.handleReportName(item.description)} value={this.handleReportName(item.item_report_name)}
// error={this.state.errorOrder} // error={this.state.errorOrder}
// helperText={this.state.msgErrorOrder} // helperText={this.state.msgErrorOrder}
inputProps={{ inputProps={{
...@@ -673,9 +580,11 @@ export default class EditMasterDataCAT extends Component { ...@@ -673,9 +580,11 @@ export default class EditMasterDataCAT extends Component {
<div className="margin-top-10px" style={{ paddingTop: 10, paddingBottom: 30, paddingRight: 30, paddingLeft: 30 }}> <div className="margin-top-10px" style={{ paddingTop: 10, paddingBottom: 30, paddingRight: 30, paddingLeft: 30 }}>
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
<Typography style={{ fontSize: 11, width: '13%' }}>Created By :</Typography> <Typography style={{ fontSize: 11, width: '13%' }}>Created By :</Typography>
{!this.state.loading && <Typography style={{ fontSize: 11 }}>: {this.state.created_by}</Typography>}
</div> </div>
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
<Typography style={{ fontSize: 11, width: '13%' }}>Updated By :</Typography> <Typography style={{ fontSize: 11, width: '13%' }}>Updated By :</Typography>
{!this.state.loading && <Typography style={{ fontSize: 11 }}>: {this.state.updated_by}</Typography>}
</div> </div>
</div> </div>
</div> </div>
......
...@@ -722,7 +722,7 @@ export default class MasterDataCAT extends Component { ...@@ -722,7 +722,7 @@ export default class MasterDataCAT extends Component {
} }
createReportItems = (payload) => { createReportItems = (payload) => {
this.setState({ add: false }) this.setState({ add: false, edit: false })
api.create().saveMasterDataCat(payload).then(response => { api.create().saveMasterDataCat(payload).then(response => {
// console.log(response); // console.log(response);
if (response.data) { if (response.data) {
...@@ -781,33 +781,6 @@ export default class MasterDataCAT extends Component { ...@@ -781,33 +781,6 @@ export default class MasterDataCAT extends Component {
} }
} }
// updateReportItems = (payload) => {
// this.setState({ edit: false })
// api.create().updateReportItems(payload).then(response => {
// if (response.data) {
// if (response.ok) {
// if (response.data.status == 'success') {
// this.getData()
// this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
// } else {
// this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
// if (response.data.message.includes("Someone Logged In")) {
// setTimeout(() => {
// localStorage.removeItem(Constant.TOKEN)
// window.location.reload();
// }, 1000);
// }
// })
// }
// } else {
// this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
// }
// } else {
// this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
// }
// })
// }
uploadReportItems() { uploadReportItems() {
api.create().uploadReportItems(this.state.payload).then(response => { api.create().uploadReportItems(this.state.payload).then(response => {
if (response.data) { if (response.data) {
......
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