Commit 3df18b93 authored by faisalhamdi's avatar faisalhamdi

editMasterDataCat

parent 9e2b67f2
......@@ -16,6 +16,7 @@ export default class EditMasterDataCAT extends Component {
constructor(props) {
super(props)
this.state = {
loading: true,
company: null,
parent: null,
reportType: null,
......@@ -26,13 +27,15 @@ export default class EditMasterDataCAT extends Component {
listPeriode: null,
errorWeight: false,
msgErrorWeight: '',
getParent: []
getParent: [],
periode: null,
created_by: '',
updated_by: ''
}
}
componentDidMount() {
this.getInputType()
this.getPerusahaan()
this.getReportType()
let date = format(new Date, 'yyyy-MM-dd')
this.setState({
......@@ -65,7 +68,7 @@ export default class EditMasterDataCAT extends Component {
if (response.data) {
if (response.data.status === 'success') {
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) => {
return {
company_id: item.company_id,
......@@ -137,8 +140,8 @@ export default class EditMasterDataCAT extends Component {
};
// let periode = (this.state.lastPeriod == "" ? String(Number(currentYear) + 1) : this.state.lastPeriod)
let periode = String(Number(currentYear))
let index = data.sort((a, b) => a - b).findIndex((val) => val === periode)
// console.log(data)
let index = data.sort((a, b) => a - b).findIndex((val) => val == this.props.data[6])
// console.log(this.props.data)
// console.log(this.state.latestPeriode)
// console.log(periodeData)
console.log(index)
......@@ -181,7 +184,7 @@ export default class EditMasterDataCAT extends Component {
handleReportName(item) {
let indexString = String(item).indexOf('-')
let gantiNama = String(item).substr(0, indexString)
let gantiNama = indexString === -1 ? item : String(item).substr(0, indexString)
return gantiNama
}
......@@ -219,7 +222,7 @@ export default class EditMasterDataCAT extends Component {
"detail": simpan
}
console.log(payload)
this.props.createReportItems(payload)
this.props.updateReportItems(payload)
}
......@@ -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() {
api.create().getReportType().then((response) => {
// console.log(response)
......@@ -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) {
let value = format(item, 'dd MMMM yyyy')
return value
}
getDetailMasterDataCat() {
console.log(this.props);
api.create().getDetailMasterDataCat(this.props.data[1], this.props.data[6]).then((response) => {
console.log(response);
this.setState({ loading: true })
api.create().getDetailMasterDataCat(this.props.data[8], this.props.data[6]).then((response) => {
// console.log(response);
if (response.data) {
if (response.ok) {
if (response.data.status === 'success') {
let data = response.data.data
this.setState({
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);
}
})
}
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 }, () => {
// console.log(this.state.getParent[0].created);
this.setState({ loading: false })
})
} 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 {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
......@@ -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="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
<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 className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
......@@ -464,11 +374,8 @@ export default class EditMasterDataCAT extends Component {
<Autocomplete
{...this.state.listCompany}
id="company"
disabled={this.state.intent === 'Home' ? true : false}
onChange={(event, newInputValue) => this.setState({ company: newInputValue, loading: true, previewTable: false }, () => {
this.getReportType()
})}
disableClearable
onChange={(event, newInputValue) => this.setState({ company_name: newInputValue }, () => this.getParent(), this.clearMessage())}
debug
style={{ width: 250 }}
renderInput={(params) =>
<TextField {...params}
......@@ -589,7 +496,7 @@ export default class EditMasterDataCAT extends Component {
disabled
// onChange={(e) => this.handleChange(e, null)}
// value={this.state.order}
value={this.handleReportName(item.description)}
value={this.handleReportName(item.item_report_name)}
// error={this.state.errorOrder}
// helperText={this.state.msgErrorOrder}
inputProps={{
......@@ -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 style={{ display: 'flex' }}>
<Typography style={{ fontSize: 11, width: '13%' }}>Created By :</Typography>
{!this.state.loading && <Typography style={{ fontSize: 11 }}>: {this.state.created_by}</Typography>}
</div>
<div style={{ display: 'flex' }}>
<Typography style={{ fontSize: 11, width: '13%' }}>Updated By :</Typography>
{!this.state.loading && <Typography style={{ fontSize: 11 }}>: {this.state.updated_by}</Typography>}
</div>
</div>
</div>
......
......@@ -722,7 +722,7 @@ export default class MasterDataCAT extends Component {
}
createReportItems = (payload) => {
this.setState({ add: false })
this.setState({ add: false, edit: false })
api.create().saveMasterDataCat(payload).then(response => {
// console.log(response);
if (response.data) {
......@@ -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() {
api.create().uploadReportItems(this.state.payload).then(response => {
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