Commit 9ab9eaed authored by Faisal Hamdi's avatar Faisal Hamdi

Merge branch 'faisal' into 'master'

handlePercent

See merge request !1073
parents f8011e9e a5394968
......@@ -1339,25 +1339,44 @@ export default class SubHolding extends Component {
}
})
} else if (this.state.report.value === 7) {
let payload = {
"report_id": 2,
"company_id": this.state.company.company_id,
"periode": this.state.periode.periode,
"months": this.state.month.month_id,
"revision": this.state.revisionType,
"quarter": 0,
"submission_id": this.state.submissionID
}
api.create().getReportBSSuma(payload).then(response => {
console.log(payload);
let dbSumaBS = []
let payloadBS = {...payload, report_id: 2, months: this.state.month.month_id, quarter: 0}
api.create().getReportBSSuma(payloadBS).then(response => {
// console.log(payloadBS);
console.log(response);
let dataTable = []
if (response.data) {
if (response.data.status === 'success') {
let res = response.data.data
const handlePushChild = (item) => {
let indexIDzz = dataTable.findIndex((val) => val[1] === item.id)
let indexIDzz = dbSumaBS.findIndex((val) => val[1] === item.id)
if (indexIDzz === -1) {
dataTable.push([
let mtd_actual = item.balance_sheet.mtd_actual == '' ? 0 : item.balance_sheet.mtd_actual
let mtd_ol = item.balance_sheet.mtd_ol == '' ? 0 : item.balance_sheet.mtd_ol
let mtd_mb = item.balance_sheet.mtd_mb == '' ? 0 : item.balance_sheet.mtd_mb
let persenMtd = 0
let persenOL = 0
if (mtd_mb < 0) {
if (mtd_actual < mtd_mb) {
persenMtd = Number((mtd_mb - mtd_actual)/mtd_mb)
} else {
persenMtd = Number((mtd_mb - mtd_actual)/mtd_mb) + 1
}
} else {
persenMtd = Number(mtd_actual/mtd_mb)
}
if (mtd_ol < 0) {
if (mtd_actual < mtd_ol) {
persenOL = Number((mtd_ol - mtd_actual)/mtd_ol)
} else {
persenOL = Number((mtd_ol - mtd_actual)/mtd_ol) + 1
}
} else {
persenOL = Number(mtd_actual/mtd_ol)
}
dbSumaBS.push([
item.type_report_id,
item.id,
item.parent,
......@@ -1367,9 +1386,9 @@ export default class SubHolding extends Component {
item.balance_sheet.mtd_last_month,
item.balance_sheet.mtd_actual,
item.balance_sheet.mtd_mb,
item.balance_sheet.percent_of_mb,
isNaN(persenMtd) || persenMtd == 'Infinity' || persenMtd == '-Infinity' ? (item.balance_sheet.mtd_mb == '' || item.balance_sheet.mtd_mb == 0 ? -0 : 0) : (item.balance_sheet.mtd_mb == '' || item.balance_sheet.mtd_mb == 0 ? persenMtd * -100 : persenMtd * 100),
item.balance_sheet.mtd_ol,
item.balance_sheet.percent_of_ol,
isNaN(persenOL) || persenOL == 'Infinity' || persenOL == '-Infinity' ? (item.balance_sheet.mtd_ol == '' || item.balance_sheet.mtd_ol == 0 ? -0 : 0) : (item.balance_sheet.mtd_ol == '' || item.balance_sheet.mtd_ol == 0 ? persenOL * -100 : persenOL * 100),
item.balance_sheet.mtd_last_year,
item.balance_sheet.forecast_next_year,
item.balance_sheet.forecast_more_year,
......@@ -1385,7 +1404,33 @@ export default class SubHolding extends Component {
}
}
res.map((item, index) => {
dataTable.push([
let mtd_actual = item.balance_sheet.mtd_actual == '' ? 0 : item.balance_sheet.mtd_actual
let mtd_ol = item.balance_sheet.mtd_ol == '' ? 0 : item.balance_sheet.mtd_ol
let mtd_mb = item.balance_sheet.mtd_mb == '' ? 0 : item.balance_sheet.mtd_mb
let persenMtd = 0
let persenOL = 0
if (mtd_mb < 0) {
if (mtd_actual < mtd_mb) {
persenMtd = Number((mtd_mb - mtd_actual)/mtd_mb)
} else {
persenMtd = Number((mtd_mb - mtd_actual)/mtd_mb) + 1
}
} else {
persenMtd = Number(mtd_actual/mtd_mb)
}
if (mtd_ol < 0) {
if (mtd_actual < mtd_ol) {
persenOL = Number((mtd_ol - mtd_actual)/mtd_ol)
} else {
persenOL = Number((mtd_ol - mtd_actual)/mtd_ol) + 1
}
} else {
persenOL = Number(mtd_actual/mtd_ol)
}
dbSumaBS.push([
item.type_report_id,
item.id,
item.parent,
......@@ -1395,9 +1440,9 @@ export default class SubHolding extends Component {
item.balance_sheet.mtd_last_month,
item.balance_sheet.mtd_actual,
item.balance_sheet.mtd_mb,
item.balance_sheet.percent_of_mb,
isNaN(persenMtd) || persenMtd == 'Infinity' || persenMtd == '-Infinity' ? (item.balance_sheet.mtd_mb == '' || item.balance_sheet.mtd_mb == 0 ? -0 : 0) : (item.balance_sheet.mtd_mb == '' || item.balance_sheet.mtd_mb == 0 ? persenMtd * -100 : persenMtd * 100),
item.balance_sheet.mtd_ol,
item.balance_sheet.percent_of_ol,
isNaN(persenOL) || persenOL == 'Infinity' || persenOL == '-Infinity' ? (item.balance_sheet.mtd_ol == '' || item.balance_sheet.mtd_ol == 0 ? -0 : 0) : (item.balance_sheet.mtd_ol == '' || item.balance_sheet.mtd_ol == 0 ? persenOL * -100 : persenOL * 100),
item.balance_sheet.mtd_last_year,
item.balance_sheet.forecast_next_year,
item.balance_sheet.forecast_more_year,
......@@ -1411,13 +1456,20 @@ export default class SubHolding extends Component {
}
}
})
this.setState({ dataTable, previewTable: true, loading: false, previewDownload: true })
// this.setState({ dataTable }, () => {
this.setState({ dataTable: dbSumaBS, previewTable: true, loading: false, previewDownload: true })
console.log(this.state.dataTable)
// // this.getBalanceSheetMR(payload)
// })
} else {
this.setState({ dataTable: [], previewTable: false, loading: false, previewDownload: false })
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
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', loading: false })
}
})
......
......@@ -1042,22 +1042,6 @@ export default class TableSubHolding extends Component {
return total
}
const handleMTDPercent = (tableMeta, dex, type) => {
let total = 0
// if (tableMeta.rowData[5] === "Cash and cash equivalent" ) {
// console.log(tableMeta);
// console.log(dataTable2);
// }
if (dex === 1) {
total = R.equals((Number(dataTable2[tableMeta.rowIndex][7]) / Number(dataTable2[tableMeta.rowIndex][8])), NaN) ? "0" : R.equals((Number(dataTable2[tableMeta.rowIndex][7]) / Number(dataTable2[tableMeta.rowIndex][8])), Infinity) ? "0" : R.equals((Number(dataTable2[tableMeta.rowIndex][7]) / Number(dataTable2[tableMeta.rowIndex][8])), -Infinity) ? "0" : Number(dataTable2[tableMeta.rowIndex][7]) / Number(dataTable2[tableMeta.rowIndex][8])
dataTable2[tableMeta.rowIndex][tableMeta.columnIndex + type] = Number(total).toFixed(1)
} else if (dex === 2) {
total = R.equals((Number(dataTable2[tableMeta.rowIndex][7]) / Number(dataTable2[tableMeta.rowIndex][10])), NaN) ? "0" : R.equals((Number(dataTable2[tableMeta.rowIndex][7]) / Number(dataTable2[tableMeta.rowIndex][10])), Infinity) ? "0" : R.equals((Number(dataTable2[tableMeta.rowIndex][7]) / Number(dataTable2[tableMeta.rowIndex][10])), -Infinity) ? "0" : Number(dataTable2[tableMeta.rowIndex][7]) / Number(dataTable2[tableMeta.rowIndex][10])
dataTable2[tableMeta.rowIndex][tableMeta.columnIndex + type] = Number(total).toFixed(1)
}
return total
}
let datas = [
["ABCD", "Testing", { a: "2", b: "3", c: "4", d: "5" }, { a: "2", b: "3", c: "4", d: "5" }, { a: "2", b: "3", c: "4", d: "5" }, { a: "2", b: "3", c: "4", d: "5" }, { a: "2", b: "3", c: "4", d: "5" }, { a: "2", b: "3", c: "4", d: "5" }],
["Total Assets", "Notes", { a: "6", b: "7", c: "8", d: "9" }, { a: "6", b: "7", c: "8", d: "9" }, { a: "6", b: "7", c: "8", d: "9" }, { a: "6", b: "7", c: "8", d: "9" }, { a: "6", b: "7", c: "8", d: "9" }, { a: "6", b: "7", c: "8", d: "9" }]
......@@ -15052,7 +15036,7 @@ export default class TableSubHolding extends Component {
}
}
}, {
name: `MTD 2021`,
name: `MTD ${this.props.periode}`,
options: {
customHeadRender: (columnMeta) => (
<th style={{ ...style2, color: '#000', backgroundColor: '#07a7d0', top: 0, zIndex: 102, fontSize: 13, fontWeight: 1, width: 150, borderRight: "1px solid rgb(255, 255, 255)", padding: 0 }} >
......@@ -15180,8 +15164,9 @@ export default class TableSubHolding extends Component {
style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 70, backgroundColor: 'transparent' }}
type="text"
placeholder=""
suffix={`%`}
disabled={true}
value={Number(handleMTDPercent(tableMeta, 1, 3)).toFixed(1)}
value={Number(tableMeta.rowData[9]).toFixed(1)}
/>
}
/>
......@@ -15228,8 +15213,9 @@ export default class TableSubHolding extends Component {
style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
type="text"
placeholder=""
suffix={'%'}
disabled={true}
value={Number(handleMTDPercent(tableMeta, 2, 5)).toFixed(1)}
value={Number(tableMeta.rowData[11]).toFixed(1)}
/>
}
/>
......@@ -15266,7 +15252,7 @@ export default class TableSubHolding extends Component {
}
}
}, {
name: "2022",
name: `${(this.props.periode) + 1}`,
options: {
customHeadRender: (columnMeta) => (
<th style={{ ...style2, color: '#fff', backgroundColor: '#07a7d0', fontSize: 13, top: 0, zIndex: 102, fontWeight: 1, width: 150, borderRight: "1px solid rgb(255, 255, 255)", padding: 0 }} >
......@@ -15311,7 +15297,7 @@ export default class TableSubHolding extends Component {
}
}
}, {
name: "2023",
name: `${(this.props.periode) + 2}`,
options: {
customHeadRender: (columnMeta) => (
<th style={{ ...style2, color: '#fff', backgroundColor: '#07a7d0', fontSize: 13, top: 0, zIndex: 102, fontWeight: 1, width: 150, borderRight: "1px solid rgb(255, 255, 255)", padding: 0 }} >
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