Commit 61b32313 authored by EKSAD's avatar EKSAD

solve issue report item

parent 0f26e4a6
......@@ -53,6 +53,7 @@ export default class ReportItems extends Component {
fileHandler = (event) => {
let fileObj = event
ExcelRenderer(fileObj, (err, resp) => {
// console.log(resp)
if (err) {
console.log(err);
}
......@@ -82,397 +83,400 @@ export default class ReportItems extends Component {
let body = {
item_report: payload
}
// console.log(JSON.stringify(body))
console.log(resp.rows[1])
this.setState({ payload: body, buttonError: false, judul: resp.rows[1][0] })
api.create().checkUploadReportItems(body).then(response => {
console.log(response)
let dataRow = []
if (response.data) {
if (response.ok) {
if (response.data.status === "success") {
dataRow = response.data.data.map((item, index) => {
return [
index + 1,
item.report,
item.company,
item.orders,
item.description,
item.parent,
item.uom,
item.weight,
item.type_report,
item.formula,
item.condition_it_should_be,
item.condition_if_wrong,
item.start_date,
item.end_date,
item.error
]
})
let columns = [
"Data",
{
name: "Report Type",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('report'))
if (check > -1) {
this.setState({ buttonError: true })
}
}
});
}
checkUpload(){
api.create().checkUploadReportItems(this.state.payload).then(response => {
console.log(response)
let dataRow = []
if (response.data) {
if (response.ok) {
if (response.data.status === "success") {
dataRow = response.data.data.map((item, index) => {
return [
index + 1,
item.report,
item.company,
item.orders,
item.description,
item.parent,
item.uom,
item.weight,
item.type_report,
item.formula,
item.condition_it_should_be,
item.condition_if_wrong,
item.start_date,
item.end_date,
item.error
]
})
let columns = [
"Data",
{
name: "Report Type",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('report'))
if (check > -1) {
this.setState({ buttonError: true })
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="reportname">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="reportname" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Company Name",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('company'))
if (check > -1) {
this.setState({ buttonError: true })
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="reportname">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="reportname" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Company Name",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('company'))
if (check > -1) {
this.setState({ buttonError: true })
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="companyname">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="companyname" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Order",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('orders'))
if (check > -1) {
this.setState({ buttonError: true })
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="companyname">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="companyname" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Order",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('orders'))
if (check > -1) {
this.setState({ buttonError: true })
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="order">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="order" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Description",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('description'))
if (check > -1) {
this.setState({ buttonError: true })
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="order">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="order" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Description",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('description'))
if (check > -1) {
this.setState({ buttonError: true })
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="desc">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="desc" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Parent ID",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('parent'))
if (check > -1) {
this.setState({ buttonError: true })
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="desc">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="desc" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Parent ID",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('parent'))
if (check > -1) {
this.setState({ buttonError: true })
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="parents">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="parents" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "UOM",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('uom'))
if (check > -1) {
this.setState({ buttonError: true })
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="parents">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="parents" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "UOM",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('uom'))
if (check > -1) {
this.setState({ buttonError: true })
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="uoms">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="uoms" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Weight",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('weight'))
if (check > -1) {
this.setState({ buttonError: true })
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="uoms">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="uoms" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Weight",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('weight'))
if (check > -1) {
this.setState({ buttonError: true })
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="weights">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="weights" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Data Type",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('type_report'))
if (check > -1) {
this.setState({ buttonError: true })
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="weights">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="weights" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Data Type",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('type_report'))
if (check > -1) {
this.setState({ buttonError: true })
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="datatype">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="datatype" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Formula",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('formula'))
if (check > -1) {
this.setState({ buttonError: true })
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="datatype">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="datatype" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Formula",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('formula'))
if (check > -1) {
this.setState({ buttonError: true })
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="formulas">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="formulas" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "True Value",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('condition_it_should_be'))
if (check > -1) {
this.setState({ buttonError: true })
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="formulas">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="formulas" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "True Value",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('condition_it_should_be'))
if (check > -1) {
this.setState({ buttonError: true })
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="values">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="values" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "False Condition",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('condition_if_wrong'))
if (check > -1) {
this.setState({ buttonError: true })
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="values">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="values" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "False Condition",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('condition_if_wrong'))
if (check > -1) {
this.setState({ buttonError: true })
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="conditions">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="conditions" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Valid From",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('start_date'))
if (check > -1) {
this.setState({ buttonError: true })
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="conditions">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="conditions" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Valid From",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('start_date'))
if (check > -1) {
this.setState({ buttonError: true })
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="startdate">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="startdate" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Valid To",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('end_date'))
if (check > -1) {
this.setState({ buttonError: true })
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="startdate">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="startdate" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "Valid To",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[14] != null) {
check = tableMeta.rowData[14].findIndex((val) => val.field.includes('end_date'))
if (check > -1) {
this.setState({ buttonError: true })
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="enddate">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="enddate" place="bottom" type="light" effect="solid" />
</div >
);
}
}
},
{
name: "",
options: {
display: false
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[14] != null && check > -1 ?
<a data-tip={tableMeta.rowData[14][check].message} data-for="enddate">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="enddate" place="bottom" type="light" effect="solid" />
</div >
);
}
}
]
console.log(dataRow);
this.setState({
dataLoaded: true,
cols: columns,
rows: dataRow
});
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Token")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
},
{
name: "",
options: {
display: false
}
})
}
}
]
// console.log(dataRow);
this.setState({
dataLoaded: true,
cols: columns,
rows: dataRow, visibleUpload: false,
itemReport: false
});
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Token")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({
dataLoaded: false,
alert: true, messageAlert: response.problem, tipeAlert: 'error' })
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
}
console.log(response);
})
} else {
this.setState({
dataLoaded: false,
alert: true, messageAlert: response.problem, tipeAlert: 'error'
});
}
});
})
}
componentDidMount() {
......@@ -1057,7 +1061,7 @@ export default class ReportItems extends Component {
}}
onUpload={() => {
this.state.judul === "MASTER DATA - REPORT ITEMS" ?
this.setState({ visibleUpload: false, itemReport: false }) :
this.checkUpload() :
this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning'})
}}
......
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